Using EPPlus Excel - How to ignore excel error checking or remove green tag on top left of the cell

Viewed 12079

I use EPPlus to export excel 2007 file. The file can export normally but i have some problem with setting column format. My string column with numeric style (Purchase Order No. ex. 49000001) be exported with green tag on the top left of the each cell, How can i remove it?

I try to set number format to "General" but it's not work

Please help.

p.s i use C#

7 Answers

In addition to @briddums' answer, since EPPlus version 5 you can ignore errors and there is no need to touch the EPPlus source.

var p = new ExcelPackage();
var ws = p.Workbook.Worksheets.Add("IgnoreErrors");

ws.Cells["A1"].Value = "1";
ws.Cells["A2"].Value = "2";
var ie = ws.IgnoredErrors.Add(ws.Cells["A2"]);
ie.NumberStoredAsText = true;   // Ignore errors on A2 only

this code works

private void removingGreenTagWarning(ExcelWorksheet template1, string address)
            {
                var xdoc = template1.WorksheetXml;
                //Create the import nodes (note the plural vs singular
                var ignoredErrors = xdoc.CreateNode(System.Xml.XmlNodeType.Element, "ignoredErrors", xdoc.DocumentElement.NamespaceURI);
                var ignoredError = xdoc.CreateNode(System.Xml.XmlNodeType.Element, "ignoredError", xdoc.DocumentElement.NamespaceURI);
                ignoredErrors.AppendChild(ignoredError);

                //Attributes for the INNER node
                var sqrefAtt = xdoc.CreateAttribute("sqref");
                sqrefAtt.Value = address;// Or whatever range is needed....

                var flagAtt = xdoc.CreateAttribute("numberStoredAsText");
                flagAtt.Value = "1";

                ignoredError.Attributes.Append(sqrefAtt);
                ignoredError.Attributes.Append(flagAtt);

                //Now put the OUTER node into the worksheet xml
                xdoc.LastChild.AppendChild(ignoredErrors);
            }

use it as

removingGreenTagWarning(template1, template1.Cells[1, 1, 100, 100].Address);
Related