Hi,
I want to set different border width for table border and cell border respectively through below methods:
// to set table border width, it seems like the setting does not work
docBuilder.getRowFormat().getBorders().setLineWidth(10);
/*docBuilder.getRowFormat().getBorders().getBottom().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getLeft().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getRight().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getTop().setLineWidth(10);*/
docBuilder.getCellFormat().getBorders().setLineWidth(2);
But it seems like the above code can not work well, only the cell width can be set correctly. No matter which value was set to table border width, the width keep 1 always. Are there any ways can be used to set different width for table border and its cell border?
Thanks.
Please reference below sample code:
DocumentBuilder docBuilder = new DocumentBuilder();
com.aspose.words.Style style = docBuilder.getDocument().getStyles().get("Normal");
if (style != null)
{
docBuilder.getParagraphFormat().setStyle(style);
}
docBuilder.clearRunAttrs();
// begin table
docBuilder.startTable();
docBuilder.getParagraphFormat().clearFormatting();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getRowFormat().clearFormatting();
// to set table border width, it seems like the setting does not work
docBuilder.getRowFormat().getBorders().setLineWidth(10);
/*docBuilder.getRowFormat().getBorders().getBottom().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getLeft().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getRight().setLineWidth(10);
docBuilder.getRowFormat().getBorders().getTop().setLineWidth(10);*/
// The first row
docBuilder.getRowFormat().setHeight(0);
docBuilder.getRowFormat().setAllowAutoFit(true);
// The first cell
docBuilder.insertCell();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getCellFormat().getBorders().setColor(Color.black);
docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
docBuilder.getCellFormat().getBorders().setLineWidth(2);
docBuilder.getParagraphFormat().clearFormatting();
docBuilder.write("111");
// The second cell
docBuilder.insertCell();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getCellFormat().getBorders().setColor(Color.black);
docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
docBuilder.getCellFormat().getBorders().setLineWidth(2);
docBuilder.getParagraphFormat().clearFormatting();
docBuilder.write("222");
// End the first row
docBuilder.endRow();
// The second row
docBuilder.getRowFormat().setHeight(0);
docBuilder.getRowFormat().setAllowAutoFit(true);
// The 3rd cell
docBuilder.insertCell();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getCellFormat().getBorders().setColor(Color.black);
docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
docBuilder.getCellFormat().getBorders().setLineWidth(2);
docBuilder.getParagraphFormat().clearFormatting();
docBuilder.write("333");
// The fourth cell
docBuilder.insertCell();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getCellFormat().getBorders().setColor(Color.black);
docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);
docBuilder.getParagraphFormat().clearFormatting();
docBuilder.write("444");
// End the second row
docBuilder.endRow();
// end table
docBuilder.endTable();
docBuilder.getDocument().save("c:\testtable.doc");