用Aspose.Words将表单信息写入到word模板中

本文介绍如何使用Aspose.Words库从Web表单数据动态生成Word文档模板,并实现导出功能。通过加载模板文件,设置表单字段,如复选框、文本框等,最终保存为新的Word文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先是要下载Aspose.Words.dll

2.建立word模板我的模板时会议联系函.doc

3.页面

<div id="top">
<ul style="height:50px;margin:0px;">
<li style="float:left;">

<asp:Button ID="btnSave" runat="server" Text="保 存" Width="60px" CssClass="btn" />

<asp:Button ID="btnExport" runat="server" Text="导 出" CssClass="btn" Width="60px" OnClick="btnExport_Click"/>
</li>

</ul>

</div>
<div id="Container">
<div id="Header">

<div id="Title">
<ul style="height:50px;">
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;武汉市政府投资工程审查</li>
</ul>
</div>

<div id="TitleSecond">
<ul style="height:50px;">
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;会议联系函</li>
</ul>
</div>

</div>

<div id="BodyPage">
<div class="Content1">
<ul style="height:1px;">
<li>市建委基础设施处:</li>
</ul>
</div>

<div class="Content1">
<ul style="height:1px; margin:0px;">
<li style="width:30px;float:left"></li>
<li style="float:left;">
<input id="TxtDesigner" type="text" runat="server" class="tbxBottom" style="width: 350px" />
</li>
<li style="float:left">(建设单位)到我办报审的</li>
</ul>

<ul style="height:20px; margin:0px;">
<li style="float:left"><input id="TxtProject" runat="server" type="text" class="tbxBottom" style="width: 450px" /></li>
<li style="float:left;">(项目)</li>
</ul>

<ul style="height:30px; margin:0px;">
<li style="float:left;margin:4px auto;">(</li>
<li style="float:left;">
<%-- <uc1:MLCheckBoxList id="MLCheckBoxList1" runat="server"></uc1:MLCheckBoxList>--%>
<input id="Checkbox1" name="Checkbox1" runat="server" type="checkbox" value="项目建议书" />项目建议书
<input id="Checkbox2" name="Checkbox2" runat="server" type="checkbox" value="可行性研究" />可行性研究
<input id="Checkbox3" name="Checkbox3" runat="server" type="checkbox" value="初步设计" />初步设计

</li>
<li style="float:left;margin:4px auto;"> )文件,拟于</li>
<li style="float:left;">2010年7月10日上午10时</li>
<li style="float:left;margin:7px auto;"></li>
</ul>


<ul style="height:20px; margin:0px;">
<li style="float:left;"><input id="TxtAddress" runat="server" type="text" class="tbxBottom" style="width: 350px" /></li>
<li style="float:left;margin:5px auto;">召开评审会,现在需要邀请以下管</li>
</ul>

<ul style="height:20px; margin:0px;">
<li style="float:left;margin:5px auto;">理部门参加:</li>
<li style="float:left;"><input id="TxtDepartMent1" runat="server" type="text" class="tbxBottom" style="width: 150px" /></li>
<li style="float:left;"><input id="TxtDepartMent2" runat="server" type="text" class="tbxBottom" style="width: 150px" /></li>
<li style="float:left;"><input id="TxtDepartMent3" runat="server" type="text" class="tbxBottom" style="width: 150px" /></li>
</ul>

<ul style="height:10px; margin:0px;">
<li></li>
</ul>

<ul style="height:20px;">
<li style="float:left;padding:40 0 0 30px;">受否,请批示。</li>

</ul>

<ul style="height:10px; margin:0px;">
<li style="float:left;">
<textarea id="TxtDescription" runat="server" cols="8" rows="5" class="textNonClass" onmouseover="this.className='textClass'" onmouseout="this.className='textNonClass'" style="width: 500px;"></textarea>
</li>
</ul>

<ul style="height:50px; margin:0px;">
<li></li>
</ul>
<ul style="height:10px; margin:0 0 0 30px;">
<li style="float:left">
项目负责人:
</li>
<li style="float:left">
<input type="text" runat="server" id="TxtProjectPerson" class="textNonClass" onmousemove="this.className='textClass'" onmouseout="this.className='textNonClass'" style="width: 80px;" />
</li>
<li style="width:65px;"></li>
<li style="float:left">
联系电话:
</li>
<li style="float:left">
<input type="text" runat="server" id="TxtPhone" class="textNonClass" onmousemove="this.className='textClass'"
onmouseout
="this.className='textNonClass'" style="width: 100px;" />
</li>
</ul>
<ul style="height:10px; margin:0px;">
<li></li>
</ul>

<ul style="height:10px; margin:0 0 0 30px;">

<li style="float:left">
部门负责人:
</li>

<li style="float:left; width:90px;">
<input type="text" id="TxtDepartmentHead" runat="server" class="textNonClass" onmousemove="this.className='textClass'" onmouseout="this.className='tbxNoneSolid'" style="width: 80px;" />
</li>
<li style="width:60px;"></li>
<li style="float:left">
分管领导:
</li>
<li style="float:left">
<input type="text" runat="server" id="TxtLeaderShip" class="textNonClass" onmousemove="this.className='textClass'"
onmouseout
="this.className='textNonClass'" style="width: 100px;" />
</li>
</ul>

<ul style="height:50px; margin:0px;">
<li></li>
</ul>

<ul style="height:10px; margin:0px;">
<li> 注:本函一式二份,一份报基础设施处,一份责任部门留存。</li>
</ul>
<ul style="height:70px; margin:0px;">
<li></li>
</ul>
<ul style="height:10px; margin:0px;">
<li> <span class="BoldFont">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 武汉市建设工程设计审查办公室</span></li>
</ul>



</div>
<div class="Content2">
<ul style="height:10px; margin:0 0 0 180px;; position:relative;">
<li>


</li>
</ul>
</div>

<div class="Content1">
<ul style="height:10px; margin:0px;">
<li style="float:left; margin:30px auto;">基础设施处意见:</li>
<li style="float:left; width:200px;"> <textarea id="TxtIdea" runat="server" cols="5" rows="5" class="textNonClass" onmouseover="this.className='textClass'" onmouseout="this.className='textNonClass'" style="width: 180px;"></textarea></li>
<li style="float:left; margin:30px auto;">签字:</li>
<li style="float:left; margin:30px auto;">
<input type="text" id="TxtSign" runat="server" class="textNonClass" onmousemove="this.className='textClass'"
onmouseout
="this.className='textNonClass'" style="width: 60px;" />
</li>
</ul>
</div>



</div>
4..cs文件
protected void btnExport_Click(object sender, EventArgs e) { string DocPath = Server.MapPath("DocTemple/会议联系函.doc"); //载入模板 Document doc = new Document(DocPath); //获取窗体域doc.Range.FormFields["CheckBox1"]是针对模板最好是将模板中的窗体名称与表单中的控件对应 if (doc.Range.FormFields["CheckBox1"] != null) { doc.Range.FormFields["CheckBox1"].Checked = Checkbox1.Checked; } if (doc.Range.FormFields["CheckBox2"] != null) { doc.Range.FormFields["CheckBox2"].Checked =Checkbox2.Checked; } if (doc.Range.FormFields["CheckBox3"] != null) { doc.Range.FormFields["CheckBox3"].Checked = Checkbox3.Checked; } //获取标签TxtDesigner if (doc.Range.Bookmarks["TxtDesigner"] != null) { Bookmark MarkDesigner = doc.Range.Bookmarks["TxtDesigner"]; MarkDesigner.Text = TxtDesigner.Value; } //保存word信息 doc.Save("demo.doc", SaveFormat.Doc, SaveType.OpenInWord, Response); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值