Java JXL An example of appending data to Excel without overwriting the original data

Source: Internet
Author: User

Writing data to Excel that has data in the first place will not overwrite the original data, just append the data. public class Excel {    public Excel () {    }    public void Createworkbook (file file, double[] a) {        try {             if (!file.exists ()) {//determines if the file already exists and creates a new file if it does not exist                  jxl.write.writableworkbook WWB = Workbook.createworkbook (new                         file ("Result.xls"                           );                 jxl.write.writablesheet ws = Wwb.createsheet ("Test Sheet 1", 0);  &nbSp;              int i = 0;                 ws.setcolumnview (0, 20); Set column widths                  Jxl.write.NumberFormat NF = new Jxl.write.NumberFormat (                          "0.0000000000000000" ); Define numeric formats                  Writablecellformat WCFN = new Writablecellformat (NF);                 string str2 = "No." + 1 + "secondary test";                 label label = new label (0, 0, str2);        &Nbsp;        ws.addcell (label);                 while (i < a.length) {                      Jxl.write.Number num = new Jxl.write.Number (0, i + 1,                             a[ I], WCFN);                     ws.addcell (num);                     i++;                 }                 //Write Exel Worksheets                  Wwb.write ();                 // Close the Excel Workbook object                  Wwb.close ();             } else {                 workbook RWB = Workbook.getWorkbook (file);                 file Tempfile = new File (System.getproperty ("User.dir") +                                            "\\tempfile.xls");                 writableworkbook WWB = Workbook.createWorkbook ( Tempfile, RWB);                 Writablesheet ws = Wwb.getsheet (0);                 int num = rwb.getsheet (0). GetColumns ();                 int NUM1 = num + 1;                 ws.setcolumnview (num, 20); Set Column width                 string STR2 = "First" + NUM1 + "secondary test"; Add Column name                 label Label = new label (num, 0, str2);                &nBsp;ws.addcell (label);                 int i = 0;                 jxl.write.numberformat NF = new Jxl.write.NumberFormat (                          " 0.000000000000000 "); Define numeric formats                  Writablecellformat WCFN = new Writablecellformat (NF);                 while (i < a.length) {                     jxl.write.number number = new Jxl.write.Number (num,                  &nbsP;          i + 1,                              a[i], WCFN);                     ws.addcell (number);                     i++;                 }                 wwb.write ();                 wwb.close ();                 rwb.close ();                 string filename = File.getpath ();         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("FileName:" + filename);                 file.delete ();                 tempfile.renameto (file);                 system.out.println (" Tempfile: "+ Tempfile.getpath ());                 system.out.println (Tempfile.exists ());                 system.out.println (File.exists ());             }        } catch (Exception e) {   &Nbsp;         e.printstacktrace ();         }    }}

Java JXL An example of appending data to Excel without overwriting the original data

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.