Hartmann wavefront sensor and detection method using spectroscopic device to achieve alignment function, two parts of rough alignment and fine alignment are added to the original system, wherein the rough alignment part includes: imaging screen with holes, light splitting The device, the rough alignment detection system, and the fine alignment part include: a focusing lens, a fine alignment beam splitter, and a fine alignment detection system. After the two steps of rough alignment and fine alignment, the incident beam can quickly and easily enter the measurement field of view of the microlens array, and can be strictly coaxial with the system, thereby improving the measurement accuracy of the Hartmann system; At the same time, the Hartmann wavefront sensor can conveniently detect positive lenses, negative lenses, convex mirrors, concave mirrors, plane mirrors, etc. The invention can display the adjustment results in real time, and has the characteristics of being intuitive and easy to understand, thereby reducing the requirements for users and reducing the adjustment time; and the device used in the invention has low specification requirements, low prices, and easy to buy. .