Essential DocIO如何使用流的形式加载Word文件

作者:控件中国网   出处:控件中国网   2015-12-16 14:41:09   阅读:6

Essential DocIO 是一款.NET库,可以帮助开发人员读取、写入和修改Microsoft Word文件,该控件功能和Microsoft Office 类似,使用该产品时系统上并不需要安装Microsoft Word,利用该产品开发人员可以在Windows forms, WPF, ASP.NET Webforms, ASP.NET MVC, Silverlight, WinRT, Windows Phone 上创建Word格式化报表,支持邮件合并功能、表单填充、查找替换、字段、表格、文本格式、列表、样式、插入图片、页眉页脚设置,书签、图表等多种常用的功能。
 
这篇文章主要介绍怎么利用Essential DocIO提供的API以流的形式加载Word文件,具体可以查看下面的代码,由于Essential DocIO并不单独销售,Syncfusion公司各种平台下的套包产品几乎都包含了该产品,开发人员可以下载测试。
 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.swiftview.com/tech/letterlegal5.doc");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
//Converts it to byte array
byte[] buffer = ReadFully(stream, 32768);            
//Stores bytes into the memory stream.
MemoryStream ms = new MemoryStream();
ms.Write(buffer, 0, buffer.Length);
ms.Seek(0, SeekOrigin.Begin);
stream.Close();
//Creates a new document.
WordDocument document = new WordDocument();
//Opens the template document from the MemoryStream.
document.Open(ms, FormatType.Doc);
 
//Saves and closes the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
 
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat