Document Builder Tables and styles

Hi
I use builder to create a docm where a template docm is used as the clone document.
This clone has various table styles which I try to use to apply to a new table.

I am setting header row status on row 1 & 2 which works as expected until I then apply a style to the table. This seems to undo the header status of all rows?

I have tried setting the style after the start table but this crashes as the table is empty and also at table end but I cannot apply a table style and have rows marked as headers.

Please help?

Code sample follows:
@Test
public void smokey() throws Throwable {

	final InputStream is = this.getClass().getResourceAsStream("/SpectraVanillaTemplate_SignedCC.docm");
	final Document doc = new Document(is);
	
	StyleCollection knownStyles = doc.getStyles();
	Style tStyle = knownStyles.get("FIN-PERF-RETURNS"); 
			

		// DocumentBuilder provides members to easily add content to a document.
		DocumentBuilder builder = new DocumentBuilder(doc);
		Table table = builder.startTable();
		
		builder.getRowFormat().setHeadingFormat(true);
		builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
		builder.getCellFormat().setWidth(100);
		builder.insertCell();
		builder.writeln("Heading row 1");
		builder.endRow();
		builder.insertCell();
		builder.writeln("Heading row 2");
		builder.endRow();

		builder.getCellFormat().setWidth(50);
		builder.getParagraphFormat().clearFormatting();

		// Insert some content so the table is long enough to continue onto the next page.
		for (int i = 0; i < 50; i++)
		{
		    builder.insertCell();
		    builder.getRowFormat().setHeadingFormat(false);
		    builder.write("Column 1 Text");
		    builder.insertCell();
		    builder.write("Column 2 Text");
		    builder.endRow();
		}

		table.setStyle(tStyle);
		builder.endTable();

		
		doc.save("c:/temp/fred.docm", SaveFormat.DOCM);
	}
Hi Jan,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input template document.
  • Please attach the expected output Word file, you can create it using MS Word.

As soon as you get these pieces of information ready, we will investigate the issue and provide you more information. Thanks for your cooperation.

Best Regards,

I revised my code sample to load the template from c:\temp

attached zip contains the template docm and a good and bad version of the output

public void smokey() throws Throwable {
final InputStream is = new FileInputStream(“c:/temp/SpectraVanillaTemplate_SignedCC - Copy.docm”);
final Document doc = new Document(is);
StyleCollection knownStyles = doc.getStyles();
Style tStyle = knownStyles.get(“FIN-PERF-RETURNS”);
// DocumentBuilder provides members to easily add content to a document.
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.startTable();
builder.getRowFormat().setHeadingFormat(true);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.getCellFormat().setWidth(100);
builder.insertCell();
builder.writeln(“Heading row 1”);
builder.endRow();
builder.insertCell();
builder.writeln(“Heading row 2”);
builder.endRow();
builder.getCellFormat().setWidth(50);
builder.getParagraphFormat().clearFormatting();
// Insert some content so the table is long enough to continue onto the next page.
for (int i = 0; i < 50; i++) {
builder.insertCell();
builder.getRowFormat().setHeadingFormat(false);
builder.write(“Column 1 Text”);
builder.insertCell();
builder.write(“Column 2 Text”);
builder.endRow();
}
// Setting the style stops the head repeat rows from working
table.setStyle(tStyle);
//
builder.endTable();
doc.save(“c:/temp/fred.docm”, SaveFormat.DOCM);
}

Hi Jan,


Thanks for sharing the source documents. We have tested the scenario and noticed the reported issue. We have logged a ticket WORDSJAVA-1594 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

@JanUrbanski

Thanks for your patience. We have investigated the issue and found it is not a bug but expected behavior. Please try to do the same using MS Word and you will get exactly the same result. Comment the line of code where the style is applied and then open the document in MS Word and apply any style you want, the header row formatting will be changed.