你知道将DOC/DOCX格式序列化为字节数组最简单方法吗?来看看Aspose.Words API如何处理

Aspose.Words API提供了将Microsoft Word文档从DOC或DOCX格式序列化为字节数组的最简单方法。将文档存储到数据库中和/或从数据库中检索时,将Word文档转换为字节数组很有帮助。

Aspose.Words for .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。

下载Aspose.Words for .NET v19.12

Aspose.Words API提供了将Microsoft Word文档从DOC或DOCX格式序列化为字节数组的最简单方法。将文档存储到数据库中和/或从数据库中检索时,将Word文档转换为字节数组很有帮助。

.NET的Aspose.Words可用于转换Document对象,以获取表示任何.NET应用程序中Document的字节数组。以下代码段演示了DOC文件到字节数组的转换。

// Load the document from disk.Document doc = new Document("Sample.doc");// Create a new memory stream.MemoryStream outStream = new MemoryStream();// Save the document to stream.doc.Save(outStream, SaveFormat.Docx);// Convert the document to byte form.byte[] docBytes = outStream.ToArray();// The bytes are now ready to be stored/transmitted.// Now reverse the steps to load the bytes back into a document object.MemoryStream inStream = new MemoryStream(docBytes);// Load the stream into a new document object.Document loadDoc = new Document(inStream);// Save the document.loadDoc.Save("loadDoc.docx",SaveFormat.Docx);

还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。让人兴奋的是Aspose.Total限时直降10000元!java版另送IDE开发工具一套!联系客服立马1分钟了解全部咨询!

以下代码段演示了如何使用Aspose.Words for Java API 将DOC文件转换为字节数组。

// Load the document.Document doc = new Document("Sample.doc");// Create a new memory stream.ByteArrayOutputStream outStream = new ByteArrayOutputStream();// Save the document to stream.doc.save(outStream, SaveFormat.DOCX);// Convert the document to byte form.byte[] docBytes = outStream.toByteArray();// The bytes are now ready to be stored/transmitted.// Now reverse the steps to load the bytes back into a document object.ByteArrayInputStream inStream = new ByteArrayInputStream(docBytes);// Load the stream into a new document object.Document loadDoc = new Document(inStream);// Save the document.loadDoc.Save("loadDoc.docx",SaveFormat.Docx);

如果您有任何疑问或需求,请随时加入Aspose技术交流群,我们很高兴为您提供查询和咨询

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年11月7日
下一篇 2019年11月7日

相关推荐

发表回复

登录后才能评论