您好!對於一塊被選中的單元格區域,作爲一個整體,其上邊框為其内部首行所有單元格的上邊框組成,下邊框為其内部末行所有單元格的下邊框組成,左邊框為其内部首列所有單元格的左邊框組成,右邊框為其内部末列所有右邊框組成。
因此,要針對單元格區域的上下左右邊框分別設置,如下動圖所示:
可以參考如下代碼:
- var ls_color_name = 'black';
- var selectedRanges = sheet.getSelections();
- selectedRanges.forEach(range => {
- // 設置單元格區域的左邊框
- sheet.getRange(range.row, range.col, range.rowCount, 1, GC.Spread.Sheets.SheetArea.viewport)
- .borderLeft(new GC.Spread.Sheets.LineBorder(ls_color_name, GC.Spread.Sheets.LineStyle.medium));
- // 設置單元格區域的有邊框
- sheet.getRange(range.row, range.col + range.colCount - 1, range.rowCount, 1, GC.Spread.Sheets.SheetArea.viewport)
- .borderRight(new GC.Spread.Sheets.LineBorder(ls_color_name, GC.Spread.Sheets.LineStyle.medium));
- // 設置單元格區域的上邊框
- sheet.getRange(range.row, range.col, 1, range.colCount, GC.Spread.Sheets.SheetArea.viewport)
- .borderTop(new GC.Spread.Sheets.LineBorder(ls_color_name, GC.Spread.Sheets.LineStyle.medium));
- // 設置單元格區域的下邊框
- sheet.getRange(range.row + range.rowCount - 1, range.col, 1, range.colCount, GC.Spread.Sheets.SheetArea.viewport)
- .borderBottom(new GC.Spread.Sheets.LineBorder(ls_color_name, GC.Spread.Sheets.LineStyle.medium));
- });
复制代码
此外,還可以一次性對單元格區域的四周設置邊框樣式,可以參考如下代碼:
- var ls_color_name = 'black';
- selectedRanges = sheet.getSelections();
- selectedRanges.forEach(range => {
- sheet.getRange(range.row, range.col, range.rowCount, range.colCount)
- .setBorder(new GC.Spread.Sheets.LineBorder(ls_color_name, GC.Spread.Sheets.LineStyle.medium),
- { left: true, right: true, top: true, bottom: true});
- });
复制代码
|