Java and Excel

Source: Internet
Author: User

MS Excel is widely used for data uploading and reporting. It is very simple to process excel in Java, but related classes are not provided in j2se, apache poi provides us with a good tool. It is very convenient to use it to process excel. The important thing is that it is open source. Here I will briefly describe how to read data in Excel using a demo.

Import org. Apache. Poi. hssf. usermodel .*;
Import java. Io. fileinputstream;
Import org. Apache. Poi. poifs. filesystem. poifsfilesystem;

Public class testpoi
{

Public static void main (string [] ARGs) throws exception {
Poifsfilesystem FS =
New poifsfilesystem (New fileinputstream ("book1.xls "));
Hssfworkbook WB = new hssfworkbook (FS );
Hssfsheet sheet = WB. getsheetat (0 );
Hssfrow ROW = sheet. getrow (2 );
Hssfcell cell = row. getcell (short) 3 );
String value = cell. getstringcellvalue ();
System. Out. println ("the Excel value is" + value );

}
}

When using poi, it is difficult to find that if the cell content is a number and you use getstringcellvalue (), an exception will be thrown, so you should call the cell first. getcelltype (), which calls different methods based on the cell type.

Poi URL in http://jakarta.apache.org/poi/

In addition to poi, F1 for Java also handles excel, but it is commercial. Strong functionality, is a strong reporting tool, address in http://www.reportingengines.com

There is also jexcel can also process Excel URLs in http://threebit.net/projects/jexcel.shtml

When it comes to excel processing, I think webofficecomponent is a good tool. It is a COM control provided by M $, in the web page, the content of a table is displayed in the middle of the Excel Web control, and can be displayed as Excel directly. The demo is as follows:

xmlns =" http://www.w3.org/TR/REC-html40 ">








9.0.0.2710

Microsoft Office spreadsheet

sheet1


7620
15240
0
0
false
210
2389



80%
80%












Who am I I am a Web Office component
who am Fang jianghua


">

Width = "100%" Height = "90%">

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.