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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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),很高兴为您提供查询和咨询。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值