The calculation of the electromagnetic field in nanostructured materials and nano-optoelectronic devices, when the wavelength of the incident radiation is comparable with the size of the structural elements, requires the exact solution of Maxwell's equations. In this case, a very promising numerical approach is the spectral element method, which combines the geometric flexibility of finite elements with high precision of spectral methods. In this paper the implementation of the spectral element method based on the Dirichlet-to-Neumann map for solving Maxwell’s equations is discussed. The application of the method for two-dimensional periodic structures, such as diffraction gratings and a metal nanowire array in a dielectric matrix, is demonstrated.