3

如何使用带有 c# 的 asp.net 复制一个工作表值并将另一个工作表粘贴到 aspose.cell 的工作簿中?

谢谢和尊重, Parthiban K.

4

1 回答 1

3

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

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

//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");
于 2014-05-08T11:34:47.887 回答