xwpf

How to create multiLevel bullets and numbering from java using apache POI XWPFDocument?

孤街浪徒 提交于 2019-12-01 18:00:31
I've read many blogs and forums related to my requirement, but till now I was able to generate bullet or numbering for first level with all the help I got. Can anyone guide me how to create a multilevel numbering using apache poi. Wondering whether Apache POI XWPFDocument support such feature? Below is what my requirement First Level Second Level Second Level First Level Edit 1 : Here is my sample code which works for single level numbering public class TestNumbering { String fileName=""; InputStream in = null; CTAbstractNum abstractNum = null; public TestNumbering() { try { in =

How to create multiLevel bullets and numbering from java using apache POI XWPFDocument?

倖福魔咒の 提交于 2019-12-01 17:49:58
问题 I've read many blogs and forums related to my requirement, but till now I was able to generate bullet or numbering for first level with all the help I got. Can anyone guide me how to create a multilevel numbering using apache poi. Wondering whether Apache POI XWPFDocument support such feature? Below is what my requirement First Level Second Level Second Level First Level Edit 1 : Here is my sample code which works for single level numbering public class TestNumbering { String fileName="";

How can I add embedded equations to docx files by using Apache POI?

我怕爱的太早我们不能终老 提交于 2019-12-01 14:05:21
I want to create a docx file programatically via Apache POI. I want to add some mathematical equations in some lines. How can I do this in a way that when the user open the docx file it see that equations as docx equation form. I mean I don't want simply give a background colour to that run, I want when the user does double click on my equation MS-Word open it in equation forms. Thanks in advance This is not really complicated: import java.io.FileOutputStream; import org.apache.poi.xwpf.usermodel.*; import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath; import org.openxmlformats

Replace text templates inside .docx (Apache POI, Docx4j or other)

别等时光非礼了梦想. 提交于 2019-12-01 13:09:06
问题 I want to do replacements in MS Word ( .docx ) document using regular expression (java RegEx): Example: …, с одной стороны, и %SOME_TEXT% именуемое в дальнейшем «Заказчик», в лице %SOME_TEXT% действующего на основании %SOME_TEXT% с другой стороны, заключили настоящий Договор о нижеследующем: … I tried to get text templates (like %SOME_TEXT% ) use Apache POI - XWPF and replace text, but replacement is not guaranteed, because POI separates runs => I get something like this( System.out.println

How to remove tables and paragraphs containing data from docx in java using apache poi

白昼怎懂夜的黑 提交于 2019-12-01 11:19:24
I have a word template that has multiple similar tables and some paragraphs associated to those tables placed just before them. Depending on the amount of data, I populate some tables and others are not required, so are there paragraphs. I need to remove these tables and paragraphs. As you can see in the image, I need to remove Table 2 and its paragraph Table Parahgraph Please help me how to do it. I tried using document.removeBodyElement(pos) , but it does not help. int startIndex = 0; int endIndex = 0; startIndex = doc.getPosOfTable(doc.getTables().get(0)); startIndex++; endIndex = doc

How to remove tables and paragraphs containing data from docx in java using apache poi

纵饮孤独 提交于 2019-12-01 09:38:49
问题 I have a word template that has multiple similar tables and some paragraphs associated to those tables placed just before them. Depending on the amount of data, I populate some tables and others are not required, so are there paragraphs. I need to remove these tables and paragraphs. As you can see in the image, I need to remove Table 2 and its paragraph Table Parahgraph Please help me how to do it. I tried using document.removeBodyElement(pos) , but it does not help. int startIndex = 0; int

How do I change color of a particular word document using apache poi?

故事扮演 提交于 2019-11-29 14:53:34
Current output: Needed output: above are the snapshots of the .docx and below is the code sample code, I want to change the color of a after it is replaced by @ . r.setColor("DC143C") doesn't work: for (XWPFParagraph p : docx.getParagraphs()) { List<XWPFRun> runs = p.getRuns(); if (runs != null) { for (XWPFRun r : runs) { String origText = r.getText(0); if (origText != null && origText.contains("a")) { origText = origText.replace("a", "@"); r.setText(origText, 0); } } } } If the need is to change the color of just one character then this character must be in its own run. This is because only

How to set page orientation for Word document?

陌路散爱 提交于 2019-11-29 07:20:59
I use Apache POI XWPF to create and handle MS Word documents. But I didn't find in the documentation how to change the page orientation. Apparently this way should make it: XWPFDocument doc = new XWPFDocument(); CTDocument1 document = doc.getDocument(); CTBody body = document.getBody(); if (!body.isSetSectPr()) { body.addNewSectPr(); } CTSectPr section = body.getSectPr(); if(!section.isSetPgSz()) { section.addNewPgSz(); } CTPageSz pageSize = section.getPgSz(); pageSize.setOrient(STPageOrientation.LANDSCAPE); But this method doesn't work properly. I can set the page orientation to landscape,

How can I use predefined formats in DOCX with POI?

冷暖自知 提交于 2019-11-28 21:28:32
I'm creating a docx generator with POI and would like to use predefined formats. Word includes several formats like Title, Heading 1..10 etc. These formats are predefined in every DOCX you create with Word. I would like to use them in my docx generator. I tried the following but the format was not applied: paragraph = document.createParagraph(); lastParagraph.setStyle("Heading1"); I also tried "heading 1", "heading1" and "Heading1" as style, but none of them worked. The API documentation doesn't show any details. I analysed a docx file created with Word 2007 and found out "Heading1" would be

How can I set background colour of a run (a word in line or a paragraph) in a docx file by using Apache POI?

落爺英雄遲暮 提交于 2019-11-28 12:50:32
I want to create a docx file by using Apache POI. I want to set background colour of a run (i.e. a word or some parts of a paragraph). How can I do this? Is in possible via Apache POI or not. Thanks in advance Word provides two possibilities for this. There are really background colors possible within runs. But there are also so called highlighting settings. With XWPF both possibilities are only possible using the underlying objects CTShd and CTHighlight . But while CTShd is shipped with the default poi-ooxml-schemas-3.13-...jar , for the CTHighlight the fully ooxml-schemas-1.3.jar is needed