写模板后读入数据库

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Word;
using System.Data.SqlClient;

public partial class ksyw_addword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        wordtosql("","");
    }
    private void AddWord()
    {

        SqlDataReader dr = DbHelperSQL.ExecuteReader("select ");

        //ApplicationClass WordApp = new ApplicationClass();
        //object missing = System.Reflection.Missing.Value;
        //string path = Server.MapPath(".");
        //path = path.Substring(0, path.Length - 10);
        //string dotpath = path + "//moban//来信来访登记表.dot";
        //string docpath = path + "//upload//ks//" + ajid + "//来信来访登记表.doc";
        docpath = "E://vs2005//ksyw//ajcl//c.doc";
        //object tempName = @dotpath;
        //object docName = @docpath;
              object isVisible = true;
              object readOnly = false;
              Word.Document WordDoc = WordApp.Documents.Open(ref docName, ref missing, ref readOnly,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing,ref missing);

              WordDoc.Activate();

              //WordApp.Selection.TypeText("This is the text");
             // WordApp.Selection.TypeParagraph();
              //WordDoc.Save();

        //WordApp.Application.Quit(ref missing, ref missing, ref missing);
        //Document MyDoc = wordApp.Documents.Add(ref tempName, ref missing, ref missing, ref missing);
        //wordApp.Visible = true;
        //MyDoc.Activate();
        //for (int i = 1; i <= MyDoc.Bookmarks.Count; i++)
        //{
        //    object j = i;
        //    Word.Range wordRng = MyDoc.Bookmarks.get_Item(ref   j).Range;
        //    string name = MyDoc.Bookmarks.get_Item(ref j).Name;
        //    wordRng.Text = MyDoc.Bookmarks.get_Item(ref j).Name;
        //}

        wordApp.Selection.Font.Size = 30; // 字体大小
        wordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; // 居中
        wordApp.Selection.Font.Bold = (int)WdConstants.wdToggle; // 黑体
        wordApp.Selection.TypeText("hello");
        保存
        //MyDoc.SaveAs(ref docName, 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);
        //MyDoc.Close(ref missing, ref missing, ref missing);
        //wordApp.Quit(ref missing, ref missing, ref missing);
        //MyDoc = null;
        //wordApp = null;
    }
    private void wordtosql(string filepath,string ajid)
    {
        StringBuilder str = new StringBuilder();
        string path = Server.MapPath(".");
        path = path.Substring(0, path.Length - 5);
        string dotpath = path + "//moban//来信来访登记表.dot";
        ajid="2009_0026";
        string docpath = path + "//upload//ks//" + ajid + "//aj1cs.doc";
           filepath=docpath;
              if (filepath != "")
             {
                    FileStream fs=File.OpenRead(filepath);

                    System.IO.BinaryReader br = null;
                    br = new BinaryReader((Stream)fs);
                    byte[] b = new byte[fs.Length];
                    int intLength = (int)fs.Length;
                    b = br.ReadBytes(intLength);
                    fs.Close();
                     str.Append("insert into ks_file(filename,ksaj_id,doccontent,filetype,doctype) values(@filename,@ksaj_id,@doccontent,@filetype,@doctype)");
                    SqlParameter[] p ={
                    new SqlParameter("@filename", SqlDbType.VarChar,50),
                    new SqlParameter("@ksaj_id", SqlDbType.VarChar,50),
                    new SqlParameter("@doccontent", SqlDbType.Image,intLength),
                    new SqlParameter("@filetype", SqlDbType.VarChar,50),
                    new SqlParameter("@doctype", SqlDbType.VarChar,50)
                    };
                    p[0].Value = "as.doc";
                    p[1].Value = "2009_0028";
                    p[2].Value =b;
                    p[3].Value = "证据材料";
                    p[4].Value = "doc";

                    int n= DbHelperSQL.ExecuteSql(str.ToString(), p);
                    if (n > 0)
                    {
                    Response.Write("dnal");
                    }
                    else
                    {
                    Response.Write("shibai");
                    }
              
       }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值