C # insert a special symbol to excel -- HSSFRichTextString

Source: Internet
Author: User

Recently, when exporting excel files in. net, the customer needs to print out the symbols with the box and the box with the check box. There are countless questions online and there is no result. Later, the problem was solved using HSSFRichTextString. Using NPOI. HSSF. UserModel; using NPOI. SS. UserModel; this is a reference required to export the excel document. The following key parts. First, we need to export the above image and print the symbol according to the actual situation. The following describes the procedure (taking office2010 as an example): 1. open excel, click Insert> symbol, and find the above box with or without a check box, such as 2. after insertion, the two symbols appear in the excel table: select the two symbols respectively and change the font, for example,, and then change them to r£4, these special symbols are converted into letters or numbers by changing the font. 3. key code: [csharp] var a = new HSSFRichTextString ("R principal owner"); var font1 = (HSSFFont) sheet. workbook. createFont (); font1.FontName = "Wingdings 2"; font1.FontHeightInPoints = 14;. applyFont (0, 1, font1); sheet. getRow (3 ). getCell (1 ). setCellValue (a); var a = new HSSFRichTextString ("R principal owner"); var font1 = (HSSFFont) sheet. workbook. createFont (); font1.FontName = "Wingdings 2"; font1.FontHeightInPoints = 14; A. applyFont (0, 1, font1); sheet. getRow (3 ). getCell (1 ). setCellValue (a); the Code above means to use the Rich Text object HSSFRichTextString and then define a font. The font type is "Wingdings 2", which is the font corresponding to the symbol selected above. ApplyFont (, font1) is used to set the first letter in the string "R principal owner" to font1. The method parameter is ApplyFont (int startIndex, int endIndex, font font) then obtain a cell in excel and set its value to this Rich Text object. Other special symbols will be output, which can be output in phase.

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.