翻譯|使用教程|編輯:李顯亮|2020-08-06 09:48:37.943|閱讀 789 次
概述:在本文中,將使用C#和Aspose.Words for .NET API 以編程方式在Word文檔中創建可填充表單。此外,我們還將介紹刪除或刪除可填寫的表單字段。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
可填充表單經常在Microsoft Word文檔中使用,例如DOC,DOCX和其他文件格式。
在本文中,我們將使用C#和Aspose.Words for .NET API 以編程方式在Word文檔中創建可填充表單。此外,我們還將介紹刪除或刪除可填寫的表單字段。讓我們繼續學習以下用例:
>>Aspose.Words for .NET已經更新至v20.7,Aspose.Words for .Net更新至新版本v20.8,此常規的每月版本中有81項改進和修復,主要特點包括實現了Markdown的“內嵌圖片”功能、為字體名稱處理添加了新的字體替換規則等三大新功能,點擊下方按鈕下載最新版。
只需幾個基本步驟即可輕松在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文件中的表單,添加可填寫的表單域和刪除可填充的表單域是最重要和最常用的功能。現在,讓我們看一下如何在.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");還想要更多嗎?您可以點擊閱讀【2020 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn