本文介绍了如何使用OpenXML在Excel工作表中插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用OpenXML在Excel工作表中添加行



尝试在最后一行之前的Excel表格中插入行。

使用以下逻辑实现。



可以帮助我实现这个目标。





- -----------------------

Sheet sheet = null;

SheetData sheetData;

DocumentFormat.OpenXml.UInt32Value sheetId;

WorksheetPart worksheetPart = null;







sheet = myWorkbook.WorkbookPart.Workbook.GetFirstChild< sheets>()。Elements< sheet>()。First(s => s.Name.Value.Equals(ExcelSheetName,StringComparison.OrdinalIgnoreCase ));

worksheetPart =(WorksheetPart)myWorkbook.WorkbookPart.GetPartById(sheet.Id.Value);

sheetData = worksheetPart.Worksheet.GetFirstChild< sheetdata>();



//尝试以下逻辑

int insertrow = 3;

sheetId = UInt32Value.FromUInt32((uint) )insertrow);

行row = new Row(){RowIndex = sheetId};

sheetData.Append(row);

insertrow ++;



任何人都可以提供一些帮助。

How to add rows in excel sheet using OpenXML

Trying to insert rows in a table in excel sheet before the last row.
Implementing with following logic.

Could any please help me to achieve this.


------------------------
Sheet sheet = null;
SheetData sheetData;
DocumentFormat.OpenXml.UInt32Value sheetId;
WorksheetPart worksheetPart = null;



sheet = myWorkbook.WorkbookPart.Workbook.GetFirstChild<sheets>().Elements<sheet>().First(s => s.Name.Value.Equals("ExcelSheetName", StringComparison.OrdinalIgnoreCase));
worksheetPart = (WorksheetPart)myWorkbook.WorkbookPart.GetPartById(sheet.Id.Value);
sheetData = worksheetPart.Worksheet.GetFirstChild<sheetdata>();

//Trying following logic
int insertrow =3;
sheetId = UInt32Value.FromUInt32((uint)insertrow);
Row row = new Row() { RowIndex = sheetId };
sheetData.Append(row);
insertrow++;

Could anyone please provide some help.

推荐答案

这篇关于如何使用OpenXML在Excel工作表中插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 22:23