epplusAan de slag met epplus


Opmerkingen

EPPlus is een .NET-bibliotheek die Excel 2007/2010/2013-bestanden leest en schrijft met behulp van het Open Office XML-formaat (xlsx).

EPPlus ondersteunt:

  • Celbereiken
  • Celstijlen (Rand, Kleur, Vulling, Lettertype, Nummer, Uitlijningen)
  • Grafieken
  • Afbeeldingen
  • vormen
  • Comments
  • tabellen
  • Bescherming
  • Encryption
  • Draaitabellen
  • Gegevensvalidatie
  • Conditionele opmaak
  • VBA
  • Formule berekening

versies

Versie Publicatiedatum
Eerste uitgave 2009-11-30
2.5.0.1 2010-01-25
2.6.0.1 2010-03-23
2.7.0.1 2010-06-17
2.8.0.2 2010-11-15
2.9.0.1 2011-05-31
3.0.0.2 2012-01-31
3.1 2012-04-11
4.0.5 2016/01/08
4.1 2016/07/14

Ermee beginnen

//Create a new ExcelPackage
using (ExcelPackage excelPackage = new ExcelPackage())
{
   //Set some properties of the Excel document
   excelPackage.Workbook.Properties.Author = "VDWWD";
   excelPackage.Workbook.Properties.Title = "Title of Document";
   excelPackage.Workbook.Properties.Subject = "EPPlus demo export data";
   excelPackage.Workbook.Properties.Created = DateTime.Now;

    //Create the WorkSheet
    ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");

    //Add some text to cell A1
    worksheet.Cells["A1"].Value = "My first EPPlus spreadsheet!";
    //You could also use [line, column] notation:
    worksheet.Cells[1,2].Value = "This is cell B1!";

    //Save your file
    FileInfo fi = new FileInfo(@"Path\To\Your\File.xlsx");
    excelPackage.SaveAs(fi);
}

//Opening an existing Excel file
FileInfo fi = new FileInfo(@"Path\To\Your\File.xlsx");
using (ExcelPackage excelPackage = new ExcelPackage(fi))
{
    //Get a WorkSheet by index. Note that EPPlus indexes are base 1, not base 0!
    ExcelWorksheet firstWorksheet = excelPackage.Workbook.Worksheets[1];
    
    //Get a WorkSheet by name. If the worksheet doesn't exist, throw an exeption
    ExcelWorksheet namedWorksheet = excelPackage.Workbook.Worksheets["SomeWorksheet"];

    //If you don't know if a worksheet exists, you could use LINQ,
    //So it doesn't throw an exception, but return null in case it doesn't find it
    ExcelWorksheet anotherWorksheet = 
        excelPackage.Workbook.Worksheets.FirstOrDefault(x=>x.Name=="SomeWorksheet");

    //Get the content from cells A1 and B1 as string, in two different notations
    string valA1 = firstWorksheet.Cells["A1"].Value.ToString();
    string valB1 = firstWorksheet.Cells[1,2].Value.ToString();

    //Save your file
    excelPackage.Save();
}
 

Installatie

Download de bestanden van CodePlex en voeg ze toe aan het project.

Of installeer de bestanden met Pakketbeheer.

PM> Install-Package EPPlus