Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 7, 2021 11:06
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/3fba100568c3e5988c396dd0630449d2 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/3fba100568c3e5988c396dd0630449d2 to your computer and use it in GitHub Desktop.
Add Comments in Excel Worksheets using C++
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// Output directory path.
StringPtr outDir = new String("OutputDirectory\\");
// Load the source Excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx")));
// Retrieve the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Add comment to the cell F5
int commentIndex = worksheet->GetIComments()->Add(new String("F5"));
// Retrieve the comment added to the cell F5
intrusive_ptr<IComment> comment = worksheet->GetIComments()->GetObjectByIndex(commentIndex);
// Set the comment note
comment->SetNote(new String("Hello Aspose!"));
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("AddComment_out.xlsx")));
// Source directory path.
StringPtr srcDir = new String("SourceDirectory\\Excel\\");
// Output directory path.
StringPtr outDir = new String("OutputDirectory\\");
// Load the source Excel file
intrusive_ptr<IWorkbook> workbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx")));
// Retrieve the first worksheet
intrusive_ptr<IWorksheet> worksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);
// Add comment to the cell F5
int commentIndex = worksheet->GetIComments()->Add(new String("F5"));
// Retrieve the comment added to the cell F5
intrusive_ptr<IComment> comment = worksheet->GetIComments()->GetObjectByIndex(commentIndex);
// Set the comment note
comment->SetNote(new String("Hello Aspose!"));
// Set the font size
comment->GetIFont()->SetSize(14);
// Set the font weight
comment->GetIFont()->SetBold(true);
// Set the height in CM
comment->SetHeightCM(10);
// Set the width in CM
comment->SetWidthCM(2);
// Save the Excel file
workbook->Save(outDir->StringAppend(new String("ApplyFormattingToComment_out.xlsx")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment