The generation of electrical energy in solar cells occurs based on the photoelectric effect that is the effect that occurs due to photons with certain wavelengths which if the energy is greater than the semiconductor threshold energy, it will be absorbed by electrons so the electrons move from the valence band (N) to the conduction band (P) and leaving the hole in the valence band, then two charges, the electron-hole pair are generated. The electron-hole flow that occurs when connected to an electrical load through the conductor will produce an electric current.
For more details we can see in the picture.