c# - open xml; trying to add multiple sheets to a workbook -


i trying add multiple spreadsheets same workbook, code seems add last element sheet. please let me know going wrong.

using (spreadsheetdocument spreadsheet = spreadsheetdocument.create(                     system.io.path.combine(appdomain.currentdomain.basedirectory, xlspath),                     spreadsheetdocumenttype.workbook))             {                 // create worksheet                 spreadsheet.addworkbookpart();                 uint = 1;                 foreach (var section in errorsections)                 {                      spreadsheet.workbookpart.workbook = new workbook();                              var sheetname = section.title.replace("xxxx - ", "");                     sheetname = sheetname.replace(" - xxxxx", "");                     worksheetpart worksheetpart =  spreadsheet.workbookpart.addnewpart<worksheetpart>();                     worksheetpart.worksheet = new worksheet(new sheetdata());                       sheets sheets = spreadsheet.workbookpart.workbook.appendchild<sheets>(new sheets());                      sheet sheet = (new sheet()                     {                         id = spreadsheet.workbookpart.getidofpart(spreadsheet.workbookpart.worksheetparts.first()),                         sheetid = i,                         name = sheetname                     });                        i++;                     sheets.appendchild(sheet);                 }                 spreadsheet.workbookpart.workbook.save();                 spreadsheet.close();             } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -