I am setting a columnformat on a column by column basis, which works fine in its own.
Then I am also setting a background color (on a row by row basis), which also works fine in its own.
However, If I combine the two togehter, then the columnformat disappears.
With this code, I do colorize ony the first 10 codes, which then show up on the sheet
with no numberformat. All the other rows show up with the correct numberformat
Regards
Andreas
Here is my code:
{
foreach (NewsRoundtrip rt in rts)
{
ws.Cells [row,1].Value = rt.DateTime;
ws.Cells [row,2].Value = rt.RCompany;
ws.Cells [row,3].Value = rt.AccountName;
ws.Cells [row,4].Value = rt.ReportInfo;
ws.Cells [row,5].Value = rt.Symbol;
ws.Cells [row,6].Value = rt.Quantity;
ws.Cells [row,7].Value = rt.AvgEntry;
ws.Cells [row,8].Value = rt.AvgExit;
ws.Cells [row,9].Value = rt.PLEuro ;
string newGroup = rt.ReportInfo;
if (name == "Trader") newGroup= rt.RCompany;
if (last_group != newGroup)
{
last_group = newGroup;
if (bg == Color.LightBlue) bg = Color.LightGreen;
else bg = Color.LightBlue;
}
if (row<10)
{
ws.Row(row).Style.Fill.PatternType=ExcelFillStyle.Solid;
ws.Row(row).Style.Fill.BackgroundColor.SetColor(bg);
}
row++;
}
ws.Row(1).Style.Fill.PatternType=ExcelFillStyle.Solid;
ws.Row(1).Style.Fill.BackgroundColor.SetColor(Color.LightGray);
ws.Column(1).Style.Numberformat.Format = "yyyy-mm-dd hh:mm";
ws.Column(6).Style.Numberformat.Format = "#,##0";
ws.Column(7).Style.Numberformat.Format = "0.00000";
ws.Column(8).Style.Numberformat.Format = "0.00000";
ws.Column(9).Style.Numberformat.Format = "#,##0";
}
}
Then I am also setting a background color (on a row by row basis), which also works fine in its own.
However, If I combine the two togehter, then the columnformat disappears.
With this code, I do colorize ony the first 10 codes, which then show up on the sheet
with no numberformat. All the other rows show up with the correct numberformat
Regards
Andreas
Here is my code:
{
foreach (NewsRoundtrip rt in rts)
{
ws.Cells [row,1].Value = rt.DateTime;
ws.Cells [row,2].Value = rt.RCompany;
ws.Cells [row,3].Value = rt.AccountName;
ws.Cells [row,4].Value = rt.ReportInfo;
ws.Cells [row,5].Value = rt.Symbol;
ws.Cells [row,6].Value = rt.Quantity;
ws.Cells [row,7].Value = rt.AvgEntry;
ws.Cells [row,8].Value = rt.AvgExit;
ws.Cells [row,9].Value = rt.PLEuro ;
string newGroup = rt.ReportInfo;
if (name == "Trader") newGroup= rt.RCompany;
if (last_group != newGroup)
{
last_group = newGroup;
if (bg == Color.LightBlue) bg = Color.LightGreen;
else bg = Color.LightBlue;
}
if (row<10)
{
ws.Row(row).Style.Fill.PatternType=ExcelFillStyle.Solid;
ws.Row(row).Style.Fill.BackgroundColor.SetColor(bg);
}
row++;
}
ws.Row(1).Style.Fill.PatternType=ExcelFillStyle.Solid;
ws.Row(1).Style.Fill.BackgroundColor.SetColor(Color.LightGray);
ws.Column(1).Style.Numberformat.Format = "yyyy-mm-dd hh:mm";
ws.Column(6).Style.Numberformat.Format = "#,##0";
ws.Column(7).Style.Numberformat.Format = "0.00000";
ws.Column(8).Style.Numberformat.Format = "0.00000";
ws.Column(9).Style.Numberformat.Format = "#,##0";
}
}