Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example
Code Block
csharp
csharp
titleC#

          //--- Open the workbook and worksheet from which we will copy cells.
          Workbook sourceWb = xla.Open("MyDataSource.xls"ExcelApplication.FileFormat.Xlsx);
          Worksheet sourceWs = sourceWb[0];

          //--- Create the workbook and and get the worksheet
          //--- into which we will paste cells.
          WorkbbokWorkbook destWb = xla.Create("MyNewWorkbook");
          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.ValueFormulasAndFormatting);

          //--- Paste the data onto the destination worksheet.
          destWs.CopyPaste(0, 0, srcArea, copyPasteProps);
        
Code Block
vb.net
vb.net
titlevb.net

          '--- Open the workbook and worksheet from which we will copy cells.
          Dim sourceWb As Workbook = xla.Open("MyDataSource.xls")
          Dim sourceWs As Worksheet = sourceWb(0)

          '--- Create the workbook and and get the worksheet
          '--- into which we will paste cells.
          Dim destWb As Workbook = xla.Create("MyNewWorkbook")
          Dim destWs As Worksheet = destWb(0)

          '--- Define the area of cells to copy.
          Dim srcArea As Area = sourceWs.CreateArea("A1:F20")

          '--- Copy cell values, formulas and cell and number formatting.
          Dim copyPasteProps As CopyPasteProperties = _
               sourceWb.CreateCopyPasteProperties( _
               CopyPasteProperties.CopyPasteType.ValueFormulasAndFormatting)

          '--- Paste the data onto the destination worksheet.
          destWs.CopyPaste(0, 0, srcArea, copyPasteProps)