Java implements Excel data import and Export

Source: Internet
Author: User

Write an Excel file import java.io.*;import Jxl.*;import java.lang.boolean;public class writetoexcel{public Boolean run (stri            ng TargetFile) {try{Jxl.write.WritableWorkbook WWB = Workbook.createworkbook (new File (targetfile));            Jxl.write.WritableSheet ws = Wwb.createsheet ("MySheet1", 0);  for (int i = 0, I < i++) {for (int j = 0; J <; J + +) {Jxl.write.Label LABELC =                    New Jxl.write.Label (J, I, "cell[" +i+ "," +j+ "]");                Ws.addcell (LABELC);            }} wwb.write ();        Wwb.close ();//Remember to close to free space return true;            } catch (Exception e) {e.printstacktrace ();        return false; }}//reads an Excel file (created by the code above) and outputs the contents of import Java.io.*;import Jxl.*;import JXL on the console.            Workbook;import Java.lang.boolean;public class Readfromexcel {public Boolean run (String targetfile) {try{ InputStream is = new FileInputStream (TARGETFILE); Jxl.            Workbook RWB = Workbook.getworkbook (IS);            Sheet rs = rwb.getsheet (0); for (int i = 0, I < i++) {for (int j = 0; J <; J + +) {cell cell = Rs.getcell (j                , i);//The first digit is the column number, the second digit is the line number System.out.print (cell.getcontents () + "\ r");            } System.out.println ();            } rwb.close ();        return true;            } catch (Exception e) {e.printstacktrace ();        return false; }    }}

  

Java implements Excel data import and Export

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.