我正在通过为其编写 XML 来生成一个 Excel 文件。我快完成了,但我无法让条件格式按照我想要的方式工作。
我想对某些单元格应用条件。例如,对于每个数据行(不是页眉或页脚),如果第 7-13 列大于第 6 列中的值,则应突出显示红色。下面的代码仅适用于第一个数据行。我怎样才能让它应用于一组行?
</Table>
<ConditionalFormatting xmlns="urn:schemas-microsoft-com:office:excel">
<Range>RC7:RC13</Range>
<Condition>
<Qualifier>Greater</Qualifier>
<Value1>RC6</Value1>
<Format Style='background-color:#F7A9A5'/>
</Condition>
</ConditionalFormatting>
</Worksheet>
</Workbook>
我宁愿不必指定确切的行号(B7-B13)。理想情况下,我可以将它应用到我想要的每一行或一组通用行。
更新:我有另一个问题,被比较的列(C6)是一个字符串。如果字符串为空,则不应应用该格式。但是,如果列包含数字,则应将其视为数字并进行比较。
更新:
这是更完整的代码:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Sodexo Platform</Author>
<LastAuthor>@HttpContext.Current.User.Identity.Name</LastAuthor>
<Created>@DateTime.Now.ToUniversalTime()</Created>
<LastSaved>@DateTime.Now.ToUniversalTime()</LastSaved>
<Company>Sodexo</Company>
<Version>1</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<DownloadComponents/>
<LocationOfComponents HRef="file:///D:\"/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>8700</WindowHeight>
<WindowWidth>11355</WindowWidth>
<WindowTopX>480</WindowTopX>
<WindowTopY>120</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Table">
<Borders>
<Border ss:Position="Top" ss:Color="#595959" ss:Weight="1" ss:LineStyle="Continuous"/>
<Border ss:Position="Bottom" ss:Color="#595959" ss:Weight="1" ss:LineStyle="Continuous"/>
<Border ss:Position="Left" ss:Color="#595959" ss:Weight="1" ss:LineStyle="Continuous"/>
<Border ss:Position="Right" ss:Color="#595959" ss:Weight="1" ss:LineStyle="Continuous"/>
</Borders>
<Font ss:FontName="Arial" ss:Size="8" />
</Style>
</Styles>
<Worksheet ss:Name="Summary">
<Table>
<Column ss:AutoFitWidth="0" ss:Width="200" />
<Column ss:AutoFitWidth="0" ss:Width="80" />
<Column ss:AutoFitWidth="0" ss:Width="130" />
<Column ss:AutoFitWidth="0" ss:Width="75" />
<Column ss:AutoFitWidth="0" ss:Width="75" />
<Column ss:AutoFitWidth="0" ss:Width="75" />
<Row>
<Cell ss:StyleID="Table">
<Data ss:Type="String">A</Data>
</Cell>
<Cell ss:StyleID="Table">
<Data ss:Type="String">B</Data>
</Cell>
<Cell ss:StyleID="Table">
<Data ss:Type="String">C</Data>
</Cell>
</Row>
</Table>
<ConditionalFormatting xmlns="urn:schemas-microsoft-com:office:excel">
<Range>RC7:RC13</Range>
<Condition>
<Qualifier>Greater</Qualifier>
<Value1>RC6</Value1>
<Format Style='background-color:#F7A9A5'/>
</Condition>
</ConditionalFormatting>
</Worksheet>
</Workbook>