如何使用aspose.cell在工作簿中将一个工作表复制到另一个工作表

本文关键字:工作 一个 另一个 复制 cell aspose 何使用 工作簿 | 更新日期: 2023-09-27 18:02:24

如何复制一个工作表值并在一个工作簿中粘贴另一个工作表。单元格使用asp.net和c#?

谢谢你Parthiban k .

如何使用aspose.cell在工作簿中将一个工作表复制到另一个工作表

我在Aspose担任社交媒体开发人员。Aspose。细胞提供多种选择,以达到您想要的结果。可以将数据从一个工作表导出到另一个工作表,然后使用将数据导入到目标工作表。还可以将所有作为范围的数据复制到目标工作表。检查以下示例:

将范围从第一个工作表复制到目标工作表

//Open the workbook
Workbook workbook = new Workbook("book1.xlsx");
//Select source worksheet
Worksheet worksheet = workbook.Worksheets[0];

//Select Destination Worksheet
Worksheet destSheet = workbook.Worksheets[1]; 
//Get the range of cells with all the data from source worksheet
Aspose.Cells.Range sourceRange = worksheet.Cells.MaxDisplayRange;
//Create a range with same row and column count as source worksheet
Aspose.Cells.Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow, sourceRange.FirstColumn, sourceRange.RowCount, sourceRange.ColumnCount);
//Select Paste Options
PasteOptions options = new PasteOptions();
options.PasteType = PasteType.All;
//Copy the range from source worksheet to destination.
destRange.Copy(sourceRange, options);
//Save the updated worksheet
workbook.Save("book1.xlsx");

从一个工作表导出数据并导入到另一个

//Open the workbook
Workbook workbook = new Workbook("book1.xlsx");
//Select source worksheet
Worksheet worksheet = workbook.Worksheets[0];
//Exporting the of worksheet to DataTable
DataTable dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.MaxRow, worksheet.Cells.MaxColumn, true);
//Select Destination Worksheet
Worksheet destSheet = workbook.Worksheets[1];
//Import data to destination worksheet
destSheet.Cells.ImportDataTable(dataTable, true, "A1");
//Save the updated worksheet
workbook.Save("book1.xlsx");
相关文章: