The key point missing from most efforts to answer this question are that the Sun has a temperature gradient with depth. If it were (somehow) isothermal, then indeed the absorption and emission processes would cancel and the Sun's spectrum would be a smooth blackbody.
The photons we see from the Sun, were those that were able to escape from its photosphere - an outer layer only a few hundred km in thickness.
The interior of the Sun is hotter than layers further out and the radiation field approximates to a blackbody, with a radiation flux that is strongly temperature dependent. The strong temperature dependence, combined with the negative temperature gradient means that the solar spectrum is produced by the hottest layers we can see.
Why the emphasis? Well, the depth we can see into the Sun is wavelength dependent. Where there are strong radiative transition probabilities, the light coming from the interior is absorbed. The re-emitted light (it has to be re-emitted if the material is in thermal equilibrium) is emitted in a random direction and a negligible fraction comes towards us.
I think there are two key points. One is the random direction of the re-emission of absorbed energy, but the other is the temperature gradient which means there is a clear outward directionality to the net radiative flux which means you can treat the Sun as a succession of cooler "slabs" as one moves outward.
The net effects are absorption lines. A good way to think about the solar spectrum is that at each wavelength you are seeing a (roughly) blackbody spectrum emitted at the temperature of the layer from which photons at that wavelength can escape. Thus the bottom of an absorption line is emitted at cooler temperatures, closer to the "surface", whilst continuum comes from hotter, deeper layers, but at wavelengths where the opacity is lower so that the photons are still able to make it out.
It's because there's more nitrogen at lower heights:
The green color of the aurora below 150 km height stems from the 558 nm line of Oxygen. It is not seen at larger heights since the 1S-state is not reached from the 3P ground state in collisions with electrons or protons. It is assumed that this state is produced in collisions of O(3P) with excited nitrogen molecules which give off their energy and take over angular momentum:
$N_2^* + O(^3P) → N_2 + O(^1S)$
By Dietrich Zawischa's Atomic spectra webpage.
Oxygen becomes more common than nitrogen at heights above ~150 km (see figure below), where the help from nitrogen then becomes less likely to take place:
Source.
Best Answer
The water droplets that create a rainbow are not emitting the light that you see in a rainbow; if they were, you would see a glowing cloud of consistent color, not a rainbow. The rainbow is formed by sunlight refracting and reflecting through water droplets in the air; the water refracts through the "front" of the drop, reflects off the "back," and refracts again on the way back out. The refractions are what separate the colors, since different wavelengths of light refract to different degrees. If you used devices capable of imaging in other wavelengths of light, you'd see further bands of "color" beyond the red and violet sides of the rainbow, resulting from the infrared/ultraviolet (and other wavelengths beyond those) radiation in the sunlight.
So in short, the full-spectrum appearance of the rainbow is due to the fact that the source of the light (the sun) is a thermal blackbody and emits a blackbody spectrum.