现在做一个OA项目,事项归档时候需要生成Word文件放到 归档的文件夹里。在数据库取出一列导入word里 然后在上传到相应的文件夹里。
现在的问题是  怎么导入word文档里。 网上一搜一大堆。  
测试了一下。 没一个对地。。
求正解 等待ing

解决方案 »

  1.   

    你保存在数据库的不是word文档吗?
    直接从数据库取出来就行了啊
      

  2.   

    就是C#往word里写入内容网上应该不少吧
      

  3.   

    挺多的,自己找拉。C#操作WORD
      

  4.   

    和导入execl一样的吧,怎么会不行?
      

  5.   

    真实孩子没娘说起来话长呀!算了直接给你vb.net的源码吧! Dim wrd As New Word.Application
         Try
                    With wrd 
                        .Documents.Open(MapPath("template/你的模板.doc"))   '打开模板
                        bmcount = .ActiveDocument.Books.Count
                        For j = bmcount To 1 Step -1
                            bmName = UCase(.ActiveDocument.Books.Item(j).Name)
                            fdname = .ActiveDocument.Books.Item(j).Name                        .ActiveDocument.Books.Item(j).Select()
                            Select Case fdname
                                Case "PC_ID"
                                    .Selection.Text = pclsUser.DJTL_PC
                                                        End Select
                        Next
                    End With
                wrd.ActiveDocument.Save()
                berror = False
                wrd.ActiveDocument.Close()
                wrd.Quit()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wrd)
                wrd = Nothing
                System.GC.Collect()
            Catch ex As Exception
    end try
      

  6.   

    打开word模板,导入数据到标签里
    public string ExportDFFK(DataSet ds,System.Web.UI.Page page,string FileName)
    {
    string strM="";
    object nothing=System.Reflection.Missing.Value;
    object optional=System.Reflection.Missing.Value;
    object visible=true;
    object saveChanges = true;
    object NOTsaveChanges = false;
    object docreadonly=true;
    object originalFormat = System.Reflection.Missing.Value;
    object routeDocument =System.Reflection.Missing.Value;
    Word.ApplicationClass app=new Word.ApplicationClass();
    object FileNa=page.Server.MapPath("../Template_temp/"+FileName);
    Word.Document Doc=app.Documents.Open(ref FileNa,ref optional,ref docreadonly,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional,ref optional, ref visible);

    try
    {
    if(Doc.Books.Exists(""))
    {
    object b1="SJ";
    Word.Book bk1=Doc.Books.Item(ref b1);                                                                             bk1.Range.Text="";
    }

    object strFi=page.Server.MapPath(@"../Template_temp/A.doc");
    Doc.SaveAs(ref strFi,ref optional, ref optional, ref optional,ref optional, ref optional, ref optional,ref optional, ref optional, ref optional, ref optional);
    Doc.Close(ref NOTsaveChanges, ref originalFormat, ref routeDocument);
        app.Quit(ref NOTsaveChanges, ref originalFormat, ref routeDocument);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(Doc);
    app=null;
    Doc=null;
    GC.Collect();
    GC.Collect();
    }
    catch(Exception err)
    {
    strM=err.Message+",导出失败!";
    return strM;
    }
    return "";
    }或
    添加table到word
    Word.Table tb=ph.Range.Tables.AddOld(ph.Range ,1,6);
    tb.Rows.Alignment=Word.WdRowAlignment.wdAlignRowCenter;
    tb.Columns.Item(3).Width=150;
    tb.Columns.Item(4).Width=100;
    tb.Range.Font.Size=15;
    tb.Range.Font.Bold=2;