[]
        
(Showing Draft Content)

修改表格自定义样式

GcExcel Java 允许用户修改具有自定义样式的表格。

默认情况下,工作簿具有内置表格样式的集合,使用户可以将格式应用于表格。这些默认表格样式表示不将任何格式应用于表格。但是,创建自定义表格样式时,它会自动添加到工作簿的表格样式集合中,并且可以在需要时重用。

在管理工作簿中的一个或多个表格样式时,用户可以使用自定义表格样式修改内置表格样式。每个表样式元素表示表中特定元素的格式。定义表格的自定义样式后,用户首先需要访问现有的表格样式元素,以便自定义表格边框、设置表格的自定义填充、设置行条纹或列条纹样式等。

要更改表格样式,可以使用setTableStyle方法。如果要删除应用的表样式,可以使用delete方法。

请参阅以下示例代码以修改具有自定义样式的表。

// Add one custom table style.
ITableStyle style = workbook.getTableStyles().add("test");

// Set WholeTable element style.
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setItalic(true);
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setThemeColor(ThemeColor.Accent6);
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getFont().setStrikethrough(true);
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getBorders().setLineStyle(BorderLineStyle.Dotted);
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getBorders().setThemeColor(ThemeColor.Accent2);
style.getTableStyleElements().get(TableStyleElementType.WholeTable).getInterior().setColor(Color.FromArgb(24, 232, 192));

// Set FirstColumnStripe element style.
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getFont().setBold(true);
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getFont().setColor(Color.FromArgb(255, 0, 0));
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getBorders().setLineStyle(BorderLineStyle.Thick);
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getBorders().setThemeColor(ThemeColor.Accent5);
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).getInterior().setColor(Color.FromArgb(255, 255, 0));
style.getTableStyleElements().get(TableStyleElementType.FirstColumnStripe).setStripeSize(2);

// Set SecondColumnStripe element style.
style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getFont().setColor(Color.FromArgb(255, 0, 255));
style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getBorders().setLineStyle(BorderLineStyle.DashDot);
style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getBorders().setColor(Color.FromArgb(42, 105, 162));
style.getTableStyleElements().get(TableStyleElementType.SecondColumnStripe).getInterior().setColor(Color.FromArgb(204, 204, 255));

ITable table = worksheet.getTables().get(0);

// Set custom table style to table.
table.setTableStyle(style);
table.setShowTableStyleColumnStripes(true);