First-principles approach to the calculation of electronic spectra in clusters