我在excel中创建一个空模板.我想打开模板并编辑文档,但我不知道如何更改现有工作表.那是代码:
using (SpreadsheetDocument xl = SpreadsheetDocument.Open(filename, true))
{
WorkbookPart wbp = xl.WorkbookPart;
WorkbookPart workbook = xl.WorkbookPart;
// Get the worksheet with the required name.
// To be used to match the ID for the required sheet data
// because the Sheet class and the SheetData class aren't
// linked to each other directly.
Sheet s = null;
if (wbp.Workbook.Sheets.Elements().Count(nm => nm.Name == sheetName) == 0)
{
// no such sheet with that name
xl.Close();
return;
}
else
{
s = …Run Code Online (Sandbox Code Playgroud)