Let me answer the most general question first:
"even if the different languages are not mutually understandable when spoken, they are when written."
To a large extent, this is true - but for two different reasons. Before the modern era, this is true because "written Chinese" was based on classical Chinese; whereas the spoken languages were highly divergent from the written form. This is similar to the situation in pre-Renaissance Italy, where scholars wrote in Latin but spoke in highly divergent (mutually unintelligible) Italian dialects.
During the 1910s-1930s, when China was beginning to modernize, there was an influential literary movement to use "Vernacular Chinese" in place of "Classical Chinese" in writing, because the former was easier to understand for the vast majority of people, who were learning how to write and read for the first time. Of course, this created a problem - there are so many languages/dialects in Vernacular Chinese, so which one do we choose as the standard one? It was agreed, after about 20 years of (often bitter) debates, spanning across different regimes, that the Mandarin (Guanhua) dialect based in Beijing would be the standard form of written Vernacular Chinese. Today this is simply referred to as "Chinese" or "Standard Chinese".
So, yes - a person living in Shanghai, who only speaks Shanghainese, is generally able to write and read in a "written form" of Beijing Mandarin. You can see how this makes things difficult for speakers of non-Mandarin dialects - they speak with a particular grammatical structure and vocabulary, but have to write and read in a completely different way. Often, to make things easier, most non-Mandarin (Jiangsu, Zhejiang, Fujian, Guangdong, Guangxi etc.) regions of China have adopted non-standardized ways of putting their native vernacular languages into writing. This usually happens when using Mandarin Chinese would create confusion or ambiguity, or when the vocabulary and grammar they used is significantly different from Mandarin vocabulary. For example, the Shanghainese would write "再會" for "Goodbye", instead of "再見". In Cantonese, in particular, the written form of Cantonese is highly developed (partially because of Hong Kong's unique history) and widely used in place of Mandarin writing in non-official settings.
For the younger generation, regardless of whether they uses local vocabulary in writing, they usually understand Standard Chinese very well, since they learn it in school. So the mutual intelligibility goes one way - the non-Mandarin speakers can read Mandarin, but the Mandarin speakers usually cannot read local dialects. Summary:
Historical:
Spoken languages: Many
Written language: Classical Chinese
Modern:
Spoken languages: Many
Written language: Mandarin is understood by all; local varieties used by some
It may also be of interest to you that there are two different scripts for written Chinese - traditional and simplified. Traditional Chinese is used by people outside of mainland China (Hong Kong, Macau, Taiwan, overseas communities) whereas Simplified Chinese is used by those within.