我已经在pdf表中添加了一些条件,但是我想在其他条件中添加替代行颜色,而不仅仅是白色。您可以看到有四种条件可以更改行颜色,但是我想在其他条件下放置替代颜色。
我的代码如下所示
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int k = 0; k < 2; k++)
{
if (dataGridView1[k, i].Value != null)
{
DateTime dateTime = DateTime.UtcNow.Date;
var tomorrow = dateTime.AddDays(1);
var tom1 = dateTime.AddDays(2);
var tom2 = dateTime.AddDays(3);
string data = dataGridView1.Rows[i].Cells[6].Value.ToString();
string dateVal = Convert.ToDateTime(dataGridView1[k, i].Value).ToString("MM/dd/yyyy");
PdfPCell cellc = new PdfPCell(new Phrase(dateVal, fontTable));
if (dateVal == dateTime.ToString("MM/dd/yyyy") && data != "FIN - ENIG ")
{
cellc.BackgroundColor = new iTextSharp.text.Color(0, 240, 240);
pdfTable.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
}
else if (data != "FIN - ENIG " && dateVal == tomorrow.ToString("MM/dd/yyyy"))
{
cellc.BackgroundColor = new iTextSharp.text.Color(0, 240, 240);
pdfTable.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
}
else if (data != "FIN - ENIG " && dateVal == tom1.ToString("MM/dd/yyyy"))
{
cellc.BackgroundColor = new iTextSharp.text.Color(0, 240, 240);
pdfTable.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
}
else if (data != "FIN - ENIG " && dateVal == tom2.ToString("MM/dd/yyyy"))
{
cellc.BackgroundColor = new iTextSharp.text.Color(0, 240, 240);
pdfTable.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
}
else
{
// pdfTable.DefaultCell.BackgroundColor = BaseColor.WHITE;
}
pdfTable.AddCell(cellc);
}
}