//--- Open the workbook and worksheet from which we will copy cells.
ExcelApplication xla = new ExcelApplication();
Workbook sourceWb = xla.Open(Page.MapPath("MyDataSourcemyfile.xlsxlsx"));
Worksheet sourceWs = sourceWb[0];
//--- Create the destination workbook and and get the worksheet
//--- into which we will paste cells.
Workbbok 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");
//--- CopyCreate cellthe values,CopyPasteProperties formulasobject and celldefine andwhich numbersettings formatting.will be copied.
CopyPasteProperties copyPasteProps =
sourceWb.CreateCopyPasteProperties(
CopyPasteProperties.CopyPasteType.ValueFormulasAndFormattingValuesAndFormatting);
//--- Paste the data onto the destination worksheet.
destWs.CopyPaste(0, 0, srcArea, copyPasteProps);
|