I try create excel document via SpreadsheetGear. And i would like to apply some styles on headers?fonts etc same as on screenshot:
I wrote the following code:
static string[] fieldsName =
{
"Name",
"LastName",
"Address",
"Phone"
};
private static void Main(string[] args)
{
var workbook = Factory.GetWorkbook();
IWorksheet worksheet = workbook.ActiveWorksheet;
IRange cells = worksheet.UsedRange;
cells["A1:C1"].Style.Font.Bold = true;
cells["A1:C1"].Font.Color = Color.FromArgb(255, 255, 255);
cells["A1:C1"].Interior.Color = Color.FromArgb(0, 204, 0);
cells["A1"].Value = " ";
cells["B1"].Value = "My demo excel file";
cells["C1"].Value = " ";
cells["A2:C2"].Style.Font.Bold = true;
cells["A2"].Value = "Field";
cells["B2"].Value = "Description";
cells["C2"].Value = "Value";
FillDecisionCells(cells);
workbook.SaveAs(@"D:\test.xlsx", FileFormat.OpenXMLWorkbook);
}
Then I try to fill Field column without bold font style:
private static void FillDecisionCells(IRange cells)
{
for (var i = 2; i < fieldsName.Length; i++)
{
cells[i, 0].Value = fieldsName[i];
}
}
But end up with all the text in bold: