无需MS Office创建Excel!使用 C++ 在 Excel 工作表中添加注释

Microsoft Excel 提供了在 Excel 文件中添加注释的选项,在本文中,您将学习 如何使用 C++ 以编程方式向 Excel 工作表添加注释。

Microsoft Excel 提供了在 Excel 文件中添加注释的选项。添加注释可能有多种原因,例如解释公式或添加可能对读者有用的上下文信息。评论也可用于建议在工作表中进行编辑。此外,可以设置评论的字体大小、高度、宽度等。在本文中,将学习 如何使用 C++ 以编程方式向 Excel 工作表添加注释。

  • 使用 C++ 在 Excel 工作表中添加注释
  • 使用 C++ 将格式应用于 Excel 工作表中的注释
  • <


使用 C++ 在 Excel 工作表中添加注释

以下是向 Excel 工作表中的单元格添加注释的步骤。

  • 使用IWorkbook 类加载 Excel 文件 。
  • 检索要添加注释的工作表。
  • 使用IWorksheet->GetIComments()->Add(intrusive_ptrcellName)方法添加注释。
  • 使用IWorksheet->GetIComments()->GetObjectByIndex(Aspose::Cells::Systems::Int32 索引)方法检索上一步中添加的注释。
  • 使用IComment->SetNote(intrusive_ptrvalue)方法设置注释的注释。
  • 使用IWorkbook->Save(intrusive_ptrfileName) 方法保存 Excel 文件 。

以下示例代码显示了如何使用 C++ 向 Excel 工作表中的单元格添加注释。

// Source directory path.StringPtr srcDir = new String("SourceDirectory\Excel\");// Output directory path.StringPtr outDir = new String("OutputDirectory\");// Load the source Excel fileintrusive_ptrworkbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx")));// Retrieve the first worksheetintrusive_ptrworksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);// Add comment to the cell F5int commentIndex = worksheet->GetIComments()->Add(new String("F5"));// Retrieve the comment added to the cell F5intrusive_ptrcomment = worksheet->GetIComments()->GetObjectByIndex(commentIndex);// Set the comment notecomment->SetNote(new String("Hello Aspose!"));// Save the Excel fileworkbook->Save(outDir->StringAppend(new String("AddComment_out.xlsx")));

使用 C++ 将格式应用于 Excel 工作表中的注释

以下是使用 C++ 将格式应用于 Excel 工作表中的注释的步骤。

  • 使用IWorkbook 类加载 Excel 文件 。
  • 检索要添加注释的工作表。
  • 使用IWorksheet->GetIComments()->Add(intrusive_ptrcellName)方法添加注释。
  • 使用IWorksheet->GetIComments()->GetObjectByIndex(Aspose::Cells::Systems::Int32 索引)方法检索上一步中添加的注释。
  • 使用IComment->SetNote(intrusive_ptrvalue)方法设置注释的注释。
  • 根据您的需要设置注释的格式。
  • 使用IWorkbook->Save(intrusive_ptrfileName) 方法保存 Excel 文件 。

以下示例代码显示如何使用 C++ 将格式应用于 Excel 工作表中的注释。

// Source directory path.StringPtr srcDir = new String("SourceDirectory\Excel\");// Output directory path.StringPtr outDir = new String("OutputDirectory\");// Load the source Excel fileintrusive_ptrworkbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx")));// Retrieve the first worksheetintrusive_ptrworksheet = workbook->GetIWorksheets()->GetObjectByIndex(0);// Add comment to the cell F5int commentIndex = worksheet->GetIComments()->Add(new String("F5"));// Retrieve the comment added to the cell F5intrusive_ptrcomment = worksheet->GetIComments()->GetObjectByIndex(commentIndex);// Set the comment notecomment->SetNote(new String("Hello Aspose!"));// Set the font sizecomment->GetIFont()->SetSize(14);// Set the font weightcomment->GetIFont()->SetBold(true);// Set the height in CMcomment->SetHeightCM(10);// Set the width in CMcomment->SetWidthCM(2);// Save the Excel fileworkbook->Save(outDir->StringAppend(new String("ApplyFormattingToComment_out.xlsx")));

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年8月4日
下一篇 2021年8月4日

相关推荐

发表回复

登录后才能评论