NPOI sets the Excel cell font, border, alignment, and background color. npoiexcel

Source: Internet
Author: User

NPOI sets the Excel cell font, border, alignment, and background color. npoiexcel

Code:

ICellStyle cellStyle = workbook. createCellStyle (); cellStyle. borderBottom = BorderStyle. thin; cellStyle. borderLeft = BorderStyle. thin; cellStyle. borderRight = BorderStyle. thin; cellStyle. borderTop = BorderStyle. thin; cellStyle. verticalAlignment = NPOI. SS. userModel. verticalAlignment. center; cellStyle. alignment = NPOI. SS. userModel. horizontalAlignment. center; ICellStyle cellStyleTitle = workbook. createCellStyle (); cellStyleTitle. borderBottom = BorderStyle. thin; cellStyleTitle. borderLeft = BorderStyle. thin; cellStyleTitle. borderRight = BorderStyle. thin; cellStyleTitle. borderTop = BorderStyle. thin; cellStyleTitle. verticalAlignment = NPOI. SS. userModel. verticalAlignment. center; cellStyleTitle. alignment = NPOI. SS. userModel. horizontalAlignment. center; IFont font = workbook. createFont (); font. isBold = false; font. fontHeightInPoints = 12; cellStyleTitle. setFont (font); HSSFPalette = (HSSFWorkbook) workbook ). getCustomPalette (); palette. setColorAtIndex (short) 9, 98,185,106); var color = palette. findColor (98,185,106); // set the cell background color cellStyleTitle in the following two rows. fillPattern = FillPattern. solidForeground; cellStyleTitle. fillForegroundColor = color. indexed; ICellStyle cellStyleTitle2 = workbook. createCellStyle (); cellStyleTitle2.CloneStyleFrom (cellStyleTitle); font = workbook. createFont (); font. isBold = false; font. fontHeightInPoints = 14; cellStyleTitle2.SetFont (font );View Code

 

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.