C# 如何使用epplus隐藏一列的轴网线
这将在完整的excel中隐藏网格线。好的,网格线仅适用于整个工作表,无论是在视图中还是在打印中,或者两者都适用。我想你说的是C# 如何使用epplus隐藏一列的轴网线,c#,.net,epplus,C#,.net,Epplus,这将在完整的excel中隐藏网格线。好的,网格线仅适用于整个工作表,无论是在视图中还是在打印中,或者两者都适用。我想你说的是Border设置。您可以这样做: WorkSheet.View.ShowGridLines = false; [TestMethod] 公共空白列_边框() { var数据表=新数据表(“tblData”); datatable.Columns.AddRange(新DataColumn[]{ 新数据列(“Col0”,typeof(object)), 新数据列(“Col1”
Border
设置。您可以这样做:
WorkSheet.View.ShowGridLines = false;
[TestMethod]
公共空白列_边框()
{
var数据表=新数据表(“tblData”);
datatable.Columns.AddRange(新DataColumn[]{
新数据列(“Col0”,typeof(object)),
新数据列(“Col1”,typeof(int)),
新数据列(“Col2”,typeof(int)),
新数据列(“Col3”,类型(对象))
});
对于(int i=0;i<10;i++)
{
var row=datatable.NewRow();
行[0]=Path.GetRandomFileName();
第[1]行=i;
第[2]行=i*10;
行[3]=Path.GetRandomFileName();
datatable.Rows.Add(行);
}
var fi=新文件信息(“c:\\temp\\Column\u Border.xlsx”);
如果(fi.存在)
fi.删除();
使用(ExcelPackage pck=新的ExcelPackage(fi))
{
var工作表=pck.Workbook.Worksheets.Add(“源”);
工作表.Cells[“A1”].LoadFromDataTable(datatable,true);
WorkSheet.View.ShowGridLines=false;
var allCells=工作表单元格;
allCells.Style.HorizontalAlignment=ExcelHorizontalAlignment.Center;
allCells.Style.Border.Top.Style=ExcelBorderStyle.Thin;
allCells.Style.Border.Bottom.Style=ExcelBorderStyle.Thin;
allCells.Style.Border.Left.Style=ExcelBorderStyle.Thin;
allCells.Style.Border.Right.Style=ExcelBorderStyle.Thin;
allCells.Style.Border.Top.Color.SetColor(Color.Green);
allCells.Style.Border.Bottom.Color.SetColor(Color.Green);
allCells.Style.Border.Left.Color.SetColor(Color.Green);
allCells.Style.Border.Right.Color.SetColor(Color.Green);
var colRange2=工作表.列(2);
colRange2.Style.Border.Top.Style=ExcelBorderStyle.None;
colRange2.Style.Border.Bottom.Style=ExcelBorderStyle.None;
colRange2.Style.Border.Left.Style=ExcelBorderStyle.None;
colRange2.Style.Border.Right.Style=ExcelBorderStyle.None;
pck.Save();
}
}
给你这个:
可能存在的副本
[TestMethod]
public void Column_Border()
{
var datatable = new DataTable("tblData");
datatable.Columns.AddRange(new DataColumn[] {
new DataColumn("Col0", typeof(object)),
new DataColumn("Col1", typeof(int)),
new DataColumn("Col2", typeof(int)),
new DataColumn("Col3", typeof(object))
});
for (int i = 0; i < 10; i++)
{
var row = datatable.NewRow();
row[0] = Path.GetRandomFileName();
row[1] = i;
row[2] = i * 10;
row[3] = Path.GetRandomFileName();
datatable.Rows.Add(row);
}
var fi = new FileInfo("c:\\temp\\Column_Border.xlsx");
if (fi.Exists)
fi.Delete();
using (ExcelPackage pck = new ExcelPackage(fi))
{
var WorkSheet = pck.Workbook.Worksheets.Add("source");
WorkSheet.Cells["A1"].LoadFromDataTable(datatable, true);
WorkSheet.View.ShowGridLines = false;
var allCells = WorkSheet.Cells;
allCells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
allCells.Style.Border.Top.Style = ExcelBorderStyle.Thin;
allCells.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
allCells.Style.Border.Left.Style = ExcelBorderStyle.Thin;
allCells.Style.Border.Right.Style = ExcelBorderStyle.Thin;
allCells.Style.Border.Top.Color.SetColor(Color.Green);
allCells.Style.Border.Bottom.Color.SetColor(Color.Green);
allCells.Style.Border.Left.Color.SetColor(Color.Green);
allCells.Style.Border.Right.Color.SetColor(Color.Green);
var colRange2 = WorkSheet.Column(2);
colRange2.Style.Border.Top.Style = ExcelBorderStyle.None;
colRange2.Style.Border.Bottom.Style = ExcelBorderStyle.None;
colRange2.Style.Border.Left.Style = ExcelBorderStyle.None;
colRange2.Style.Border.Right.Style = ExcelBorderStyle.None;
pck.Save();
}
}