NPOI Excel Style settings, npoiexcel Style

Source: Internet
Author: User
Tags comparison table italic font

NPOI Excel Style settings, npoiexcel Style
1. Create an Excel file

// Create a workbook XSSFWorkbook workbook = new XSSFWorkbook (); // create a page ISheet sheet = workbook. createSheet ("sheet1"); // create an IRow row = sheet. createRow (0); // create an ICell cell = row column. createCell (0 );

 

2. Set the font
ICellStyle style = workbook. createCellStyle (); // create a style object IFont font = workbook. createFont (); // create a font style object. fontName = "正 "; // font corresponding to the font in the excel file. color = new HSSFColor. PINK (). getIndex (); // color reference NPOI color table (replace PINK () font. isItalic = true; // italic font. fontHeightInPoints = 16; // font size. boldweight = short. maxValue; // Bold style in the font. setFont (font); // assign the font style to the style object
Cell. CellStyle = style; // assign the style to the cell.
3. Set cell 1 and cell foreground color
ICellStyle style = workbook. CreateCellStyle (); style. FillForegroundColor = 14; // you can see the NPOI Color comparison table style. FillPattern = FillPatternType. SOLID_FOREGROUND;
2. cell width and height

Row Height: row. Height = 30*20; // The row Height is 30.

Column width: sheet. SetColumnWidth (3, 13*256) // The column width of the 4th column is 13

3. Merge Cells

After cells are merged, the style is subject to the cells in the upper left corner.

// The four parameters of CellRangeAddress are: Start row, end row, start column, and end column.

Sheet. AddMergedRegion (new CellRangeAddress (0, 0, 0, 10 ));

4. horizontal center

Style. Alignment = HorizontalAlignment. CENTER;

5. Set the formula

No need to write "="

Cell. CellFormula = "formula ";

6. Border

// Upper, lower, and left

StyleFont. BorderTop = NPOI. SS. UserModel. BorderStyle. THIN;
StyleFont. BorderBottom = NPOI. SS. UserModel. BorderStyle. THIN;
StyleFont. BorderLeft = NPOI. SS. UserModel. BorderStyle. THIN;
StyleFont. BorderRight = NPOI. SS. UserModel. BorderStyle. THICK;

 

Color Table:

Color Test Class Name Short
       
  Test color Black 8
  Test color Brown 60
  Test color Olive_Green 59
  Test color Dark_Green 58
  Test color Dark_Teal 56
  Test color Dark_Blue 18
  Test color Indigo 62
  Test color Grey_80_PERCENT 63
  Test color Dark_Red 16
  Test color Orange 53
  Test color DARK_YELLOW 19
  Test color Green 17
  Test color Teal 21
  Test color Blue 12
  Test color Blue_Grey 54
  Test color Grey_50_PERCENT 23
  Test color Red 10
  Test color LIGHT_ORANGE 52
  Test color LIME 50
  Test color SEA_GREEN 57
  Test color AQUA 49
  Test color LIGHT_BLUE 48
  Test color Viotlet 20
  Test color GREY_40_PERCENT 55
  Test color Pink 14
  Test color Gold 51
  Test color Yellow 13
  Test color BRIGHT_GREEN 11
  Test color TURQUOISE 15
  Test color SKY_BLUE 40
  Test color Plum 61
  Test color GREY_25_PERCENT 22
  Test color Rose 45
  Test color Tan 47
  Test color LIGHT_YELLOW 43
  Test color LIGHT_GREEN 42
  Test color LIGHT_TURQUOISE 41
  Test color PALE_BLUE 44
  Test color LAVENDER 46
  Test color White 9
  Test color CORNFLOWER_BLUE 24
  Test color LEMON_CHIFFON 26
  Test color MAROON 25
  Test color ORCHID 28
  Test color CORAL 29
  Test color ROYAL_BLUE 30
  Test color LIGHT_CORNFLOWER_BLUE 31
  Test color AUTOMATIC 64

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.