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%">