writing to different worksheets at the same time

Jun 6, 2013 at 3:07 PM
Hi!

I want to write same data to different worksheets in one Loop.
so here is an example:
FileInfo template = new FileInfo(file);
FileInfo newFile = null;
OfficeOpenXml.ExcelPackage excelpackage = null;
OfficeOpenXml.ExcelWorksheet worksheet = null;

foreach(...)
{
      newFile = new FileInfo(....);
      excelpackage = new OfficeOpenXml.ExcelPackage(newFile, template);
      worksheet = excelpackage.Workbook.Worksheets["Sheet"]; 
      worksheet_2 = excelpackage.Workbook.Worksheets["Sheet_2"];

      worksheet.Cells[1, 1].Value = "some Value";

      worksheet_2.Cells[2, 2].Value = "some other Value";

      excelpackage.Save();                
}
but this does not work. Any idea how to solve this ?

thanks
Simon