Aspose.Words简单生成word文档
2018-06-22 07:42:32来源:未知 阅读 ()
Aspose.Words简单生成word文档
Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.Writeln("试卷一-Title"); builder.Writeln("试卷一-Des"); string subject = @"<p>111-1<img src='/UploadFiles/UEditor/image/20161206/6361662975800625528094831.jpg' title='QQ图片20161107105516.jpg' _src='/UploadFiles/UEditor/image/20161206/6361662975800625528094831.jpg' alt='QQ图片20161107105516.jpg' style='float: right;'/></p>"; builder.Writeln(TextNoHTML(subject)); string[] imgurls = GetHtmlImageUrlList(subject); string imgtargeturl = ""; foreach (string imgurl in imgurls) { imgtargeturl = Server.MapPath(imgurl); if (File.Exists(imgtargeturl)) { builder.InsertImage(imgtargeturl, 400, 300); } } //builder.InsertImage(@"C:\Users\Sale\Pictures\1366-768壁纸\1357640083366.jpg",400,300); doc.Save(@"D:\1.docx");
C#获取纯文本 去除html标签
/// <summary> /// 将html文本转化为 文本内容方法NoHTML /// </summary> /// <param name="Htmlstring">HTML文本值</param> /// <returns></returns> public string TextNoHTML(string Htmlstring) { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除HTML Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"([/r/n])[/s]+", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "/", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "/xa1", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "/xa2", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "/xa3", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "/xa9", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&#(/d+);", "", RegexOptions.IgnoreCase); //替换掉 < 和 > 标记 Htmlstring.Replace("<", ""); Htmlstring.Replace(">", ""); Htmlstring.Replace("/r/n", ""); //返回去掉html标记的字符串 return Htmlstring; }
C#获取img src
/// <summary> /// 获取Img的路径 /// </summary> /// <param name="htmlText">Html字符串文本</param> /// <returns>以数组形式返回图片路径</returns> public static string[] GetHtmlImageUrlList(string htmlText) { Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase); //新建一个matches的MatchCollection对象 保存 匹配对象个数(img标签) MatchCollection matches = regImg.Matches(htmlText); int i = 0; string[] sUrlList = new string[matches.Count]; //遍历所有的img标签对象 foreach (Match match in matches) { //获取所有Img的路径src,并保存到数组中 sUrlList[i++] = match.Groups["imgUrl"].Value; } return sUrlList; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- WPF实现简单的跑马灯效果 2020-03-23
- .NET随机数函数的生成方法 2020-03-18
- .NET下通过HttpListener实现简单的Http服务 2020-02-27
- ASP.NET编程简单实现生成静态页面的方法 2020-02-06
- ASP.NET MVC中SignalR的简单应用 2020-02-06
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash