Search code examples
javaapache-poidocx

Creating tab spaces in word document using Apache POI


I am using Apche POI to create MS Word documents(.docx format). I am able to create custom spaces among lines of text. Is there any class that is used to create tab spaces in word documents?


Solution

  • Are you able to use a character run to insert a \t character? I haven't tested this but it should work as follows:

          XWPFDocument newDoc = new XWPFDocument(); //Doc to write new doc to
          XWPFParagraph para = newDoc.createParagraph(); //Paragraph
          XWPFRun run = para.createRun();  //Where the text will be written from
          run.setText("\t");
    

    EDIT

    The alternative is to 'simulate' the tab yourself, I have tested this bit and it does work:

    run.setText("     ");