Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 6, 2021 11:03
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/91953e5b36223b2b43268c46d5b32394 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/91953e5b36223b2b43268c46d5b32394 to your computer and use it in GitHub Desktop.
Copy Rows and Columns in Excel using C++
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// 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")));
// Get the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Copy Column
worksheet->GetICells()->CopyIColumn(worksheet->GetICells(), 0, 6);
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("CopyColumn_out.xlsx")));
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// 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")));
// Get the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Copy Columns
worksheet->GetICells()->CopyIColumns(worksheet->GetICells(), 0, 6, 3);
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("CopyColumns_out.xlsx")));
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// 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")));
// Get the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Copy Row
worksheet->GetICells()->CopyIRow(worksheet->GetICells(), 1, 15);
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("CopyRow_out.xlsx")));
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// 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")));
// Get the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Copy Rows
worksheet->GetICells()->CopyIRows(worksheet->GetICells(), 1, 15, 3);
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("CopyRows_out.xlsx")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment