Apache POI : POI ignoring extra spaces in the string












0















I have a code to read paragraphs from .docx file :



package com.detector;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

public class Test2 {
public static void readDocx() {
try {
File file = new File("D:/sample.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getParagraphText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
readDocx();

}

}


The code is working fine. But it is removing the extra spaces or spaces outside from text.



For ex : I have a text with right alignment like this below :



                                                                     Exhibit 10.4


But the code after scanning the paragraph gives me the text like this :



Exhibit 10.4 


I want that exact text with spaces from that .docx using that Apache POI. Is there any way to get that ?? :)










share|improve this question

























  • Its worked for me. Please check your word file.

    – flopcoder
    Nov 16 '18 at 7:14











  • Is it scanning the spaces there for the alignment ??

    – Anish B.
    Nov 16 '18 at 7:22






  • 3





    XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

    – Trung NT Nguyen
    Nov 16 '18 at 7:25













  • I want the whole thing with spaces (it should not ignore the spaces outside) as well.

    – Anish B.
    Nov 16 '18 at 7:27








  • 1





    But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

    – Axel Richter
    Nov 16 '18 at 14:26
















0















I have a code to read paragraphs from .docx file :



package com.detector;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

public class Test2 {
public static void readDocx() {
try {
File file = new File("D:/sample.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getParagraphText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
readDocx();

}

}


The code is working fine. But it is removing the extra spaces or spaces outside from text.



For ex : I have a text with right alignment like this below :



                                                                     Exhibit 10.4


But the code after scanning the paragraph gives me the text like this :



Exhibit 10.4 


I want that exact text with spaces from that .docx using that Apache POI. Is there any way to get that ?? :)










share|improve this question

























  • Its worked for me. Please check your word file.

    – flopcoder
    Nov 16 '18 at 7:14











  • Is it scanning the spaces there for the alignment ??

    – Anish B.
    Nov 16 '18 at 7:22






  • 3





    XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

    – Trung NT Nguyen
    Nov 16 '18 at 7:25













  • I want the whole thing with spaces (it should not ignore the spaces outside) as well.

    – Anish B.
    Nov 16 '18 at 7:27








  • 1





    But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

    – Axel Richter
    Nov 16 '18 at 14:26














0












0








0








I have a code to read paragraphs from .docx file :



package com.detector;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

public class Test2 {
public static void readDocx() {
try {
File file = new File("D:/sample.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getParagraphText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
readDocx();

}

}


The code is working fine. But it is removing the extra spaces or spaces outside from text.



For ex : I have a text with right alignment like this below :



                                                                     Exhibit 10.4


But the code after scanning the paragraph gives me the text like this :



Exhibit 10.4 


I want that exact text with spaces from that .docx using that Apache POI. Is there any way to get that ?? :)










share|improve this question
















I have a code to read paragraphs from .docx file :



package com.detector;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

public class Test2 {
public static void readDocx() {
try {
File file = new File("D:/sample.docx");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument document = new XWPFDocument(OPCPackage.open(fis));
List<XWPFParagraph> paragraphs = document.getParagraphs();
for (XWPFParagraph para : paragraphs) {
System.out.println(para.getParagraphText());
}
fis.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String args) {
readDocx();

}

}


The code is working fine. But it is removing the extra spaces or spaces outside from text.



For ex : I have a text with right alignment like this below :



                                                                     Exhibit 10.4


But the code after scanning the paragraph gives me the text like this :



Exhibit 10.4 


I want that exact text with spaces from that .docx using that Apache POI. Is there any way to get that ?? :)







java apache apache-poi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 7:28







Anish B.

















asked Nov 16 '18 at 7:00









Anish B.Anish B.

419113




419113













  • Its worked for me. Please check your word file.

    – flopcoder
    Nov 16 '18 at 7:14











  • Is it scanning the spaces there for the alignment ??

    – Anish B.
    Nov 16 '18 at 7:22






  • 3





    XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

    – Trung NT Nguyen
    Nov 16 '18 at 7:25













  • I want the whole thing with spaces (it should not ignore the spaces outside) as well.

    – Anish B.
    Nov 16 '18 at 7:27








  • 1





    But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

    – Axel Richter
    Nov 16 '18 at 14:26



















  • Its worked for me. Please check your word file.

    – flopcoder
    Nov 16 '18 at 7:14











  • Is it scanning the spaces there for the alignment ??

    – Anish B.
    Nov 16 '18 at 7:22






  • 3





    XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

    – Trung NT Nguyen
    Nov 16 '18 at 7:25













  • I want the whole thing with spaces (it should not ignore the spaces outside) as well.

    – Anish B.
    Nov 16 '18 at 7:27








  • 1





    But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

    – Axel Richter
    Nov 16 '18 at 14:26

















Its worked for me. Please check your word file.

– flopcoder
Nov 16 '18 at 7:14





Its worked for me. Please check your word file.

– flopcoder
Nov 16 '18 at 7:14













Is it scanning the spaces there for the alignment ??

– Anish B.
Nov 16 '18 at 7:22





Is it scanning the spaces there for the alignment ??

– Anish B.
Nov 16 '18 at 7:22




3




3





XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

– Trung NT Nguyen
Nov 16 '18 at 7:25







XWPFParagraph has ParagraphAlignment property. In this case, it's only a text "Exhibit 10.4" with ParagraphAlignment.RIGHT, not with some spaces

– Trung NT Nguyen
Nov 16 '18 at 7:25















I want the whole thing with spaces (it should not ignore the spaces outside) as well.

– Anish B.
Nov 16 '18 at 7:27







I want the whole thing with spaces (it should not ignore the spaces outside) as well.

– Anish B.
Nov 16 '18 at 7:27






1




1





But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

– Axel Richter
Nov 16 '18 at 14:26





But as @Trung NT Nguyen told you: There are no spaces at all. Please read XWPFParagraph.getAlignment for how to get the paragraph alignment settings.

– Axel Richter
Nov 16 '18 at 14:26












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332912%2fapache-poi-poi-ignoring-extra-spaces-in-the-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53332912%2fapache-poi-poi-ignoring-extra-spaces-in-the-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma