Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot handle text box in docx #1478

Open
1 of 5 tasks
liiws opened this issue Jan 19, 2025 · 0 comments
Open
1 of 5 tasks

Cannot handle text box in docx #1478

liiws opened this issue Jan 19, 2025 · 0 comments

Comments

@liiws
Copy link

liiws commented Jan 19, 2025

NPOI Version

2.7.2

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Word File

textbox.docx

Reproduce Steps

  1. Use attached document? or create new document then write text "Text1" in the document and create textbox with text "TextBox2".
  2. Replace text like in the following code example:
XWPFDocument document;
using (var fs = new FileStream(@"D:\DOCUMENTS\PROGRMG\dotnet\Stomatient\Stomatient\DocumentTemplates\0\textbox.docx", FileMode.Open))
{
	using (var ms = new MemoryStream())
	{
		fs.CopyTo(ms);
		ms.Position = 0;
		document = new XWPFDocument(ms);
	}
}

document.FindAndReplaceText("Text1", "Replace1");
document.FindAndReplaceText("TextBox2", "Replace2");

var tempFile = Path.GetTempFileName() + ".docx";
using (var fs = new FileStream(tempFile, FileMode.CreateNew))
{
	document.Write(fs);
	fs.Close();
}

document.Close();
document.Dispose();

var psi = new ProcessStartInfo(tempFile);
psi.Verb = "ViewProtected";
Process.Start(psi);

Issue Description

"Text1" is replaced, but "TextBox2" inside textbox is not replaced.
And there is no any way to access text in the text box.
For example with DocX library textbox xan be accessed using Paragraphs, but here it seems it's not possible.
There is an answer on the SO but for Java how to access - https://stackoverflow.com/questions/46802369/replace-text-in-text-box-of-docx-by-using-apache-poi/46894499#46894499 - but it's very ugly and there is no Cursor in .NET's GetCTP() and no SelectPath() I could find.

@liiws liiws added the bug label Jan 19, 2025
@tonyqus tonyqus added the docx label Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants