翻譯|使用教程|編輯:李顯亮|2021-09-07 10:02:08.123|閱讀 217 次
概述:Microsoft Excel 提供了在 Excel 文件中添加注釋的選項,在本文中,您將學習 如何使用 C++ 以編程方式向 Excel 工作表添加注釋。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Microsoft Excel 提供了在 Excel 文件中添加注釋的選項。添加注釋可能有多種原因,例如解釋公式或添加可能對讀者有用的上下文信息。評論也可用于建議在工作表中進行編輯。此外,可以設置評論的字體大小、高度、寬度等。在本文中,將學習 如何使用 C++ 以編程方式向 Excel 工作表添加注釋。
Aspose.Cells for C++是一個原生的 C++ 庫,允許您處理 Excel 文件。使用 API,您可以輕松創建、讀取和修改 Excel 文件。此外,您可以向 Excel 工作表添加注釋。
以下是向 Excel 工作表中的單元格添加注釋的步驟。
以下示例代碼顯示了如何使用 C++ 向 Excel 工作表中的單元格添加注釋。
// Source directory path. StringPtr srcDir = new String("SourceDirectory\\Excel\\"); // Output directory path. StringPtr outDir = new String("OutputDirectory\\"); // Load the source Excel file intrusive_ptrworkbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); // Retrieve the first worksheet intrusive_ptrworksheet = 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_ptrcomment = 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")));
以下是使用 C++ 將格式應用于 Excel 工作表中的注釋的步驟。
以下示例代碼顯示如何使用 C++ 將格式應用于 Excel 工作表中的注釋。
// Source directory path. StringPtr srcDir = new String("SourceDirectory\\Excel\\"); // Output directory path. StringPtr outDir = new String("OutputDirectory\\"); // Load the source Excel file intrusive_ptrworkbook = Factory::CreateIWorkbook(srcDir->StringAppend(new String("Sample1.xlsx"))); // Retrieve the first worksheet intrusive_ptrworksheet = 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_ptrcomment = 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")));
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn