• Word处理控件Aspose.Words功能演示:在Word文档中创建可填充表单


    可填充表单经常在Microsoft Word文档中使用,例如DOC,DOCX和其他文件格式。

    在本文中,我们将使用C#和Aspose.Words for .NET API 以编程方式在Word文档中创建可填充表单。此外,我们还将介绍删除或删除可填写的表单字段。让我们继续学习以下用例:

    • 使用C#在Word中使用复选框,文本框创建可填写的表单字段
    • 使用C#从Word文档中删除可填写的表单字段

    点击下载最新版Aspose.Words for .NET(技术交流Q群:761297826)icon-default.png?t=M85Bhttps://www.evget.com/product/564/download

    使用C#在Word中使用复选框,文本框创建可填写的表单字段

    只需几个基本步骤即可轻松在Word文档中创建或插入复选框。除了复选框之外,还将探讨如何添加文本框和组合框。以下是在DOCX文件中插入或添加复选框,文本框和组合框的步骤。

    • 初始化一个新的Word文档
    • 使用InsertTextInput方法插入文本表单字段
    • 使用InsertCheckBox方法插入复选框字段
    • 使用InsertComboBox方法插入组合框字段
    • 保存输出字文件

    下面的代码段显示了如何在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类可用于设置大小,默认值,进入和退出宏等。

    使用C#删除Word文档中的可填写表格字段

    参考Word文件中的表单,添加可填写的表单域和删除可填充的表单域是最重要和最常用的功能。现在,让我们看一下如何在.NET应用程序中使用C#删除可填写的表单字段。可以按照以下步骤删除字段

    • 使用Document类加载输入的单词文件
    • 通过名称获取特定的可填写表格字段
    • 使用移除方法
    • 保存输出字文件

    以下代码段基于这些步骤,这些步骤显示了如何使用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");
  • 相关阅读:
    fabic.js Quadratic Curve /可控制的曲线
    SpringMVC实现增删改查
    【数据结构】栈和队列
    程序员日常|为什么我在开发工作中偏爱这款键盘?
    21_pre_access 阶段
    用工具实现 Mock API 的整个流程
    圆满收官,百花齐放!2022企业级低代码应用大赛获奖结果公布
    京东商品如何同步主图到长主图
    C语言实战项目---贪吃蛇(上)
    docker部署rustdesk远程控制服务器
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/126779514