Use POI to read all sheet tables in Excel

Source: Internet
Author: User
Use POI to read all sheet tables in Excel
Recently contacted the import and export of multiple sheet pages, now gives examples of how to use POI to read all sheet table contents in Excel through multiple loops.

Package poitest;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Org.apache.poi.hssf.usermodel.HSSFRow;
Import Org.apache.poi.hssf.usermodel.HSSFSheet;
Import Org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class Getallexceldata {

public static void Main (string[] args) {
try {
Showexcel ();
catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
public static void Showexcel () throws Exception {
Hssfworkbook workbook=new Hssfworkbook (New FileInputStream ("/file/student.xls"));
Hssfsheet Sheet=null;
for (int i = 0; i < workbook.getnumberofsheets (); i++) {//Get each sheet table
Sheet=workbook.getsheetat (i);
for (int j = 0; J < Sheet.getphysicalnumberofrows (); j + +) {//Get each row
Hssfrow Row=sheet.getrow (j);
for (int k = 0; k < Row.getphysicalnumberofcells (); k++) {//Get each cell
System.out.print (Row.getcell (k) + "T");
}
SYSTEM.OUT.PRINTLN ("---sheet table" +i+ "Processing completed---");
}
}
}
}

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.