我正在写一个工作正常的 Excel 电子表格,但我需要将标题着色为深蓝色并将字体颜色设为白色,但我在弄清楚如何实现这一点时遇到了一些问题.....这是到目前为止我的代码:
foreach (DataColumn c in DT.Columns)
{
iColumnCount++;
if(iRowCount == 0)
Worksheet.Cells[1, iColumnCount] = c.ColumnName;
else
Worksheet.Cells[iRowCount, iColumnCount] = c.ColumnName;
Worksheet.Columns.AutoFit(); //Correct the width of the columns
//THIS IS WHERE I WANT TO COLOR THE HEADERS
}
foreach (DataRow r in DT.Rows)
{
iRowCount++;
iColumnCount = 0;
foreach (DataColumn c in DT.Columns)
{
iColumnCount++;
if(iRowCount == 1)
Worksheet.Cells[iRowCount + 1, iColumnCount] = r[c.ColumnName].ToString();
else
Worksheet.Cells[iRowCount, iColumnCount] = r[c.ColumnName].ToString();
Worksheet.Columns.AutoFit(); //Correct the width of the columns
}
}
任何人都可以帮助我实现这一目标吗?