This project has moved. For the latest updates, please go here.

Worksheet being overwritten

Jun 15, 2011 at 5:13 AM

Hi - I am calling passing in a datatable and a string parameter - which will populate and name a worksheet, respectively.  This method will be called multiple times and should create a new spreadsheet everytime it is called.  The method is working, but it is overwriting an existing spreadsheet instead of adding a new spreadhseet each time.  What am I misssing?  Is it the string?



public static void ExportExcel(DataTable dt, string s)

     if  (dt.Rows.Count > 0) 

     {using (ExcelPackage p = new ExcelPackage())



    p.Workbook.Properties.Title = "Office Open XML xlsx Processor"


//Create a sheet  
//tried both of these



var sheet = p.Workbook.Worksheets[s];
if (sheet == null)
//Add a new sheet...

sheet = p.Workbook.Worksheets.Add(s);

Jun 15, 2011 at 2:07 PM

ALso tried:

ExcelWorksheet ws = p.Workbook.Worksheets.Add(s);






Jun 15, 2011 at 6:44 PM

nevermind, got it!