简体   繁体   English

Excel内部单元格字体格式与XML

[英]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. 我已编写了一些生成Excel XML文件格式的C#代码,目前正在使用Microsoft Office 2010 Professional Plus。 This XML file contains many worksheets, it's possible that the worksheet may contain several thousand lines of data. 这个XML文件包含许多工作表,该工作表可能包含数千行数据。 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; 工作表会生成多个单元格,但是每个单元格中的文本都可以设置为不同的字体颜色(而不是使用全局单元格字体颜色)-使用类似于以下摘录的XML可以实现此目的;

<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". 但是,如果我生成一个很大的工作表,并且有很多像这样的单元格,它将导致Excel的行为“有些奇怪”。 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. 严格来说,我的意思是,当我尝试查看工作表时,我看到了一些奇怪的渲染工件-从电子表格的顶部,它会慢慢地逐行渲染,直到大约20行,此时它将暂停,再次将其自身向下清除,并重复该过程,这将继续导致Excel变得无响应,直到我使用任务管理器将其杀死为止。

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. 我不确定这是一个编程问题,即使我是软件开发人员,但我一直在相信Excel可能无法处理这种性质的“大”文档,因此搜索google似乎并没有提出建议有关此主题的信息,但是很难找到合适的关键字。 This appears to be a fairly esotoric thing to do with Excel. 对于Excel来说,这似乎是一件相当深奥的事。

I have tried saving the XML file into an XLSX format and reopening it, with little luck. 我试过将XML文件保存为XLSX格式,然后重新打开它,运气不佳。 I have also tried generating a smaller dataset which causes Excel to behave normally. 我也尝试过生成一个较小的数据集,从而导致Excel正常运行。 My Desktop PC should be powerful enough to handle this, lots of RAM and fresh out of the shop. 我的台式机应该足够强大,可以处理这些问题,而且可以在工厂外购买大量RAM和新鲜事物。

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. 需要注意的一件事是,Excel对工作表中允许的唯一格式的数量有所限制。 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. 在Excel 2007中, 唯一单元格格式的限制为64,000 ,但将其应用于Excel 2003格式的Spreadsheet XML时,则可能低至4000。

So, you may need to re-use some global cell formats if you exceed the cell format limit. 因此,如果超出单元格格式限制,则可能需要重新使用某些全局单元格格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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