简体   繁体   中英

Excel interior cell font formatting with XML

I've written some C# code which generates an Excel XML file format, I'm currently using Microsoft Office 2010 Professional Plus. This XML file contains many worksheets, it's possible that the worksheet may contain several thousand lines of data. The worksheet generates multiple cells however the text in each cell maybe formatted to a different font colour (rather than using a global cell font colour) - this is possible using some XML similar to the extract below;

<Cell ss:StyleID="Normal">
    <ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
        <Font html:Color="Red">Text in red</Font>
        <Font html:Color="Blue">text in blue</Font>
    </ss:Data>
</Cell>

However, it would appear that if I generate a large worksheet, with lots of cells like this it causes Excel to behave "a little strangely". By stangely I mean that when I attempt to view the worksheet I see some odd rendering artifacts - from the top of the spreadsheet it will slowly render row by row, until about row 20, at which point it will pause, clear itself down again, and repeat the process, this will continue causing Excel to become unresponsive until I kill it using task manager.

Would anybody be able to shed some light on this issue? I'm not sure this is a programming issue even though I'm a software developer, I'm edging towards believing that Excel may not be able to cope with a "large" document of this nature, searching google appears to bring up no information on this subject, but it is difficult to find the appropriate keywords. This appears to be a fairly esotoric thing to do with Excel.

I have tried saving the XML file into an XLSX format and reopening it, with little luck. I have also tried generating a smaller dataset which causes Excel to behave normally. My Desktop PC should be powerful enough to handle this, lots of RAM and fresh out of the shop.

Any help appreciated, thank you for your time.

The worksheet generates multiple cells however the text in each cell maybe formatted to a different font colour (rather than using a global cell font colour)

One thing to look out for is that Excel has a limit on the number of unique formats that it allows in a worksheet. If you are using inline string formatting (as shown in your example) as general formatting for cells then you may exceed this limit.

The limit of unique cell formats is 64,000 in Excel 2007 but may be as low as 4000 when applied to Spreadsheet XML, which was an Excel 2003 format.

So, you may need to re-use some global cell formats if you exceed the cell format limit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM