Java reader versions 03 and 07 EXCEL, java0307excel

Source: Internet
Author: User

Java reader versions 03 and 07 EXCEL, java0307excel

Jxl. jar is required for excel version 03.

Package test. poi; import java. io. file; import java. io. IOException; import jxl. sheet; import jxl. workbook; import jxl. read. biff. biffException; // version 03 excelpublic class getExcel {public static void main (String [] args) {show03Excel ();} public static void show03Excel () {Sheet sheet; workbook book = null; try {book = Workbook. getWorkbook (new File ("F: \ Book1.xls");} catch (BiffException e) {e. printStackTrac E ();} catch (IOException e) {e. printStackTrace ();} // System. out. println (book); // obtain the first worksheet object (the sheet number in ecxel starts from 0 ,....) sheet = book. getSheet (0); int rows = 0; int r = 0, l = 0; String value = null; while (sheet. getCell (0, r ). getContents ()! = "" & Sheet. getCell (0, r). getContents ()! = Null) {r ++;} while (sheet. getCell (l, 0). getContents ()! = "" & Sheet. getCell (l, 0). getContents ()! = Null) {l ++;} for (int I = 0; I <(r); I ++) {for (int j = 0; j <(l ); j ++) System. out. print (sheet. getCell (j, I ). getContents () + "\ t"); System. out. println ();}}}

The jar package poi is required for EXCEL of Version 07.

Package test. poi; import java. io. IOException; import org. apache. poi. xssf. usermodel. XSSFRow; import org. apache. poi. xssf. usermodel. XSSFSheet; import org. apache. poi. xssf. usermodel. XSSFWorkbook; public class get07Excel {public static void main (String [] arg) {show07excel ();} public static void show07excel () {XSSFWorkbook xwb = null; try {xwb = new XSSFWorkbook ("F: \ Book1.xlsx");} catch (IOException e) {e. PrintStackTrace ();} XSSFSheet sheet = xwb. getSheetAt (0); XSSFRow row; String cell; int r = 0, l = 0; row = sheet. getRow (0); while (row. getCell (l ). toString ()! = "" & Row. getCell (l). toString ()! = Null) {l ++;} while (row. getCell (0). toString ()! = "" & Row. getCell (0). toString ()! = Null) {r ++; row = sheet. getRow (r);} System. out. println ("the rows is" + r + "and the number of one row is" + l); // cyclically output the table content for (int I = sheet. getFirstRowNum (); I <r; I ++) {row = sheet. getRow (I); for (int j = row. getFirstCellNum (); j <l; j ++) {cell = row. getCell (j ). toString (); System. out. print (cell + "\ t");} System. out. println ("");}}}

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.