【发布时间】:2015-05-22 08:51:15
【问题描述】:
我根据DataSet 创建了一个 Excel 文件,我想添加一个带有红绿灯的列。
红绿灯:
int trafficCollor = 1;
if (trafficCollor == 1)
{
DataRow NR = DT.NewRow();
NR[0] = ""; //add string with the code for the Excel traffic light yellow
}
if (trafficCollor < 1)
{
DataRow NR = DT.NewRow();
NR[0] = ""; //add string with the code for the Excel traffic light green
}
if (trafficCollor > 1)
{
DataRow NR = DT.NewRow();
NR[0] = ""; //add string with the code for the Excel traffic light red
}
Excel 是如何创建的:
//Create an Excel application instance
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelWorkBook = excelApp.Application.Workbooks.Add();
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
excelApp.Visible = false;
worksheet = excelWorkBook.ActiveSheet;
//set headers
for (int i = 1; i < DGV.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = DGV.Columns[i - 1].HeaderText;
}
createList(worksheet, DGV);
//Create excel with the choosen name
Worksheet sheet1 = excelWorkBook.Worksheets[1];
worksheet.Name = fileName;
如果您对存档此类内容有任何建议,请告诉我!
【问题讨论】:
-
您是如何创建 Excel 文件的?您将无法将条件格式添加到
DataTable。 -
@Charles Mager 查看编辑..
-
我没有看到您在代码中使用条件格式做任何事情?
标签: c# excel excel-2013 conditional-formatting