EPPLus al momento non supporta la disattivazione del tag verde. Tuttavia, è possibile modificare il progetto per sopprimerlo. In primo luogo sarà necessario aggiungere una nuova classe al progetto, 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);
}
}
}
}
Successivamente sarà necessario modificare ExcelWorkSheet.cs, aggiungendo questo codice:
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);
}
}
Compile la soluzione EPPPlus, includila nel tuo progetto e sarai in grado di rimuovere i tag usando un codice simile a questo:
//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;
Nota che le ultime righe devono essere '// Non visualizzare il messaggio 'numero memorizzato come testo'. Ignora l'errore. NumeroStoredAsText = Vero;' E grazie per aver postato questo messaggio! Funziona alla grande! – user2029432
Si noti che l'impostazione dell'intervallo in questa soluzione alternativa è importante. Sono stato negligente e ha ottenuto un errore di Excel all'apertura della cartella di lavoro. –
@briddums Non ho la possibilità di modificare la fonte, c'è un modo per modificare l'XML "dall'esterno"? –