0

We are trying to bold a row in excel , Visual studio 2008,

framework 3.5 NPOI 1.2.5.0 - getting compile error

Following is the code snippet,

ICellStyle style1 = templateWorkbook.CreateCellStyle();
style1.SetFont(font1);
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
HSSFFont font = (HSSFFont)hssfworkbook.CreateFont();
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
style1.SetFont(font1);

it is giving compile error on line where we have written font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;

compile Error    2    
'NPOI.HSSF.UserModel.HSSFFont' does not contain a definition for 'BOLDWEIGHT_BOLD'   
C:\SampleApp\XLSFormatDotNet\XLSFormatingDLL\Class1.cs   301    60    XLSFormatingDLL

Sample codes on the internet show same syntax, but I am getting this compiler error, seems strange,

please help me. any suggestion welcome.

Regards sham

Sascha
  • 10,231
  • 4
  • 41
  • 65
Sham Yemul
  • 463
  • 7
  • 30

1 Answers1

1

HSSFFont is a class (see http://npoi.codeplex.com/SourceControl/changeset/view/64939#134674). The Boldweight property is of type short and there is an enum to help you set the properties:

public enum FontBoldWeight:short
{
        /**
     * Normal boldness (not bold)
     */

    NORMAL = 0x190,

    /**
     * Bold boldness (bold)
     */

    BOLD = 0x2bc,
}

You should try to do something like this:

 font.Boldweight = FontBoldWeight.BOLD;

Maybe they have changed from constants to enums and haven't updated their samples.

Sascha
  • 10,231
  • 4
  • 41
  • 65