Solution to the formatting problems of Java for importing Excel data into a database

Source: Internet
Author: User
Tags java web

Previously, as a project party, and Java contact is not much, in Java Web Development is to play a part.

For Excel data import into the database This problem has always been the format reason and import failure is also a bit melancholy, the development team just said go back to check the format.

However, each time the import is also due to formatting problems and worry, recently put the code to study a bit, online check.

It turns out that there is no direct assignment of format matching after extracting data from the cell. Therefore, it would be nice to do a format match before extracting the data to the database.

So frustrated by the PREVIOUS ignorance!

1 //Convert Excel cell legacy data to String type2     PrivateString getcellstring (cell cell) {3String cellsring= "";4         Switch(Cell.getcelltype ()) {5          CaseHssfcell.cell_type_string://string6Cellsring =Cell.getstringcellvalue ();7              Break; 8          CaseHssfcell.cell_type_numeric://Digital9cellsring=string.valueof (Cell.getnumericcellvalue ());Ten              Break;  One          CaseHssfcell.cell_type_boolean://Boolean Acellsring=string.valueof (Cell.getbooleancellvalue ()); -              Break;  -          CaseHssfcell.cell_type_formula://Formula thecellsring=string.valueof (Cell.getcellformula ()); -              Break;  -          CaseHssfcell.cell_type_blank://Null value -Cellsring= "";  +              Break;  -          CaseHssfcell.cell_type_error://malfunction +Cellsring= "";  A              Break;  at         default:   -Cellsring= "ERROR";  -              Break;  -       }         -         returncellsring; -}

Of course the import POI package is required:

Import Org.apache.poi.hssf.usermodel.HSSFCell;

Solution to the formatting problems of Java for importing Excel data into a database

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.