Pergunta

I'm trying to use the standard .Clear() method for an EPPlus spreadsheet without any luck. Anyone know how to clear all the data in a column using the EPPlus plugin? Below is what i have so far. Does not throw an exception but doesn't work at all.

if (File.Exists(path))
{
    //Connect to spreadsheet
    FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read);
    FileInfo file = new FileInfo(path);
    _package = new ExcelPackage();

    //Pull data into EPPlus object
    _package.Load(stream);
    _sheet = _package.Workbook.Worksheets.First(); 

    //Clear out previous errors
    _sheet.Cells["L1"].Clear();
}
Foi útil?

Solução

I use the ExcelPackage a little differently (assuming we are talking about the same DLL):

public static FileInfo existingFile =
    new FileInfo(@"C:\Users\cle1394\Desktop\ExampleExcelFile.xlsx");

using (ExcelPackage xlPackage = new ExcelPackage(existingFile))
{
    ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];

    // clear value
    worksheet.Cell(iRow, 1).Value = "";

}

Try that, let me know if it works.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top