Copy&Paste from Excel to Grid

Do you have any plans in the near future to launch a copy&paste option from Excel to grid? Currently in grid the cells paste as an image, not as values, which makes it difficult to work on the data when several files need to be merged.

@Dorota_EON

Currently, there is no direct feature in Aspose.Cells that allows for copying and pasting data from Excel to a grid while retaining the values instead of pasting them as images. However, you can utilize the existing methods in Aspose.Cells to programmatically copy rows and columns from an Excel file to your grid.

To achieve this, you can use the CopyRow and CopyRows methods provided by the Aspose.Cells API. These methods allow you to copy data, including values, formulas, and formatting, from one location to another within an Excel workbook. Here’s a brief overview of how you can implement this:

  1. Copying a Single Row:
    You can use the CopyRow method to copy a specific row from one worksheet to another. This method takes the source row index and the destination row index as parameters.

    // Load the workbook
    Workbook workbook = new Workbook("path_to_your_excel_file.xlsx");
    Worksheet worksheet = workbook.Worksheets[0];
    
    // Copy the second row to the twelfth row
    worksheet.Cells.CopyRow(worksheet.Cells, 1, 11);
    
    // Save the workbook
    workbook.Save("output_file.xlsx");
    
  2. Copying Multiple Rows:
    If you need to copy multiple rows, you can use the CopyRows method, which allows you to specify the number of rows to copy.

    // Load the workbook
    Workbook workbook = new Workbook("path_to_your_excel_file.xlsx");
    Worksheet worksheet = workbook.Worksheets[0];
    
    // Copy the first three rows to the seventh row
    worksheet.Cells.CopyRows(worksheet.Cells, 0, 6, 3);
    
    // Save the workbook
    workbook.Save("output_file.xlsx");
    
  3. Using Paste Options:
    Aspose.Cells also provides options for pasting data, allowing you to specify whether to paste values, formats, or formulas. This can be particularly useful if you want to control how the data is pasted into your grid.

    // Set up paste options
    PasteOptions pasteOptions = new PasteOptions();
    pasteOptions.PasteType = PasteType.Values; // Only paste values
    
    // Copy and paste with options
    destination.Cells.CopyRows(source.Cells, 0, 0, source.Cells.MaxDisplayRange.RowCount, options, pasteOptions);
    

By using these methods, you can effectively manage the data transfer from Excel to your grid without losing the values. If you have further questions or need assistance with specific implementations, feel free to ask!

Sources:
[1]: Copying Rows and Columns - Aspose Documentation

@Dorota_EON,

Are you using the Aspose.Cells.GridJS control or Aspose.Cells.GridWeb/
Aspose.Cells.GridDesktop, please confirm? Please note that the GridJS control currently does not support copying a range of cells from Excel spreadsheet and pasting them as data/values in the GridJS matrix. Instead, it will paste the copied range as an image. After your confirmation, we will look into your issue/requirements and try to address them soon. We may log an appropriate ticket for the feature/task in our database.