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
Post a Comment