我如何使用带有 c# 的 asp.net 复制一个工作表值并将另一个工作表粘贴到 aspose.cell 中的工作簿中?
感谢和问候, 帕提类 K.
最佳答案
我在 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");
关于c# - 如何使用 aspose.cell 将一个工作表复制到工作簿中的另一个工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23538780/