[英]How to save Excel file exported from datagridview in a particular folder with unique name?
[英]How to format background of DataGridView exported to Excel?
我想在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-如何更改dataGridView標頭的顏色
但是,如果您想使用一種更自定義的方法來解決此問題,即可以設置特定單元格 (項目)的背景顏色,則可以使用以下方法完成:
DataGridView1.CurrentCell = DataGridView1.Item("ColumnName", 5)
columnHeadingsRange.Interior.Color = XlRgbColor.rgbSkyBlue;
在SO上對此用例進行了說明:
使用這兩個資源應該可以幫助您實現所需的目標,因為這兩個問題都已得到解答 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.