c# - 如何格式化导出到 Excel 的 DataGridView 的背景?
问题描述
我想在 excel 中格式化我的标题单元格的背景,它是通过我的 Datagridview 填充的。我试过了
ws.Cells[1. 2].Style.Fill.PatternType = ExcelFillStyle.Solid;
ws.Cells[1, 2].Style.Fill.BackgroundColor.SetColor(Color.LightGray);
但我收到一条错误消息,显示名称 ExcelFillStyle.Solid 在当前上下文中不存在。有任何想法吗?
谢谢
解决方案
首先欢迎作为新的贡献者加入 SO 社区!
做一些研究,我建议使用以下内容更改GridView的标题颜色:
_dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
_dataGridView.EnableHeadersVisualStyles = false;
这是在SO上找到的: SO - How to change the color of dataGridView header
但是,如果您想使用更自定义的方法来解决这个问题,您可以设置特定的单元格(项目)背景颜色,这可以使用以下方法完成:
DataGridView1.CurrentCell = DataGridView1.Item("ColumnName", 5)
columnHeadingsRange.Interior.Color = XlRgbColor.rgbSkyBlue;
此处的SO对此用例进行了解释:
使用这两个来源应该可以帮助您实现您所需要的,因为这两个来源都已得到解答。
推荐阅读
- java - 在Matlab图中设置java swing组件可见性时,一个矩形仍然存在
- c++ - 落沙模拟碰撞检测C++和SFML
- compiler-construction - 为什么我们需要 ABI 和调用约定
- javascript - 如何在nodejs中将字符串转换为Uint8Array类型
- javascript - 为什么我不能使用 Array.prototype.join.call 作为 Promise 的回调?
- node.js - 将 winston 日志传输到服务器
- java - 如果超构造函数中有参数,则超类内部类的构造函数是未定义的
- python - Python数据框丢弃发生频率较低的行
- c# - 在 iText7 (.NET) 中为现有 PDF 的每一页添加页脚
- java - Android Studio - 重新格式化代码“优化导入”顺序无法正常工作