你知道將DOC格式序列化爲字節數組最簡單方法嗎?來看看Aspose.Words API如何處理

Aspose.Words for .Net點擊下載)是一種高級Word文檔處理API,用於執行各類文檔管理和操做任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。數據庫

Aspose.Words API提供了將Microsoft Word文檔從DOC或DOCX格式序列化爲字節數組的最簡單方法。將文檔存儲到數據庫中和/或從數據庫中檢索時,將Word文檔轉換爲字節數組頗有幫助。數組

.NET的Aspose.Words可用於轉換Document對象,以獲取表示任何.NET應用程序中Document的字節數組。如下代碼段演示了DOC文件到字節數組的轉換。spa

// 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文件轉換爲字節數組。orm

// 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,很高興爲您提供查詢和諮詢。對象

相關文章
相關標籤/搜索