Poi reads cells that process numbers in Excel

Source: Internet
Author: User
When I read EXCEL from poi, I encountered the following common case:

When you enter 1000 in a cell, poi needs to use getnumericcellvalue () to obtain the value, even though you set the cell to text in Excel.

If you insist on using getstringcellvalue (), the following error is returned:

Cannot get a text value from a numeric cell...

When you use getnumericcellvalue () to obtain the value, you will find that the value you get is 1000.0. Because poi treats it as a double.

In this case, we should do the following:

                HSSFCell cell7 = row.getCell(7);                cell7.setCellType(Cell.CELL_TYPE_STRING);                String content = cell7.getStringCellValue();                myModel.setContent(content);

That is, set the cell type to string in Java code.

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.