XML を記述して Excel ファイルを生成しています。ほぼ完了しましたが、条件付き書式を希望どおりに動作させることができません。
特定のセルに条件を適用したい。たとえば、各データ行 (ヘッダーまたはフッターではない) では、列 6 の値よりも大きい場合、列 7 ~ 13 が赤で強調表示されます。以下のコードは、最初のデータ行のみで機能します。行のセットに適用するにはどうすればよいですか?
</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>