Java and Excel

xiaoxiao2021-03-06  168

MS Excel is now very common as a data upload and reporting in the user, and performing Excel in Java is a very simple requirement, but there is no associated class in J2SE, and Apache Poi provides us with a good tool. It is very convenient to handle Excel through him. It is important that he is Open Source. I am brief here, according to a Demo, describe how to read the data in Excel.

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, I feel that there is a little bad if the content of the cell is a number, and you will use getStringcellValue () will have an abnormally thrown, so call Cell.getCellType (), call according to the type of Cell. Different ways.

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

In addition to Poi, there is also F1 for Java to process Excel, but he is commercial. The function is quite strong, it is a strong report tool, address at http://www.reportingengines.com

There is also Jexcel to handle the Excel URL at http://threebit.net/projects/jexcel.shtml

When it comes to handle Excel, I think webofficeComponent does not mention, I feel that he is a good tool. He is a COM control provided by the M $, which is displayed in the middle of the content in the Excel Web control in the webpage, and can be directly Pour out EXCEL, DEMO is as follows:

Width = "100%" height = "90%">

转载请注明原文地址:https://www.9cbs.com/read-128472.html

New Post(0)