Bold Fonts

Jun 13, 2010 at 2:19 AM

I created two fonts:

HSSFFont headerFont = imWorkbook.CreateFont();
headerFont.FontHeightInPoints = 9;
headerFont.Color = HSSFColor.BLACK.index;
headerFont.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
headerFont.FontName = "Calibri";

and

HSSFFont wbFont = imWorkbook.CreateFont();
wbFont.Color = HSSFColor.BLACK.index;
wbFont.Boldweight = HSSFFont.BOLDWEIGHT_NORMAL;
wbFont.FontName = "Calibri";
wbFont.FontHeightInPoints = 9;

I apply the headerFont to the header row and it "Bolds" all the column in the rows. 

Then I apply the wbFont to the rest of the rows in the sheet and but they stay bold. 

What am I doing wrong?

 

 

Jun 14, 2010 at 10:43 PM

I think your doing something wrong in how your apply the HSSFCellStyle to the header row.  Here is a quick example of making everything in the header (aka: Row 0) bold.

            HSSFSheet sheet = workbook.GetSheet("Sheet1"); // Get Sheet1

            HSSFFont headerRowCellFont = workbook.CreateFont(); // Create a new font in the workbook
            headerRowCellFont.FontName = "Calibri";
            headerRowCellFont.Color = HSSFColor.BLACK.index;
            headerRowCellFont.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;

            HSSFCellStyle headerRowCellStyle = workbook.CreateCellStyle(); // Create a new style in the workbook
            headerRowCellStyle.SetFont(headerRowCellFont);  // Attach the font to the Style

            foreach (HSSFCell cell in sheet.GetRow(0).Cells)
            {
                cell.CellStyle = headerRowCellStyle; // Assign style to all the cells in the header
            }

This will not change your detail rows, only your header row.

Jun 19, 2010 at 11:09 PM

Thank you but in following your code

foreach (HSSFCell cell in sheet.GetRow(0).Cells) {
    cell.CellStyle = headerRowCellStyle; // Assign style to all the cells in the header
}
The GetRow(0).Cells does not work - there is no defination to "Cells"
Roy

 

Jun 23, 2010 at 4:15 AM

Sounds like I made a typo, since I still don't have VS in front of me hopefully this one is perfect.

 

HSSFRow headerRow = sheet.GetRow(0);

for(int x = 0; x < headerRow.LastCellNum; x++)
{
    //Do Work
} 

 

Jun 23, 2010 at 6:25 AM

Thank you got it working...