Cells.CopyColumns

CopyColumns(Cells, int, int, int)

Copies data and formats of a whole column.

public void CopyColumns(Cells sourceCells0, int sourceColumnIndex, int destinationColumnIndex, 
    int columnNumber)
ParameterTypeDescription
sourceCells0CellsSource Cells object contains data and formats to copy.
sourceColumnIndexInt32Source column index.
destinationColumnIndexInt32Destination column index.
columnNumberInt32The copied column number.

Examples

// Called: cells.CopyColumns(cells, 4, 5, 1);
public void Cells_Method_CopyColumns()
{
    Workbook wb = new Workbook(Constants.sourcePath + "example.xlsx");
    Cells cells = wb.Worksheets[0].Cells;
    cells.CopyRows(cells, 1, 2, 1);
          
    cells.CopyColumns(cells, 4, 5, 1);
    Assert.AreEqual(wb.Worksheets[0].SparklineGroups.Count, 4);
}

See Also


CopyColumns(Cells, int, int, int, int)

Copies data and formats of the whole columns.

public void CopyColumns(Cells sourceCells, int sourceColumnIndex, int sourceTotalColumns, 
    int destinationColumnIndex, int destinationTotalColumns)
ParameterTypeDescription
sourceCellsCellsSource Cells object contains data and formats to copy.
sourceColumnIndexInt32Source column index.
sourceTotalColumnsInt32The number of the source columns.
destinationColumnIndexInt32Destination column index.
destinationTotalColumnsInt32The number of the destination columns.

See Also


CopyColumns(Cells, int, int, int, PasteOptions)

Copies data and formats of a whole column.

public void CopyColumns(Cells sourceCells0, int sourceColumnIndex, int destinationColumnIndex, 
    int columnNumber, PasteOptions pasteOptions)
ParameterTypeDescription
sourceCells0CellsSource Cells object contains data and formats to copy.
sourceColumnIndexInt32Source column index.
destinationColumnIndexInt32Destination column index.
columnNumberInt32The copied column number.
pasteOptionsPasteOptionsthe options of pasting.

Examples

// Called: upgradingWorkbook.Worksheets[workSheet.Name].Cells.CopyColumns(workSheet.Cells, 0, 0, workSheet.Cells.MaxColumn + 1, new PasteOptions() { PasteType = PasteType.Formats }); // raises the exception
private static void Cells_Method_CopyColumns(Worksheet workSheet, Workbook upgradingWorkbook)
        {
            if (upgradingWorkbook.Worksheets[workSheet.Name] != null && upgradingWorkbook.Worksheets[workSheet.Name].Index != -1)
            {

                if (workSheet.Cells.MaxColumn >= 0)
                {
                    try
                    {
                        //Copy Columns is having issue in latest version of aspose
                        upgradingWorkbook.Worksheets[workSheet.Name].Cells.CopyColumns(workSheet.Cells, 0, 0, workSheet.Cells.MaxColumn + 1, new PasteOptions() { PasteType = PasteType.Formats }); // raises the exception
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    //Copy Rows works fine in any version
                    //upgradingWorkbook.Worksheets[workSheet.Name].Cells.CopyRows(workSheet.Cells, 0, 0, workSheet.Cells.MaxColumn + 1);
                    Aspose.Cells.Range range = workSheet.Cells.CreateRange(0, 0, workSheet.Cells.MaxRow + 1, workSheet.Cells.MaxColumn + 1);
                    Aspose.Cells.Range upgradeRange = upgradingWorkbook.Worksheets[workSheet.Name].Cells.CreateRange(0, 0, workSheet.Cells.MaxRow + 1, workSheet.Cells.MaxColumn + 1);
                    upgradeRange.CopyData(range);

                }
            }
        }

See Also