تبدیل Word (DOC، DOCX) به آرایه بایت C# جاوا

Aspose.Words API ساده ترین راه را برای تبدیل سند مایکروسافت ورد DOC یا DOCX به آرایه بایت در C# و جاوا ارائه می دهد.

تبدیل یک سند Word به یک آرایه بایت هنگام ذخیره اسناد در پایگاه داده و/یا بازیابی آنها از پایگاه داده مفید است.

Aspose.Words API قابلیت دستکاری فایل های Microsoft Word را بدون استفاده از Microsoft Word فراهم می کند. اگر Aspose.Words API را نصب نکرده‌اید، لطفاً دستورالعمل‌های داده‌شده در صفحه نصب برای دات‌نت و صفحه نصب برای استفاده با جاوا را دنبال کنید.

تبدیل یک سند Word به آرایه بایت با استفاده از سی شارپ

Aspose.Words for .NET می تواند برای تبدیل یک شی Document برای به دست آوردن یک آرایه بایتی که سند را در هر برنامه NET نشان می دهد استفاده شود. قطعه کد زیر تبدیل یک فایل 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);

تبدیل یک سند Word به آرایه بایت با استفاده از جاوا

قطعه کد زیر تبدیل یک فایل DOC به آرایه بایت را با استفاده از Aspose.Words for Java API نشان می دهد.

// 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);

همچنین ببینید