欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net下將頁面內容導入到word模板中的方法

 更新時間:2010年10月20日 19:04:23   作者:  
asp.net下將頁面內容導入到word模板中的方法,需要的朋友可以參考下。
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: 在此處添加構造函數(shù)邏輯
//
}
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");//做個跳轉用于下載.

相關文章

  • 獲取客戶端IP地址c#/vb.net各自實現(xiàn)代碼

    獲取客戶端IP地址c#/vb.net各自實現(xiàn)代碼

    項目要求獲取客戶端的IP地址,分析并且用c#與vb各自實現(xiàn)了此要求,有需要的朋友可以了解下啊,希望本文對你們有所幫助
    2013-01-01
  • asp.net模板引擎Razor中cacheName的問題分析

    asp.net模板引擎Razor中cacheName的問題分析

    這篇文章主要介紹了asp.net模板引擎Razor中cacheName的問題,實例分析了cacheName在提高編譯效率方面的使用技巧,需要的朋友可以參考下
    2015-06-06
  • ASP.NET Web Page應用深入探討

    ASP.NET Web Page應用深入探討

    這些內容是我在學習ASP.Net的時候對Page研究的一些心得,具體的細節(jié)沒有很詳細的探討,更多的內容請大家參考MSDN,但是我舉了一些初學者常犯的錯誤和出現(xiàn)錯誤的原因,希望可以給大家?guī)韱l(fā)。
    2009-08-08
  • asp.net SqlDataAdapter對象使用札記

    asp.net SqlDataAdapter對象使用札記

    如果 DataAdapter 遇到多個結果集,它將在 DataSet 中創(chuàng)建多個表。將向這些表提供遞增的默認名稱 TableN,以表示 Table0 的“Table”為第一個表名。
    2009-04-04
  • c# 可變數(shù)目參數(shù)params實例

    c# 可變數(shù)目參數(shù)params實例

    一般來說,參數(shù)個數(shù)都是固定的,定義為集群類型的參數(shù)可以實現(xiàn)可變數(shù)目參數(shù)的目的,但是.NET提供了更靈活的機制來實現(xiàn)可變數(shù)目參數(shù),這就是使用params修飾符
    2012-11-11
  • 使用ASP.NET操作IIS7中應用程序

    使用ASP.NET操作IIS7中應用程序

    IIS7的操作和IIS5/6有很大的不同,在IIS7里增加了 Microsoft.Web.Administration 命名空間里,增加了ServerManager、Site幾個大類來操作IIS7。本文主要介紹.NET對IIS7的操作。
    2015-10-10
  • .Net?Core日志記錄之第三方框架Serilog

    .Net?Core日志記錄之第三方框架Serilog

    這篇文章介紹了.Net?Core日志記錄之第三方框架Serilog,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-06-06
  • asp .net core靜態(tài)文件資源的深入講解

    asp .net core靜態(tài)文件資源的深入講解

    這篇文章主要給大家介紹了關于asp .net core靜態(tài)文件資源的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • ASP.NET線程相關配置

    ASP.NET線程相關配置

    ASP.NET 同一時刻只能發(fā)起的工作線程數(shù)量
    2012-12-12
  • 上傳圖片前判斷文件格式與大小驗證文件是不是圖片

    上傳圖片前判斷文件格式與大小驗證文件是不是圖片

    既然上傳的是圖片,那么就應該在上傳之前對文件進行一下驗證,看看要上傳的是不是圖片文件
    2014-03-03

最新評論