Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/40d92e679534a123d60ab9a02c09359e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/40d92e679534a123d60ab9a02c09359e to your computer and use it in GitHub Desktop.
Inserting and Deleting Rows and Columns In Excel using C++
Examples for Inserting and Deleting Rows and Columns In Excel using C++
// 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);
// 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);
// 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);
// 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