你可以将内建的样式应用到表格上,或者给某一个区域设置样式。
关于内建的样式,你可以参照 TableThemes 类来获取所有内建样式的列表和可以被设置到特定区域的样式。
一些样式属性在界面上是不可见的,或者没有默认值,比如如果表格中没有设置 showFooter 为 true, lastFooterCellStyle 就不会起作用。
下表描述了 Table 中的属性与样式之间的关系
当该属性为True时 | 该属性才会起作用 |
firstColumnStripSize, firstColumnStripStyle, secondColumnStripSize, secondColumnStripStyle | |
firstRowStripSize, firstRowStripStyle, secondRowStripSize, secondRowStripStyle | |
示例代码
以下代码创建了一个表格,并且使用了内建的样式。
JavaScript
activeSheet.tables.add("Table1", 0, 0, 3, 3, GC.Spread.Sheets.Tables.TableThemes.dark1); activeSheet.getCell(0,0).text("Name"); activeSheet.getCell(0,1).text("Value"); activeSheet.getCell(0,2).text("T/F"); activeSheet.getCell(1,0).text("AW"); activeSheet.getCell(1,1).text("5"); activeSheet.getCell(1,2).text("T");
示例代码
以下代码给表格的表尾设置了样式。
HTML
window.onload = function(){ var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3}); var activeSheet = spread.getActiveSheet();//添加数据 for (var col = 1; col < 6; col+) { for (var row = 2; row < 11; row+) { activeSheet.setValue(row, col, row + col); } } var tableStyle = new GC.Spread.Sheets.Tables.TableTheme(); var thinBorder = new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.dotted); tableStyle.wholeTableStyle(new GC.Spread.Sheets.Tables.TableStyle("aliceblue", "green", "bold 10pt arial", thinBorder, thinBorder, thinBorder, thinBorder, thinBorder, thinBorder, GC.Spread.Sheets.TextDecorationType.none)); var tStyleInfo = new GC.Spread.Sheets.Tables.TableStyle(); tStyleInfo.backColor = "green"; tStyleInfo.foreColor = "red"; tStyleInfo.borderBottom = new GC.Spread.Sheets.LineBorder("green", GC.Spread.Sheets.LineStyle.thin); tStyleInfo.borderLeft = new GC.Spread.Sheets.LineBorder("yellow", GC.Spread.Sheets.LineStyle.medium); tStyleInfo.borderTop = new GC.Spread.Sheets.LineBorder("green", GC.Spread.Sheets.LineStyle.thin); tStyleInfo.borderRight = new GC.Spread.Sheets.LineBorder("green", GC.Spread.Sheets.LineStyle.thin); tStyleInfo.font = "bold 11pt arial";tableStyle.footerRowStyle(tStyleInfo); var sTable = activeSheet.tables.add("Custom", 1, 1, 10, 5, tableStyle);sTable.showFooter(true);//设置表尾数据 Table.setColumnValue(0, "Total");//设置表尾的公式 Table.setColumnFormula(4, "SUM(F3:F11)"); }...<div id="ss" style="height: 500px; width: 800px"></div>
更多信息