翻譯|使用教程|編輯:胡濤|2023-02-13 11:15:54.110|閱讀 261 次
概述:在本文中,我們將使用 C# 和Aspose.Words for .NET API 以編程方式在 Word 文檔中創建一個可填寫的表單,歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words 是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
可填寫表單經常用于 Microsoft Word 文檔,如DOC、DOCX和其他文件格式。在本文中,我們將使用 C# 和Aspose.Words for .NET API 以編程方式在 Word 文檔中創建一個可填寫的表單。此外,我們還將介紹刪除或刪除可填寫的表單字段。
您可以在您的 .NET 應用程序中為 .NET API 配置 Aspose.Words,然后將其與 C# 或 VB.NET 一起使用。您可以從新版本部分下載 DLL或使用以下 NuGet 命令對其進行配置。
PM> Install-Package Aspose.Words -Version 20.8.0
此外,您還可以在 Visual Studio 中使用 NuGet Manager for Solution 工具安裝 API,如下圖所示:
所以API已經在這一步配置好了。讓我們繼續學習以下用例:
您可以通過幾個基本步驟輕松地在 Word 文檔中創建或插入復選框。除了復選框之外,我們還將探討如何添加文本框和組合框。以下是在 DOCX 文件中插入或添加復選框、文本框和組合框的步驟。
下面的代碼片段顯示了如何在 C# 中的 Word 文件 (DOC/DOCX) 中插入復選框、文本框和組合框等可填寫字段:
// Initialize new Word document Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); // Insert Text Form Field Aspose.Words.Fields.FormField text = builder.InsertTextInput("TextInput", Aspose.Words.Fields.TextFormFieldType.Regular, "", "Hello", 0); // Add line break builder.InsertBreak(Aspose.Words.BreakType.LineBreak); // Insert Checkbox Form Field Aspose.Words.Fields.FormField checkbox = builder.InsertCheckBox("CheckBox", true, true, 0); checkbox.Checked = true; builder.InsertBreak(Aspose.Words.BreakType.LineBreak); string[] items = { "One", "Two", "Three" }; // Insert Combobox Form Field Aspose.Words.Fields.FormField combo = builder.InsertComboBox("DropDown", items, 0); //builder.InsertBreak(Aspose.Words.BreakType.LineBreak); dataDir = dataDir + "InsertFormFields.docx"; doc.Save(dataDir);
此外,Aspose.Words for .NET API 是一個功能豐富的 API,可讓您設置表單字段的許多屬性。例如,FormField 類可用于設置大小、默認值、進入和退出宏等。
添加可填寫表單域和刪除可填寫表單域是引用word文件中的表單最重要和最常用的功能?,F在,讓我們看一下如何在 .NET 應用程序中使用 C# 刪除可填寫的表單字段。您可以按照以下步驟刪除字段:
以下代碼片段基于這些步驟,展示了如何使用 C# 從 word 文檔中刪除可填寫的表單字段:
// Load source DOCX file Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + "InsertFormFields.docx"); // Load form fields of the word file Aspose.Words.Fields.FormFieldCollection documentFormFields = doc.Range.FormFields; // Access the checkbox Aspose.Words.Fields.FormField checkbox = documentFormFields["CheckBox"]; //Delete or remove checkbox checkbox.Remove(); // Save updated DOCX file doc.Save(dataDir + "DeleteField.docx");
以上便是在 Word 中制作可填寫的表格 | 在 C# 中插入、刪除復選框和字段 ,要是您還有其他關于產品方面的問題,歡迎咨詢我們,或者加入我們官方技術交流群。
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn