根据数据表中的html代码生成word文件

kevin87923 2012-12-10 10:29:36
Microsoft.Office.Interop.Word

能生成word文件,, 如果有图片的话。下载到本地就看不到图片,,
如何将图片生成到word中呢。。
...全文
103 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
蝶恋花雨 2012-12-10
  • 打赏
  • 举报
回复
http://www.cnblogs.com/syfblog/archive/2012/12/06/2804639.html c#导出包含图片的word文档
蝶恋花雨 2012-12-10
  • 打赏
  • 举报
回复
图片的话注意路径就行 下载这个你看看吧 http://download.csdn.net/detail/zane199118/2612180 C#动态生成含有图片、图标、表格的Word并保存
kevin87923 2012-12-10
  • 打赏
  • 举报
回复
顶下,别沉了。
kevin87923 2012-12-10
  • 打赏
  • 举报
回复
求助,各位能人。
kevin87923 2012-12-10
  • 打赏
  • 举报
回复

 object path;                           //文件路径变量       
        Application wordApp;               //Word应用程序变量
        Document wordDoc;              //Word文档变量
        string strWordFile = HttpContext.Current.Server.MapPath(WordFilePath);
        if (!Directory.Exists(strWordFile))
            Directory.CreateDirectory(strWordFile);
        Thread.Sleep(1000);//延迟1秒
        path = strWordFile + strTitle + ".doc";           //路径
        wordApp = new ApplicationClass();  //初始化
        //如果已存在,则删除
        if (File.Exists((string)path))
        {
            File.Delete((string)path);
        }
        //由于使用的是COM库,因此有许多变量需要用Missing.Value代替
        Object Nothing = Missing.Value;
        wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);        
        //WdSaveFormat为Word文档的保存格式
        int intIndex = strContent.IndexOf("<div");//根据<div>判断是否为txt文本       
        string strImagePath = ""; //图片地址        
        string picUrl = "";//图片绝对路径
        foreach (Match match in Regex.Matches(strContent, @"(?<=src=['""])[^'""]*(?=['""])", RegexOptions.IgnoreCase))
        {
            strImagePath = HttpContext.Current.Server.MapPath(UploadFilePath);

            strImagePath = strImagePath + match.Value.Replace("/","\\"); //strAPath.Substring(strPath.Length+1, strAPath.Length - strPath.Length-1);
            strContent = strContent.Replace(match.Value, strImagePath);
        }
        picUrl = strImagePath;
        object format = intIndex > 0 ? WdSaveFormat.wdFormatDOSTextLineBreaks : WdSaveFormat.wdFormatDocument;
        //文件内容
        wordDoc.Paragraphs.Last.Range.Text = intIndex > 0 ? "<body>" + strContent + "</body>" : strContent;      
        //将wordDoc文档对象的内容保存为DOC文档     
        wordDoc.SaveAs(ref path, 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文档对象 
        wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
        //关闭wordApp组件对象 
        wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
可我数据表中有多个图片如何生成到word呢。 难道一个个插入??

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧