What would cause spikes of this kind, lasting only a few seconds each time?
Lots of things, all perfectly normal. Because of the way computers work, they are NOT pulling the same amount of power all the time. Drives spin up and spin down, memory is used then let go, the CPU does a task, then goes to idle waiting for the next task. The graphic solution (often the most power hungry component in our computers) is suddenly tasked to display a bunch of animated objects, then goes back to the plain desktop.
All these things cause power demands to fluctuate.
That said, I am not keen on you running your computer directly from a home generator. Most portable home generators are designed to power heavy duty appliances (refrigerators and freezers) or motorized tools or air compressors and the sort. Not sensitive computers and as such, most home generators don't have the best output power regulation to ensure anomalies (often from fluctuations in revolutions from the generator's lawn mower engine sputtering, or missing a beat) don't disrupt the computer's operation. Also, grounding (Earthing) the generator's output can be tricky - typically requiring pounding a long copper grounding spike into the ground, then tying the generator's ground to it.
Because high-speed digital electronics need "quality", stable power, I
STRONGLY URGE you to get a "
good" UPS with AVR (automatic voltage regulation) to use at all times, but for sure, while on generator power. I emphasis "
good" because, like power supplies, there are good UPS and cheap UPS. Something like this
1000VA APC UPS with AVR would suit you fine, protecting your computer, your LCD monitor, and your network gear. Like power supplies, there is really no such thing as "too big" as the system will draw only what it needs. But like power supplies, the larger models tend to have the higher-end features and components.
Understand a surge and spike protector is little more than a fancy and expensive extension cord that does
absolutely nothing for anomalous "low-voltage events" like dips (opposite of spikes) and sags (opposite of surges), or brownouts (long durations sags). And for anomalous "high-voltage events" like surges and spikes, all a surge and spike protector does is chop off the tops ("clamp") of the voltage sinewaves - leaving a not-so-pretty mess for the PSU's filters and regulators to clean up. The better UPS will use it's AVR circuits to regulate the power into something easier on your computer's PSU.
If the anomaly is too extreme (high or low) for a surge and spike protector, they typically just kill power, causing the computer to crash, potentially corrupting hard drives. Hardly beneficial, IMO. But an UPS, on the other hand, will sense the extreme conditions and simply flip to battery power only to keep your system running AND isolated from destructive power.
Note until now, I mentioned nothing about an UPS providing backup power during a complete power outage - that's because battery backup is just the "icing on the cake". The "bread and butter" (I must be hungry!

) of a "good" UPS with AVR is the automatic voltage regulation.
That said, an UPS will typically have enough battery power for 20 to 30 minutes of backup power - so sorry, but an UPS is not likely able to provide power for the entire outage during the AC work being done on your apartment.
And for the record, I recommend ALL COMPUTERS BE ON A GOOD UPS w/AVR. I also have an UPS on my big screen TV and home theater equipment.