无为清净楼资源网 Design By www.qnjia.com
1,新建word模版,方法是找需要用程序填充的word文档,在需要输入的地方用"书签"(插入-->书签-->输入id-->ok)标记后保存既可.
2,在word模版上修改安全添加everyone 可读,以防文件无法打开.
3,在工程里添加"引用"找到"Microsoft Word 10.0 Object Library"或"Microsoft Word 11.0 Object Library"点确定.
4,新建类叫WordOp.cs 意思是操作word的类.
内容如下:
复制代码 代码如下:
using System;
using System.Web.Security;
using Microsoft.Office.Interop.Word;
using System.IO;
/// <summary>
/// Word 的摘要说明
/// </summary>
public class WordOp
{
public WordOp()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private ApplicationClass WordApp ;
private Document WordDoc;
private static bool isOpened=false;//判断word模版是否被占用
public void SaveAs(string strFileName,bool isReplace)
{
if (isReplace && File.Exists(strFileName))
{
File.Delete(strFileName);
}
object missing = Type.Missing;
object fileName = strFileName;
WordDoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
//定义一个Word.Application 对象
public void activeWordApp()
{
WordApp = new ApplicationClass();
}
public void Quit()
{
object missing = System.Reflection.Missing.Value;
WordApp.Application.Quit(ref missing, ref missing, ref missing);
isOpened = false;
}
//基于模版新建Word文件
public void OpenTempelte(string strTemppath)
{
object Missing = Type.Missing;
//object Missing = System.Reflection.Missing.Value;
activeWordApp();
WordApp.Visible = false;
object oTemplate = (object)strTemppath;
try
{
while (isOpened)
{
System.Threading.Thread.Sleep(500);
}
WordDoc = WordApp.Documents.Add(ref oTemplate, ref Missing, ref Missing, ref Missing);
isOpened = true;
WordDoc.Activate();
}
catch (Exception Ex)
{
Quit();
isOpened = false;
throw new Exception(Ex.Message);
}
}
public void FillLable(string LabelId,string Content)
{
//打开Word模版
// OpenTempelte(tempName); //对LabelId的标签进行填充内容Content,即函件题目项
object bkmC = LabelId;
if (WordApp.ActiveDocument.Bookmarks.Exists(LabelId) == true)
{
WordApp.ActiveDocument.Bookmarks.get_Item(ref bkmC).Select();
}
WordApp.Selection.TypeText(Content);
//SaveAs(saveAsFileName);
//Quit();
}
}

5,在需要使用的页面后台调用既可,举例如下:
复制代码 代码如下:
string path = Server.MapPath("download");
string templatePath = path + "file://downloadczql.doc/";
WordOp wop = new WordOp();
wop.OpenTempelte(templatePath);
wop.FillLable("id", "1");
wop.FillLable("usr_name", "测试");
wop.SaveAs(path + "file://savetest.doc",true/);
wop.Quit();
Response.redirect(@"/download/savetest.doc");//做个跳转用于下载.
标签:
页面内容,word模板

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。