Hi again,
These suggestions worked well for small tables. Now I’m facing a larger table, and the setHorizontalMerge method does not work.

This is my code:
if (indicatorInstance.getAttributeList().size() == 3)
{
Attribute attribute1 = attribute1;
Attribute attribute2 = attribute2;
Table table = builder.startTable();
int colSpan = (attribute1.getValueList().size()) * (attribute2.getValueList().size()) + 1;
Cell interventionAreaRow = builder.insertCell();
interventionAreaRow.getCellFormat().getShading().setBackgroundPatternColor(new Color(45, 163, 151));
interventionAreaRow.getFirstParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
Font indicatorFont = builder.getFont();
indicatorFont.setSize(10);
indicatorFont.setColor(new Color(255, 255, 255));
indicatorFont.setBold(true);
builder.getCellFormat().setTopPadding(10);
builder.getCellFormat().setBottomPadding(10);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write(indicatorInstance.getIndicator().getCategory().getName());
for (int i = 0; i < colSpan - 1; i++)
{
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
builder.endRow();
Cell indicatorNameRow = builder.insertCell();
indicatorNameRow.getCellFormat().getShading().setBackgroundPatternColor(new Color(255, 255, 255));
indicatorNameRow.getFirstParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
indicatorFont.setSize(10);
indicatorFont.setColor(new Color(91, 87, 164));
indicatorFont.setBold(true);
builder.getCellFormat().setTopPadding(20);
builder.getCellFormat().setBottomPadding(20);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write(indicatorInstance.getIndicator().getName());
for (int i = 0; i < colSpan - 1; i++)
{
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
builder.endRow();
builder.insertCell();
for (Value value : attribute1.getValueList())
{
builder.insertCell();
builder.write(value.getValue());
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
for (int j = 0; j < attribute2.getValueList().size() - 1; j++)
{
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
}
builder.endRow();
builder.insertCell();
for (int i = 0; i < attribute1.getValueList().size(); i++)
{
for (Value value2 : attribute2.getValueList())
{
builder.insertCell();
builder.write(value2.getValue());
}
}
builder.endRow();
Attribute columnAttribute = indicatorInstance.getAttributeList().get(2);
for (Value value : columnAttribute.getValueList())
{
builder.insertCell();
builder.write(value.getValue());
for (ValueInstance valueInstance : indicatorInstance.getValueInstanceList())
{
for (Value value1 : attribute1.getValueList())
{
for (Value value2 : attribute2.getValueList())
{
if (valueInstance.getValues().contains(value1) && valueInstance.getValues().contains(value2) && valueInstance.getValues().contains(value))
{
builder.insertCell();
builder.write(valueInstance.getValue());
}
}
}
}
builder.endRow();
}
if (indicatorInstance.getNote() != null && !indicatorInstance.getNote().isEmpty())
{
Cell noteCell = builder.insertCell();
noteCell.getCellFormat().getShading().setBackgroundPatternColor(new Color(255, 255, 255));
noteCell.getFirstParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
indicatorFont.setSize(10);
indicatorFont.setColor(new Color(30, 32, 25));
indicatorFont.setBold(false);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("NOTE: " + indicatorInstance.getNote());
for (int i = 0; i < colSpan - 1; i++)
{
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
builder.endRow();
}
if (indicatorInstance.getAction() != null && !indicatorInstance.getAction().isEmpty())
{
Cell noteCell = builder.insertCell();
noteCell.getCellFormat().getShading().setBackgroundPatternColor(new Color(255, 255, 255));
noteCell.getFirstParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
indicatorFont.setSize(10);
indicatorFont.setColor(new Color(30, 32, 25));
indicatorFont.setBold(false);
builder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
builder.write("ACTION: " + indicatorInstance.getAction());
for (int i = 0; i < colSpan - 1; i++)
{
builder.insertCell();
builder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
}
builder.endRow();
}
table.setAlignment(HorizontalAlignment.CENTER);
builder.endTable();
}
The image below is the output of my code. How could I change it to make it work properly and obtain the table in the first image?

My next step would be to create a greater table, with 4 attributes (2 on columns and 2 on rows). Is it possible to set a vertical merge?
Thanks,
Regards