Read the complete article on copying rows and columns in Excel using C#: https://blog.aspose.com/2021/07/15/copy-rows-and-columns-in-excel-using-csharp/
Last active
January 30, 2022 18:08
-
-
Save aspose-com-gists/badef5dcc0845289eb79e3fed242c6cd to your computer and use it in GitHub Desktop.
Copy Rows and Columns in Excel using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Excel file | |
Workbook excelWorkbook1 = new Workbook("book1.xlsx"); | |
// Get reference of the first worksheet | |
Worksheet ws1 = excelWorkbook1.Worksheets[0]; | |
// Copy the first column from the first worksheet of the workbook | |
ws1.Cells.CopyColumn(ws1.Cells, ws1.Cells.Columns[0].Index, ws1.Cells.Columns[2].Index); | |
// Autofit the column | |
ws1.AutoFitColumn(2); | |
// Save the Excel file | |
excelWorkbook1.Save("output.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Excel file | |
Workbook excelWorkbook1 = new Workbook("book1.xlsx"); | |
// Get reference of the first worksheet | |
Worksheet ws1 = excelWorkbook1.Worksheets[0]; | |
// Copy the second row with data, formattings, images and drawing objects to the 16th row in the worksheet | |
ws1.Cells.CopyRow(ws1.Cells, 1, 15); | |
// Save the Excel file | |
excelWorkbook1.Save("output.xlsx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment