Search code examples
c#.netepplus

Is there any function to add Workbook in EPPLUS?


How to write this Code in EPPLUS?

Microsoft.Office.Interop.Excel.Workbook Workbook = Excel.Workbooks.Add(System.Type.Missing);

Solution

  • This is a boilerplate for creating a new spreadsheet in EPPlus:

    FileInfo newFile = new FileInfo(fileName);
    ExcelPackage package = new ExcelPackage(newFile);
    ExcelWorksheet ws = package.Workbook.Worksheets.Add("Sheet1");
    
    // Do some stuff
    ws.Cells["A1"].Formula = "=TODAY()";
    ws.Cells[2, 1].Value = "Hello World";
    
    package.Save();
    

    You could do it with the empty constructor (no file info specified), but you'll eventually have to declare that, so I always find it useful to do it up front.