翻譯|行業(yè)資訊|編輯:胡濤|2024-08-15 14:20:37.037|閱讀 72 次
概述:在這篇博文中,我們將學(xué)習(xí)如何使用 C# 在 Excel 中讀取、添加和編輯線程注釋,歡迎查閱
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Excel 中的線程注釋是協(xié)作工作的重要功能。它允許多個(gè)用戶在共享文檔中添加、編輯和查看對話線程。在某些情況下,我們可能需要以編程方式管理這些線程注釋。在這篇博文中,我們將學(xué)習(xí)如何使用 C# 在 Excel 中讀取、添加和編輯線程注釋。
Aspose.Cells 是Excel電子表格編程API,可加快電子表格的管理和處理任務(wù),支持構(gòu)建能夠生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印電子表格的跨平臺應(yīng)用程序。同時(shí)不依賴于Microsoft Excel或任何Microsoft Office Interop組件,Aspose API 支持旗下產(chǎn)品覆蓋文檔、圖表、PDF、條碼、OCR、CAD、HTML、電子郵件等各個(gè)文檔管理領(lǐng)域,為全球.NET 、Java、C ++等10余種平臺開發(fā)人員提供豐富的開發(fā)選擇。
為了處理 Excel 工作表中的線程注釋,我們將使用Aspose.Cells for .NET API。它是一個(gè)功能強(qiáng)大的電子表格編程 API,使開發(fā)人員能夠在 .NET 應(yīng)用程序中創(chuàng)建、操作和轉(zhuǎn)換 Excel 文件。通過利用 Aspose.Cells for .NET,我們可以輕松地在 Excel 工作表中添加、讀取、編輯或刪除線程注釋。
要使用 API,請下載 DLL或使用以下命令從NuGet安裝它:
PM> Install-Package Aspose.Cells
以下代碼示例顯示如何使用 C# 向 Excel 工作表添加線程注釋。
// This code example demonstrates how to add threaded comments in an Excel worksheet // Create an instance of the Workbook class Workbook workbook = new Workbook(); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Add an Author var authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add("Aspose Test", "", ""); var author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; // Add Threaded Comment worksheet.Comments.AddThreadedComment("A1", "Test Threaded Comment", author); // Save the output file workbook.Save("AddThreadedComments_out.xlsx");
要從 Excel 工作表中的指定單元格讀取線程注釋,請按照以下步驟操作:
以下代碼示例顯示如何使用 C# 從 Excel 工作表中讀取指定列的線程注釋。
// This code example demonstrates how to read threaded comments for a specified cell in an Excel worksheet // Load an existing Excel file Workbook workbook = new Workbook("AddThreadedComments_out.xlsx"); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Get Threaded Comments for a specific cell var threadedComments = worksheet.Comments.GetThreadedComments("A1"); // Read the threaded comments foreach (var comment in threadedComments) { Console.WriteLine("Author Name: " + comment.Author.Name); Console.WriteLine("Threaded comment Notes:" + comment.Notes); } Author Name: author@domain.com Threaded comment Notes:Test Threaded Comment
類似地,我們可以按照以下步驟讀取 Excel 工作表中所有可用的主題評論:
以下代碼示例顯示如何使用 C# 從 Excel 工作表讀取所有線程注釋。
// This code example demonstrates how to read threaded comments for a specified cell in an Excel worksheet // Load an existing Excel file Workbook workbook = new Workbook("AddThreadedComments_out.xlsx"); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Get all the comments var comments = worksheet.Comments; // Read all the threaded comments foreach (var comment in comments) { // Process threaded comments foreach (var threadedComment in comment.ThreadedComments) { Console.WriteLine("Author Name: " + threadedComment.Author.Name); Console.WriteLine("Threaded comment author User Id: " + threadedComment.Author.UserId); Console.WriteLine("Threaded comment author ProviderId:" + threadedComment.Author.ProviderId); Console.WriteLine("Threaded comment Notes:" + threadedComment.Notes); } }
請按照以下步驟更新 Excel 中的任何主題評論:
以下代碼示例展示如何使用 C# 編輯 Excel 工作表中的線程注釋
// This code example demonstrates how to edit threaded comments in an Excel worksheet // Load an existing Excel file Workbook workbook = new Workbook("AddThreadedComments_out.xlsx"); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Get Threaded Comments for a specific cell var threadedComments = worksheet.Comments.GetThreadedComments("A1"); var comment = threadedComments[0]; // Update the comment note comment.Notes = "Updated Comment"; // Save the output file workbook.Save("EditThreadedComments.xlsx");
我們還可以按照以下步驟刪除Excel工作表中特定單元格的線程注釋:
以下代碼示例顯示如何使用 C# 刪除 Excel 工作表中的線程注釋。
// This code example demonstrates how to delete threaded comments in an Excel worksheet // Load an existing Excel file Workbook workbook = new Workbook("AddThreadedComments_out.xlsx"); // Get all the comments var comments = workbook.Worksheets[0].Comments; // Remove Comments comments.RemoveAt("A1"); // Save the output file workbook.Save("DeleteThreadedComments.xlsx");
在本文中,我們學(xué)習(xí)了如何使用 C# 讀取、添加、編輯和刪除 Excel 工作表中的線程注釋。通過利用 Aspose.Cell for .NET,您可以輕松地在 C# 應(yīng)用程序中操作 Excel 工作表。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn