How to convert an Interop.Word.Document object to a stream or byte array?
By : SkîLiks Nazîh
Date : March 29 2020, 07:55 AM
|
How to create Microsoft.Office.Interop.Word.Document object from byte array, without saving it to disk?
By : kenyanburnham
Date : March 29 2020, 07:55 AM
it helps some times There is no straight-forward way of doing this as far as I know. The Word interop libs are not able to read from a byte stream. Unless you are working with huge (or a huge amount of) files, I would recommend simply using a tmp file: code :
Application app = new Application();
byte[] wordContent = GetBytesInSomeWay();
var tmpFile = Path.GetTempFileName();
var tmpFileStream = File.OpenWrite(tmpFile);
tmpFileStream.Write(wordContent, 0, wordContent.Length);
tmpFileStream.Close();
app.Documents.Open(tmpFile);
|
Replacing strings stored in a byte array that represent Word/Excel document
By : Jeremy
Date : March 29 2020, 07:55 AM
With these it helps I would recommend you using the Open XML SDK. With the library, you can do the following to replace text from a Word document, considering that documentByteArray is your document byte content taken from database: code :
using (MemoryStream mem = new MemoryStream())
{
mem.Write(documentByteArray, 0, (int)documentByteArray.Length);
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true))
{
string docText = null;
using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream()))
{
docText = sr.ReadToEnd();
}
Regex regexText = new Regex("Hello world!");
docText = regexText.Replace(docText, "Hi Everyone!");
using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create)))
{
sw.Write(docText);
}
}
}
|
Convert Word document to pdf byte array in memory
By : joyandroid
Date : March 29 2020, 07:55 AM
Any of those help I need to open a Microsoft Word document, replace some of the text then convert to a pdf byte array. I have created code to do this but it involves saving the pdf to disk and reading the bytes back into memory. I would like to avoid writing anything to the disk as I do not need to save the file. , There are two problems:
|
How to Extract Word document text from byte array?
By : user3234624
Date : March 29 2020, 07:55 AM
|