Java reads Excel content with JXL

Source: Internet
Author: User

ImportJava.io.File;ImportJava.io.FileInputStream;ImportJXL. Cell;ImportJXL. Sheet;ImportJXL. Workbook; Public classTestxls {/*** Read xls file contents *@paramfile object to read *@returnReturn file Contents*/     Public Staticstring xls2string (file file) {string result= ""; Try{FileInputStream fis=Newfileinputstream (file); StringBuilder SB=NewStringBuilder (); Jxl. Workbook RWB=Workbook.getworkbook (FIS); Sheet[] Sheet=rwb.getsheets ();  for(inti = 0; i < sheet.length; i++) {Sheet rs=Rwb.getsheet (i);  for(intj = 0; J < Rs.getrows (); J + +) {cell[] cells=Rs.getrow (j);  for(intk=0;k<cells.length;k++) Sb.append (Cells[k].getcontents ());               }} fis.close (); Result+=sb.tostring (); }Catch(Exception e) {e.printstacktrace (); }        returnresult; }     Public Static voidMain (string[] args) {File file=NewFile ("D:/lucenedata/test5.xls");    System.out.println (xls2string (file)); }}



Jxl.jar

Java reads Excel content with JXL

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.