The complicated task allocation, scheduling and planning problem with multiple stations and multiple robots commonly seen in spot welding production line design is studied in this paper. To deal with the highly coupled model combined with several task planning sub-problems, including robot cells design, robots allocation among cells, welding allocation among cells and robots, and welding scheduling for each robot, as well as numerous internal and external constraints, the traditional multi-robot task allocation (MRTA) framework is extended to a novel and uniform multi-station multi-robot (MS-MRTA) framework, and a sophisticated hierarchical optimization algorithm is proposed. Firstly, to establish the optimization model based on MS-MRTA framework as a whole, constraints such as reachability constraint, maximum speed and acceleration constraint, collision constraint and welding operation time constraint are considered, and the optimization objective is established based on the balance of welding tasks of each robot and each cell. Then, in order to solve the highly coupled model, a hierarchical optimization algorithm is proposed to divide the problem into three layers from top to bottom: the path planning of a single robot, welding task allocation among robots, and welding task allocation among cells. The path planning of a single robot is analogous to the Travelling Salesman Problem (TSP) solved by iterating the Lin-Kernighan-Helsgaun (LKH) solver with the trapezoidal acceleration and deceleration motion. To solve the welding task allocation among robots with numerous constraints, a regional assignment method was proposed which simplify the model and eliminate the accessibility constraint and collision constraint, and combined with genetic algorithm to solve the sub-problem iteratively. The welding task allocation among cells is solved based on the principle of balanced welding of each cell. Genetic algorithm is used to obtain the nested iterative solution of three sub-problems. The cases of actual door welding tasks are studied to verify the effectiveness of the proposed optimization algorithm. Compared with the method of long-term trial and error by experienced experts and two other more advanced algorithms, the proposed optimization algorithm results in a task assignment scheme with less welding time, less waiting time and an increase of welding operation productivity, which shows the effectiveness and feasibility of the multi-robot multi-station task allocation algorithm based on stepwise optimization.