Robotium Java Read excel2010

Source: Internet
Author: User

Reading Excel in Java is of course a troublesome thing, but now open source is a lot of things, naturally become simple, let us take a look, the previous and everyone share is to use JXL read Excel, Pit can be defective, and now share is the POI read Excel, they two what is the difference?

We quote the following passage

Data volume 3,000 data, 60 columns per bar. JVM Virtual machine memory size 64M.
Use POI: Run to 2,800 or so to report memory overflow.
Use the jxl:3000 strip all out, and the memory has 21M of space.
It is conceivable that the memory consumption of the gap is still quite large.
Maybe it's because JXL is doing a pretty good job of recycling resources.
As for the efficiency of the two, it is also based on the large data volume, the small amount of data is basically different, it is not difficult to be detected. But with large data volumes, POI consumes more JVM memory than JXL consumes. But compared to the features provided, JXL is a little bit weaker. So if you want to implement a more complex scenario, consider using POI, but if you want to generate some big data, consider using JXL, or CSV is a good choice, but CSV is not really excel

This passage comes from http://blog.csdn.net/lilinandlilin/article/details/24098699.

This clearly distinguishes between the two, which is only the beginning, not the content to be shared today:

Here's what to share today: POI read Excel

First jar package is not small, in my network can be down to the connection:

Http://pan.baidu.com/s/1eQH7L30

And then find

Poi-ooxml-3.9-20121203.jar

Poi-ooxml-schemas-3.9-20121203.jar

Poi-3.9-20121203.jar

Dom4j-1.6.1.jar

Xmlbeans-2.3.0.jar

The following two jars are in the Ooxml-lib folder;

After the addition is completed, two Excel is built below the D drive, which we use to read;

Package Poi;import Java.io.fileinputstream;import Java.io.ioexception;import java.io.inputstream;import Java.util.iterator;import Org.apache.poi.hssf.usermodel.hssfcell;import Org.apache.poi.hssf.usermodel.hssfworkbook;import Org.apache.poi.ss.usermodel.cell;import Org.apache.poi.ss.usermodel.row;import Org.apache.poi.ss.usermodel.sheet;import Org.apache.poi.ss.usermodel.workbook;import Org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ReadExcel001 {public static void main (string[] args) {readXml ("d:/test case. xlsx"); System.out.println ("-------------"); READXML ("d:/test case. xls"); }public static void ReadXml (String fileName) {Boolean isE2007 = false;//Determines if it is excel2007 format if (Filename.endswith ("xlsx")) isE2007 = true;try {InputStream input = new FileInputStream (fileName);//Establish input stream Workbook WB = null;//According to the file format (2003 or 2007) to initialize if (isE2007) WB = new Xssfworkbook (input), ELSEWB = new Hssfworkbook (input); Sheet Sheet = wb.getsheetat (0);//Get the first form iterator<row> rows = Sheet.rowiterator ();//The iterator that gets the first form while (Rows.hasnext ()) {Row row = Rows.next ();//Get Row data System.out.println ("Row #" + Row.getrownum ());//Get line number starting from 0 iterator<cell> cells = Row.celliterator ();//Gets the first line of the iterator while (Cells.hasnext ()) {Cell cell = Cells.next (); System.out.println ("Cell #" + Cell.getcolumnindex ()); switch (Cell.getcelltype ()) {//Output data case according to type in cell HSSFCell.CELL_TYPE_NUMERIC:System.out.println (Cell.getnumericcellvalue ()); Break;case hssfcell.cell_type_string: System.out.println (Cell.getstringcellvalue ()); Break;case HSSFCell.CELL_TYPE_BOOLEAN:System.out.println ( Cell.getbooleancellvalue ()); Break;case HSSFCell.CELL_TYPE_FORMULA:System.out.println (Cell.getcellformula ()); BREAK;DEFAULT:SYSTEM.OUT.PRINTLN ("unsuported sell type"); break;}}} catch (IOException ex) {ex.printstacktrace ();}}}

This will enable you to read the Excel content.

Robotium Java Read excel2010

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.