Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

excel

epplus

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#

like image 242
CYK Avatar asked Aug 08 '12 05:08

CYK


1 Answers

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);
like image 111
Chirag Sheth Avatar answered Oct 18 '22 01:10

Chirag Sheth