我在Winform C#中的DataGridView中製作了Shift Roster。 This是我從DataGridView導出的excel表格截圖。導出DataGridVeiw在C#中使用單元格背景色優於
我需要導出DataGridView,因爲它是Excel工作表維護字體顏色和背景顏色也我不想導出的第一列DataGridView到Excel是不可見的。
我已經使用下面的代碼將DataGridView導出到Excel。
using (ExcelPackage pck = new ExcelPackage(file))
{
// Add a new worksheet to the empty workbook
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Sheet1");
// Load data from DataTable to the worksheet
ws.Cells["A1"].LoadFromDataTable(((DataTable)gvShift.DataSource), true);
ws.Cells.AutoFitColumns();
// Add some styling
using (ExcelRange rng = ws.Cells[1, 1, 1, gvShift.Columns.Count])
{
rng.Style.Font.Bold = true;
rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(79, 129, 189));
rng.Style.Font.Color.SetColor(System.Drawing.Color.White);
}
請幫助請....
什麼庫或DLL用於Excel導出? – Kira
我使用的Microsoft.Office.Interop.Excel –
@MianSalmanNasir待辦事項看看EPPlus了。 – Yahya