.Net实现Word文档及导出

参考网址:

http://www.jb51.net/article/25062.htm(实用性)

http://wenku.baidu.com/link?url=44O7Dua49DrZ-PF2QU70Aobp8D8cOTBWXtYxfxAFwzbjJswHulXZfiOlhFmXsnJH1MHpy83EA8Gt-yaNVAADfuhhZHzGRqourd30ig5V3ka

http://www.csharpwin.com/dotnetspace/12470r7724.shtml

http://bbs.youkuaiyun.com/topics/220001707(各文本加入)

WORD文档保存后,获取并现在已保存文档。

   string path = AppDomain.CurrentDomain.BaseDirectory + ("UpFiles\\") + fileName;
   return File(new FileStream(path, FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite), "image/jpeg jpeg jpg jpe", fileName);

此处加入:System.IO.FileAccess.Read, FileShare.ReadWrite  文档流只读,文档共享读写操作。可避免如下错误提示

...文本正由另一进程使用,因此该进程无法访问该文件

=================

        /// <summary>
        /// 新建Word文档
        /// </summary>
        /// <param name="path">文件路径</param>
        /// <param name="strContent">文件内容</param>
        public void CreateWordFile(string path, string strContent)
        {

            MSWord.Application wordApp;
            //C#创建Word文档之word应用程序  

            MSWord.Document wordDoc;//word文档  


            wordApp = new MSWord.Application();

            if (File.Exists(path))
            {

                File.Delete(path);

            }

            object filePath = path;
            Object nothing = Missing.Value;

            wordDoc = wordApp.Documents.Add(
            ref nothing, ref nothing, ref nothing, ref nothing);

            wordApp.Visible = false;

            wordDoc.Paragraphs.Last.Range.Text = strContent;

            object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;

            wordDoc.SaveAs(ref filePath, ref format,
            ref nothing, ref nothing, ref nothing,
            ref nothing, ref nothing,

             ref nothing, ref nothing, ref nothing,
            ref nothing, ref nothing, ref nothing,

            ref nothing, ref nothing, ref nothing);

            wordDoc.Close(ref nothing, ref nothing, ref nothing);

            wordApp.Quit(ref nothing, ref nothing, ref nothing);
        }

 


      

 

 

转载于:https://www.cnblogs.com/senyier/p/3498542.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值