Aspose.Words for .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。
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);
以下代码段演示了如何使用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技术交流群(642018183),很高兴为您提供查询和咨询。

Aspose.Words for .Net是高级的Word文档处理API,支持生成、修改、转换文档等操作。文章介绍了如何利用API将DOC或DOCX格式的文档序列化为字节数组,这对于在数据库中存储和检索文档非常有用。提供了.NET和Java平台下的代码示例进行说明。
459

被折叠的 条评论
为什么被折叠?



