工作表中划分不同行列的横线和竖线被称为网格线,某个单元格或某个区域的网格线通常被称为边框。本文将介绍如何为单元格或区域设置边框样式,以及如何隐藏工作表的网格线。
设置边框样式
c#
//创建workbook对象,获取第一个工作表
workbook wb = new workbook();
worksheet sheet = wb.worksheets[0];
//选择区域(在区域b2:d4设置边框样式一)
cellrange range = sheet.range["b2:d4"];
//应用双线样式
range.borders.linestyle = linestyletype.double;
//隐藏斜线
range.borders[borderslinetype.diagonaldown].linestyle = linestyletype.none;
range.borders[borderslinetype.diagonalup].linestyle = linestyletype.none;
//设置颜色
range.borders.color = color.blue;
//选择区域(在区域d7:f9设置边框样式二)
range = sheet.range["d7:f9"];
//区域内部置应用细线
range.borderinside(linestyletype.thin);
//区域外部置应用中粗线
range.borderaround(linestyletype.medium);
//隐藏斜线
range.borders[borderslinetype.diagonaldown].linestyle = linestyletype.none;
range.borders[borderslinetype.diagonalup].linestyle = linestyletype.none;
//选择区域(在区域f12:h14设置边框样式三)
range = sheet.range["f12:h14"];
//合并单元格
range.merge();
//在合并的区域外部置应用细线
range.borderaround(linestyletype.thin);
//在合并的区域底部置应用粗线
range.borders[borderslinetype.edgebottom].linestyle = linestyletype.thick;
//设置颜色
range.borders.color = color.red;
//保存文档
wb.savetofile("result.xlsx", excelversion.version2013);
vb.net
'创建workbook对象,获取第一个工作表
dim wb as new workbook()
dim sheet as worksheet = wb.worksheets(0)
'选择区域(在区域b2:d4设置边框样式一)
dim range as cellrange = sheet.range("b2:d4")
'应用双线样式
range.borders.linestyle = linestyletype.[double]
'隐藏斜线
range.borders(borderslinetype.diagonaldown).linestyle = linestyletype.none
range.borders(borderslinetype.diagonalup).linestyle = linestyletype.none
'设置颜色
range.borders.color = color.blue
'选择区域(在区域d7:f9设置边框样式二)
range = sheet.range("d7:f9")
'区域内部置应用细线
range.borderinside(linestyletype.thin)
'区域外部置应用中粗线
range.borderaround(linestyletype.medium)
'隐藏斜线
range.borders(borderslinetype.diagonaldown).linestyle = linestyletype.none
range.borders(borderslinetype.diagonalup).linestyle = linestyletype.none
'选择区域(在区域f12:h14设置边框样式三)
range = sheet.range("f12:h14")
'合并单元格
range.merge()
'在合并的区域外部置应用细线
range.borderaround(linestyletype.thin)
'在合并的区域底部置应用粗线
range.borders(borderslinetype.edgebottom).linestyle = linestyletype.thick
'设置颜色
range.borders.color = color.red
'保存文档
wb.savetofile("result.xlsx", excelversion.version2013)
隐藏/取消隐藏网格线
c#
//创建workbook对象
workbook wb = new workbook();
//加载一个现成的excel文档
wb.loadfromfile("成绩统计表.xlsx");
//获取第一个工作表
worksheet sheet = wb.worksheets[0];
//隐藏网格线
sheet.gridlinesvisible = false;
////显示网格线
//sheet.gridlinesvisible = true;
//保存文档
wb.savetofile("result.xlsx", excelversion.version2013);
vb.net
'创建workbook对象
dim wb as new workbook()
'加载一个现成的excel文档
wb.loadfromfile("成绩统计表.xlsx")
'获取第一个工作表
dim sheet as worksheet = wb.worksheets(0)
'隐藏网格线
sheet.gridlinesvisible = false
'显示网格线
'sheet.gridlinesvisible = true;
'保存文档
wb.savetofile("result.xlsx", excelversion.version2013)