Last active
April 23, 2021 18:00
-
-
Save aspose-com-gists/40d92e679534a123d60ab9a02c09359e to your computer and use it in GitHub Desktop.
Inserting and Deleting 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
Examples for Inserting and Deleting 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
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the input Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Delete 2 columns from the worksheet starting at the 2nd position | |
worksheet->GetICells()->DeleteColumns(1, 2, true); | |
// Path of output Excel file | |
StringPtr outputDeleteColumns = outDir->StringAppend(new String("outputDeleteColumns.xlsx")); | |
// Save the Excel file. | |
workbook->Save(outputDeleteColumns); |
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
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the input Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Delete 2 rows starting from the 3rd row | |
worksheet->GetICells()->DeleteRows(2, 2, true); | |
// Path of output Excel file | |
StringPtr outputDeleteRows = outDir->StringAppend(new String("outputDeleteRows.xlsx")); | |
// Save the Excel file. | |
workbook->Save(outputDeleteRows); |
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
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the input Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Insert 2 columns into the worksheet at 2nd position | |
worksheet->GetICells()->InsertColumns(1, 2); | |
// Path of output Excel file | |
StringPtr outputInsertColumns = outDir->StringAppend(new String("outputInsertColumns.xlsx")); | |
// Save the Excel file. | |
workbook->Save(outputInsertColumns); |
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
// Source directory path. | |
StringPtr srcDir = new String("SourceDirectory\\"); | |
// Output directory path. | |
StringPtr outDir = new String("OutputDirectory\\"); | |
// Load the input Excel file | |
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); | |
// Access the first worksheet in the Excel file | |
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0); | |
// Insert 2 rows into the worksheet at 3rd position | |
worksheet->GetICells()->InsertRows(2, 2); | |
// Path of output Excel file | |
StringPtr outputInsertRows = outDir->StringAppend(new String("outputInsertRows.xlsx")); | |
// Save the Excel file. | |
workbook->Save(outputInsertRows); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment