Java read Excel data format conversion __java

Source: Internet
Author: User

Workbook workbook = (workbook) modelutils.getrequestcontext (). Getactioncontext (). GetParameter ("Excel");
Sheet Sheet = workbook.getsheetat (0);
System.out.println ("----------sheet0--------------");
First Behavior header row
Get second row data: Sheet.getrow (1)
Org.apache.poi.ss.usermodel.Row row= Sheet.getrow (1);

Set Cell type

Cell cell = Row.getcell (0);

System.out.println (cell.getcelltype ());

Celltype 0 is a numeric type that automatically becomes the scientific notation format when the number is too long

Output is 1.01001007835E9

So when a string of pure numbers reads a full number in Java, you need to convert the cell format to text type

Cell.setcelltype (1); 1 represents the format of a cell type as text

String Material_number = cell.tostring ();

System.out.println (Material_number);

Output as: 101001007835


Other ways to convert types

Hssfworkbook wb = new Hssfworkbook ();
Hssfcellstyle CellStyle = Wb.createcellstyle ();
Hssfdataformat format = Wb.createdataformat ();
Cellstyle.setdataformat (Format.getformat ("@"));

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.