Reputation: 2125
I am developing an application where i am using POI library to generate .docx files.
By using XWPFTable
I am unable to apply table styles. can any one worked on this part? There are no examples and not good documentation out there.
Here is my snippet.
int nRows = 14;
int nCols = 6;
XWPFTable t1 = doc.createTable(nRows, nCols);
t1.setStyleID("Table Grid");
Thanks in advance
Upvotes: 0
Views: 3620
Reputation: 1
I had trouble identifying the styleId to use. If you make a template and add the table with the style in, export it as a Word XML file then you can look up styleId. So "Light List" for me was actually "LightList" (w:style w:type="table" w:styleId="LightList").
Upvotes: 0
Reputation: 344
I have stumbled on this issue. I have created an empty docx file with all my juicy style available (Heading 1, 2, etc...). I create a XWPFDocument
try {
InputStream resourceAsStream = new FileInputStream("protocol_empty.docx");
document = new XWPFDocument(resourceAsStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
then add my paragraph my setting the style ....setStyle("Heading 1");
It works.
Upvotes: 1
Reputation: 2125
Got the answer. I added a template with few styles in it. It worked.
Upvotes: 0