翻譯|使用教程|編輯:李顯亮|2020-08-06 09:48:37.943|閱讀 789 次
概述:在本文中,將使用C#和Aspose.Words for .NET API 以編程方式在Word文檔中創(chuàng)建可填充表單。此外,我們還將介紹刪除或刪除可填寫(xiě)的表單字段。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
可填充表單經(jīng)常在Microsoft Word文檔中使用,例如DOC,DOCX和其他文件格式。
在本文中,我們將使用C#和Aspose.Words for .NET API 以編程方式在Word文檔中創(chuàng)建可填充表單。此外,我們還將介紹刪除或刪除可填寫(xiě)的表單字段。讓我們繼續(xù)學(xué)習(xí)以下用例:
>>Aspose.Words for .NET已經(jīng)更新至v20.7,Aspose.Words for .Net更新至新版本v20.8,此常規(guī)的每月版本中有81項(xiàng)改進(jìn)和修復(fù),主要特點(diǎn)包括實(shí)現(xiàn)了Markdown的“內(nèi)嵌圖片”功能、為字體名稱處理添加了新的字體替換規(guī)則等三大新功能,點(diǎn)擊下方按鈕下載最新版。
點(diǎn)擊下載最新版Aspose.Words for .NET
只需幾個(gè)基本步驟即可輕松在Word文檔中創(chuàng)建或插入復(fù)選框。除了復(fù)選框之外,還將探討如何添加文本框和組合框。以下是在DOCX文件中插入或添加復(fù)選框,文本框和組合框的步驟。
下面的代碼段顯示了如何在C#的Word文件(DOC / DOCX)中插入諸如復(fù)選框,文本框和組合框之類(lèi)的可填充字段:
// 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,可用于設(shè)置表單字段的許多屬性。例如,F(xiàn)ormField類(lèi)可用于設(shè)置大小,默認(rèn)值,進(jìn)入和退出宏等。
參考Word文件中的表單,添加可填寫(xiě)的表單域和刪除可填充的表單域是最重要和最常用的功能?,F(xiàn)在,讓我們看一下如何在.NET應(yīng)用程序中使用C#刪除可填寫(xiě)的表單字段??梢园凑找韵虏襟E刪除字段:
以下代碼段基于這些步驟,這些步驟顯示了如何使用C#從Word文檔中刪除可填寫(xiě)的表單字段:
// 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");還想要更多嗎?您可以點(diǎn)擊閱讀【2020 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問(wèn)或需求,請(qǐng)隨時(shí)加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn