We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to remove table's border using Java

Hi Support,

Please see my pasted code snippet, it shows setting the cell border style to single firstly, later set its style to none. We expect the none style will take effect finally, but the result is cell border style is single, not none. Why? Is it a defect?

Thanks.
Vincent

DocumentBuilder docBuilder = new DocumentBuilder();
docBuilder.clearRunAttrs();

//begin table
Table table = docBuilder.startTable();
docBuilder.getCellFormat().clearFormatting();
docBuilder.getRowFormat().clearFormatting();

Cell cell = docBuilder.insertCell();
docBuilder.getCellFormat().clearFormatting();
docBuilder.write( “GUID” );

docBuilder.getCellFormat().getBorders().setColor( Color.BLACK );
docBuilder.getCellFormat().getBorders().setLineWidth( 1 );
docBuilder.getCellFormat().getBorders().setLineStyle( LineStyle.SINGLE );


docBuilder.getCellFormat().getBorders().setColor( Color.RED );
docBuilder.getCellFormat().getBorders().setLineStyle( LineStyle.NONE );
docBuilder.getCellFormat().getBorders().setLineWidth( 5 );

docBuilder.endRow();

// End Table
docBuilder.endTable();
docBuilder.getDocument().save( “C:\test.doc” );
docBuilder.getDocument().save( “C:\test.pdf” );





Hi Vincent,

Thanks for your query. Please see commented line (italic bold) in the following code. After executing following code, you will get the border line style as None.

DocumentBuilder docBuilder = new DocumentBuilder();

docBuilder.clearRunAttrs();

//begin table

Table table = docBuilder.startTable();

docBuilder.getCellFormat().clearFormatting();

docBuilder.getRowFormat().clearFormatting();

Cell cell = docBuilder.insertCell();

docBuilder.getCellFormat().clearFormatting();

docBuilder.write("GUID");

docBuilder.getCellFormat().getBorders().setColor(Color.BLACK);

docBuilder.getCellFormat().getBorders().setLineWidth(1);

docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.SINGLE);

docBuilder.getCellFormat().getBorders().setColor(Color.RED);

docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.NONE);

***//docBuilder.getCellFormat().getBorders().setLineWidth(5);***

docBuilder.endRow();

// End Table

docBuilder.endTable();

docBuilder.getDocument().save(DirDoc + "test.doc");

docBuilder.getDocument().save(DirDoc + "test.pdf");

Why it worked after commenting out setting line width? But I must set a different line width, so how I can walk around it?

Thanks.

Hi Vincent,

I have managed to reproduce the same problem at my end. I will discuss this issue with our development team and will update you further soon.

Hi Vincent,

I have discussed this issue with our development team and like to share with you that this is not an issue. LineStyle.None means that border should be transparent with zero width. When you set width of border, its style is reset to LineStyle.Single, because None border cannot have width.

Please see following two line of your code.

//LineStyle.None set border width to zero

docBuilder.getCellFormat().getBorders().setLineStyle(LineStyle.NONE);

//By setting line width to 5, it reset the style to LineStyle.Single

docBuilder.getCellFormat().getBorders().setLineWidth(5);