我试图根据其值用“红色” 或“绿色” 填充一个单元格;这是我到目前为止尝试过的:
{{#xlsxAdd 'xl/worksheets/sheet1.xml' "worksheet.conditionalFormatting"}}
<conditionalFormatting sqref="G7:M7">
<cfRule type="cellIs" dxfId="0" priority="1" operator="notBetween">
<formula>{{productObj.min}}</formula>
<formula>{{productObj.max}}</formula>
</cfRule>
</conditionalFormatting>
{{/xlsxAdd}}
{{#xlsxAdd 'xl/worksheets/sheet1.xml' "worksheet.conditionalFormatting"}}
<conditionalFormatting sqref="G7:M7">
<cfRule type="cellIs" dxfId="2" priority="1" operator="between">
<formula>{{productObj.min}}</formula>
<formula>{{productObj.max}}</formula>
</cfRule>
</conditionalFormatting>
{{/xlsxAdd}}
但是似乎条件notBetween
总是与单元格匹配,但是在我下载文件然后更改了单元格的值之后,条件开始正常工作。
我不知道reportjs是否将我的电话号码视为 strings
,因为下载文件后更改该值非常有效。
-更新---
发现了此问题:https://github.com/jsreport/jsreport-html-to-xlsx/issues/7
这是jsreport的一个问题,它是在我的数字前添加'
的自身,这导致条件渲染失败。
但是,我仍然希望有一种使用条件格式来填充“ NOT”单元格的正确方法,因此我将保留这个问题
-结束更新---
我也尝试用静态颜色填充它,但是没有用:
{{#xlsxReplace "xl/styles.xml" "styleSheet.fills"}}
<fills count="5">
<fill>
<patternFill patternType="none"/>
</fill>
<fill>
<patternFill patternType="lightGray"/>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FFBFBFBF"/>
<bgColor rgb="FFBFBFBF"/>
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FFFF0000"/>
<bgColor rgb="FFFF0000"/>
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FF00FF00"/>
<bgColor rgb="FF00FF00"/>
</patternFill>
</fill>
</fills>
{{/xlsxReplace}}
// then adding the cell like this:
<c t="inlineStr" fillId="3" ><is><t>{{val}}</t></is></c>
但仍然不能完成工作,我什至尝试添加dxfs
而不是fills
,如果有人可以帮助我找出我在做什么错?!
答案 0 :(得分:1)
其(zero-based index) ,因此s="1"
将成为第二个元素<cellXfs>
请记住,从零开始的索引,counts属性将是内部元素的计数
在主jsreport文件中添加
{{#xlsxReplace "xl/styles.xml"}}
{#asset style.xml}}
{{/xlsxReplace}}
创建style.xml并在其中添加
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">
<fonts count="2" x14ac:knownFonts="2">
<font>
<sz val="12" />
<name val="Calibri" />
<b />
</font>
<font>
<sz val="12" />
<name val="Calibri" />
</font>
</fonts>
<fills count="5">
<fill>
<patternFill patternType="solid">
<fgColor rgb="bfbfbf" />
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="bfbfbf" />
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="bfbfbf" />
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FFFF00" />
</patternFill>
</fill>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FF0000" />
</patternFill>
</fill>
</fills>
<borders count="1">
<border>
<left/>
<right/>
<top/>
<bottom/>
<diagonal/>
</border>
</borders>
<cellXfs count="7">
<xf />
<xf fontId="0" fillId="2">
<alignment horizontal="center" vertical="center" />
</xf>
<xf fontId="0" fillId="3">
<alignment horizontal="center" vertical="center" />
</xf>
<xf fontId="0" fillId="4">
<alignment horizontal="center" vertical="center" />
</xf>
<xf fontId="1">
<alignment horizontal="center" vertical="center" />
</xf>
<xf fontId="1" fillId="3">
<alignment horizontal="center" vertical="center" />
</xf>
<xf fontId="1" fillId="4">
<alignment horizontal="center" vertical="center" />
</xf>
</cellXfs>
</styleSheet>