Leading/trailing whitespace is preserved only if leading or trailing character is a whitespace but fails to preserve if that chararter is a tab (\t). Tab characters get stripped in the generated Word document. Here's a patch to XWPFRun.java in org.apache.poi.xwpf.usermodel package from poi-ooxml-4.1.1.jar. *** XWPFRun.java --- XWPFRun.java.orig *************** *** 146,152 **** */ static void preserveSpaces(XmlString xs) { String text = xs.getStringValue(); ! if (text != null && text.length() >= 1 && (Character.isWhitespace(text.charAt(0)) ! || Character.isWhitespace(text.charAt(text.length()-1))) { XmlCursor c = xs.newCursor(); c.toNextToken(); --- 146,152 ---- */ static void preserveSpaces(XmlString xs) { String text = xs.getStringValue(); ! if (text != null && (text.startsWith(" ") || text.endsWith(" "))) { XmlCursor c = xs.newCursor(); c.toNextToken();
Do you have an input file that demonstrates the problem? Or a unit test? It would be useful for us to have a regression test so that we don't accidentally undo this change later.
Created attachment 36981 [details] Junit test that fails
Created attachment 36982 [details] build.gradle file to run testcase
applied with https://svn.apache.org/repos/asf/poi/trunk@1873188