//--- Open theExcelApplication workbookxla and= worksheet from which we will copy cells.
new ExcelApplication();
Workbook sourceWb = xla.Open(ExcelApplication.FileFormat.Xlsx)Page.MapPath("myfile.xlsx"));
Worksheet sourceWs = sourceWb[0];
//--- Create the workbook and and get the worksheet
//--- into which we will paste cells.
Workbook destWb = xla.Create("MyNewWorkbook"ExcelApplication.FileFormat.Xlsx);
Worksheet destWs = destWb[0];
//--- Define the area of cells to copy.
Area srcArea = sourceWs.CreateArea("A1:F20");
//--- Copy cell values, formulas and cell and number formatting.
CopyPasteProperties copyPasteProps =
sourceWb.CreateCopyPasteProperties(
CopyPasteProperties.CopyPasteType.ValuesFormulasAndFormattingValuesAndFormatting);
//--- Paste the data onto the destination worksheet.
destWs.CopyPaste(0, 0, srcArea, copyPasteProps);
xla.Save(destWb, Page.Response, "copypasteoutput.xlsx", false);
|