lundi 14 décembre 2015

C# Missing conditional formats with EPPlus

When writing a excel file from a template, using a web page in mvc3, the conditional format get messed up. Checking the xml files of the sheet, I go from this:

<conditionalFormatting sqref="T6:U18">
<cfRule type="colorScale" priority="2">
<colorScale>
<cfvo type="percentile" val="0"/>
<cfvo type="percentile" val="50"/>
<cfvo type="percentile" val="100"/>
<color rgb="FF63BE7B"/>
<color rgb="FFFFEB84"/>
<color rgb="FFF8696B"/>
</colorScale>
</cfRule>
</conditionalFormatting>

To this:

<conditionalFormatting sqref="T6:U18">
<cfRule type="colorScale" priority="2">
<colorScale>
<cfvo type="min" />
<cfvo type="percent" val="50" />
<cfvo type="max" />
<color rgb="fff8696b" />
<color rgb="ffffeb84" />
<color rgb="ff63be7b" />
</colorScale>
</cfRule>
</conditionalFormatting>

A code snip:

[HttpPost]
public ActionResult Export(DataModel model)
{ 
    using (ExcelPackage xlsPackage = new ExcelPackage(new FileInfo(Server.MapPath("~/Content/Data/TEMPLATE.xlsx")), true))
    {
        ExcelWorksheet wsSheet = xlsPackage.Workbook.Worksheets["TOTAL"];

       //Data fill

        MemoryStream stream = new MemoryStream();
        xlsPackage.SaveAs(stream);
        stream.Position = 0;

        return File(stream, "application/vnd.ms-excel", "Data.xlsx");
    }
}

Aucun commentaire:

Enregistrer un commentaire