You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by david810376 February 25, 2022
Hi,
I am trying to replace some text in the word document, but in the document there are some image in the header, so when I read the document and replace the text, then I open the new word document that finish replace, the word show out the document is borken so it can't open it. Thus I did not have any idea how can I replace the document that include images, I did not do anything to the image, I just replace the text. I'm sure about the replace text is fine because in the beginning just want to replace the text it work great, but when the document have image in the header it doesn't work anymore. Thus is there have any example about edit the word document include image?
Here are the part of code
`
string strSourcePath = System.Environment.CurrentDirectory + "\\Sample.docx";
string filepath = selectfolder +"\\" +TXT_FileName.Text +".docx";
try
{
System.IO.File.Copy(strSourcePath, filepath, true);
FileStream fsFile = new FileStream(filepath, FileMode.Open, FileAccess.Read);
XWPFDocument document = new XWPFDocument(fsFile);
document.CreateParagraph();
//into the header
foreach (XWPFHeader header in document.HeaderList)
{
//create header
document.CreateParagraph().CreateRun();
}
//body part
foreach(var para in document.Paragraphs)
{
string strOldText = para.ParagraphText;
if (strOldText == "")
continue;
string strTempText = para.ParagraphText;
if (strTempText.Contains("Test"))
strTempText = strTempText.Replace("Test", "Hello");
para.ReplaceText(strOldText, strTempText);
}
FileStream out1 = new FileStream(filepath, FileMode.Create);
document.Write(out1);
out1.Close();
`
The text was updated successfully, but these errors were encountered:
Discussed in #767
Originally posted by david810376 February 25, 2022
Hi,
I am trying to replace some text in the word document, but in the document there are some image in the header, so when I read the document and replace the text, then I open the new word document that finish replace, the word show out the document is borken so it can't open it. Thus I did not have any idea how can I replace the document that include images, I did not do anything to the image, I just replace the text. I'm sure about the replace text is fine because in the beginning just want to replace the text it work great, but when the document have image in the header it doesn't work anymore. Thus is there have any example about edit the word document include image?
Here are the part of code
`
`
The text was updated successfully, but these errors were encountered: