c# - 如何使用epplus隐藏一列的网格线
问题描述
WorkSheet.View.ShowGridLines = false;
这将在完整的 excel 中隐藏网格线。
解决方案
AFAIK,网格线仅适用于整个工作表,无论是在视图中,打印中,或两者兼而有之。我认为您在谈论Border
设置。你会做这样的事情:
[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();
}
}
给你这个:
推荐阅读
- angular - ngFor 匹配键值
- python - Python在某些单词后捕获某些数字
- python - Python pandas数据框删除索引名称不出现在其他数据框中的行
- python - 如何在 Ubuntu 18.04 上安装 python3.7 并使用 pip 创建一个 virtualenv?
- sql-server - 在 ADO 中捕获 T-SQL PRINT 输出?
- php - 如何实现 PHP 流包装器来修改另一个包装器的输出?
- react-google-maps - 如何从 react-google-maps 的 InfoWindow 中删除“关闭”按钮?
- python - In Jupyter Notebook and matplotlib, how to avoid replot everything in an interactive plot
- node.js - How to set markModified at object in array?
- jestjs - 开玩笑-每次拆毁都不叫