2017-06-11 67 views

回答

0

您可以訪問所需的Word文檔表格和apply formatting to Table,Row and Cell。請檢查以下代碼片段以格式化文檔的第一個表格。

我使用Aspose作爲開發人員傳播者。

com.aspose.words.Document doc = new com.aspose.words.Document("input.doc"); 
com.aspose.words.Table table = (com.aspose.words.Table) doc.getChild(NodeType.TABLE, 0, true); 

// Align the table to the center of the page. 
table.setAlignment(TableAlignment.CENTER); 

// Clear any existing borders from the table. 
table.clearBorders(); 

// Set a green border around the table but not inside. 
table.setBorder(BorderType.LEFT, LineStyle.SINGLE, 1.5, Color.GREEN, true); 
table.setBorder(BorderType.RIGHT, LineStyle.SINGLE, 1.5, Color.GREEN, true); 
table.setBorder(BorderType.TOP, LineStyle.SINGLE, 1.5, Color.GREEN, true); 
table.setBorder(BorderType.BOTTOM, LineStyle.SINGLE, 1.5, Color.GREEN, true); 

// Fill the cells with a light green solid color. 
table.setShading(TextureIndex.TEXTURE_SOLID, Color.GREEN, Color.GREEN); 

doc.save("Table.SetOutlineBorders_Out.doc"); 
+0

我測試了這種方法,對於我來說最好避免在java中添加樣式,最好使用word文檔。 – asdasdsdf