Clear data in column

时光毁灭记忆、已成空白 提交于 2019-12-11 01:59:03

问题


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();
}

回答1:


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.



来源:https://stackoverflow.com/questions/21916041/clear-data-in-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!