使用EPPlus的Excel - 如何忽略练成错误检查或者对细胞的左上方除去绿色标签 [英] Using EPPlus Excel - How to ignore excel error checking or remove green tag on top left of the cell

查看:2086
本文介绍了使用EPPlus的Excel - 如何忽略练成错误检查或者对细胞的左上方除去绿色标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用EPPlus导出Excel 2007文件。该文件可以正常出口,但我有一些问题,设置列格式。

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

请帮忙。

PS我使用C#

推荐答案

EPPLus目前不支持禁用绿色标记。然而,这是可以修改的项目中,为了抑制它。首先,你需要一个新的类添加到项目中,ExcelIgnoredError.cs:

EPPLus does not currently support disabling that green tag. However, it is possible to modify the project in order to suppress it. First you will need to add a new class to the project, ExcelIgnoredError.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace OfficeOpenXml
{
    public class ExcelIgnoredError : XmlHelper
    {
        private ExcelWorksheet _worksheet;

        /// <summary>
        /// Constructor
        /// </summary>
        internal ExcelIgnoredError(XmlNamespaceManager ns, XmlNode node, ExcelWorksheet xlWorkSheet) :
            base(ns, node)
        {
            _worksheet = xlWorkSheet;
        }


        public bool NumberStoredAsText
        {
            get
            {
                return GetXmlNodeBool("@numberStoredAsText");
            }
            set
            {
                SetXmlNodeBool("@numberStoredAsText", value);
            }
        }


        public bool TwoDigitTextYear
        {
            get
            {
                return GetXmlNodeBool("@twoDigitTextYear");
            }
            set
            {
                SetXmlNodeBool("@twoDigitTextYear", value);
            }
        }


        public string Range
        {
            get
            {
                return GetXmlNodeString("@sqref");
            }
            set
            {
                SetXmlNodeString("@sqref", value);
            }
        }
    }
}



接下来,您将需要修改ExcelWorkSheet.cs,添加以下代码:


Next you will need to modify ExcelWorkSheet.cs, adding this code:

public ExcelIgnoredError _ignoredError;

public ExcelIgnoredError IgnoredError
{
    get
    {
        if (_ignoredError == null)
        {
            // Check that ignoredErrors exists
            XmlNode node = TopNode.SelectSingleNode("d:ignoredErrors", NameSpaceManager);

            if (node == null)
            {
                CreateNode("d:ignoredErrors");
            }

            //Check that ignoredError exists
            node = TopNode.SelectSingleNode("d:ignoredErrors/d:ignoredError", NameSpaceManager);

            if (node == null)
            {
                CreateNode("d:ignoredErrors/d:ignoredError");
                node = TopNode.SelectSingleNode("d:ignoredErrors/d:ignoredError", NameSpaceManager);
            }

            _ignoredError = new ExcelIgnoredError(NameSpaceManager, node, this);
        }

        return (_ignoredError);
    }
}





编译EPPPlus解决方案,它包含在你的项目,你就可以删除使用类似的代码标记这样:


Compile the EPPPlus solution, include it in your project and you will be able to remove the tags using code similar to this:

//Get a reference to the worksheet
ExcelWorkSheet sheet = package.WorkBook.WorkSheets(0);

//Set the cell range to ignore errors on to the whole sheet
sheet.IgnoredError.Range = Sheet.Dimension.Address;

//Do not display the warning 'number stored as text'
sheet.IgnoredError.NumberStoredAsText = true;

这篇关于使用EPPlus的Excel - 如何忽略练成错误检查或者对细胞的左上方除去绿色标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆