本文整理汇总了C#中DocumentFormat.OpenXml.Packaging.WorksheetPart.PutXDocument方法的典型用法代码示例。如果您正苦于以下问题:C# WorksheetPart.PutXDocument方法的具体用法?C# WorksheetPart.PutXDocument怎么用?C# WorksheetPart.PutXDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentFormat.OpenXml.Packaging.WorksheetPart
的用法示例。
在下文中一共展示了WorksheetPart.PutXDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyCellRange
// Copy all cells in the specified range to a new location
public static void CopyCellRange(SpreadsheetDocument document, WorksheetPart worksheet, int startRow, int startColumn, int endRow, int endColumn,
int toRow, int toColumn)
{
int rowOffset = toRow - startRow;
int columnOffset = toColumn - startColumn;
XDocument worksheetXDocument = worksheet.GetXDocument();
for (int row = startRow; row <= endRow; row++)
for (int column = startColumn; column <= endColumn; column++)
{
XElement oldCell = GetCell(worksheetXDocument, column, row);
if (oldCell != null)
{
XElement newCell = new XElement(oldCell);
newCell.SetAttributeValue(NoNamespace.r, GetColumnId(column + columnOffset) + (row + rowOffset).ToString());
XElement formula = newCell.Element(S.f);
if (formula != null)
{
ParseFormula parser = new ParseFormula(formula.Value);
formula.SetValue(parser.ReplaceRelativeCell(rowOffset, columnOffset));
}
SetCell(worksheetXDocument, newCell);
}
}
worksheet.PutXDocument();
ForceCalculateOnLoad(document);
}
示例2: SetSheetContents
// Creates a new worksheet with the specified name and contents from a memory spreadsheet
public static void SetSheetContents(SpreadsheetDocument document, WorksheetPart worksheet, MemorySpreadsheet contents)
{
XDocument worksheetXDocument = worksheet.GetXDocument();
worksheetXDocument.Root.Element(S.sheetData).ReplaceWith(contents.GetElements());
worksheet.PutXDocument();
}