JXL operation Excel writes the data does not overwrite the original data example _java

Source: Internet
Author: User

Packages that need to be imported: Jxl.jar

Copy Code code as follows:

public void Readto () {
Workbook WB = null;
Writableworkbook WWB = null;
try {
The file is = new file (System.getproperty ("User.dir") + "\\in.xls");
File OS = new file (System.getproperty ("User.dir") + "\\out.xls");
if (!os.isfile ())//If the specified file does not exist, create the new file
Os.createnewfile ();

WB = Workbook.getworkbook (IS);//Get Data source In.xls Workbook object
WWB = Workbook.createworkbook (OS, WB);//Append data to the original workbook Out.xls
WWB = Workbook.createworkbook (OS);//difference from the previous line of code, create a new write workbook
if (WB!= null && WWB!= null) {

Writablesheet sheet = wwb.getsheet (0);//Get Out.xls First sheet
Writablecell cell = Sheet.getwritablecell (2, 4);//Get Out.xls cell to write data

sheet[] sheets = wb.getsheets ()//Get data source In.xls sheets
Cell[] cells = sheets[0].getrow (1);//Get In.xls The second row of the first sheet
if (cell.gettype () = = Celltype.label) {
Label L = (label) cell;
L.setstring (Cells[1].getcontents ());//Writes the second cell to the fifth row of the third column of Out.xls
}
Wwb.write ();
System.out.println (Workbook writes data successful!) ");
}
Wwb.close ();//Close
catch (Exception e) {
E.printstacktrace ();
finally {
Wb.close ();
}
}

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.