Jexcelapi Modify existing Excel

Source: Internet
Author: User
Package com.jExcelApi.test;
Import Java.io.File;
 
Import java.io.IOException; Import JXL.
workbook;
Import jxl.read.biff.BiffException;
Import Jxl.write.Label;
Import Jxl.write.Number;
Import Jxl.write.WritableSheet;
Import Jxl.write.WritableWorkbook;
 
  
 
Import jxl.write.WriteException; /** * Jexcelapi Modify the contents of Excel * @author Kanjingcai * Note: Must add JEXCELAPI jar execution/public class Updateexcel {public stat IC void Main (String args[]) {try {//Get create Myfile.xls File Workbook Workbook =workbook.getworkbook (new file ("D:\\m
    
 
   Yfile.xls "));
    
   Copy a copy and assign to the original file Writableworkbook copy1 =workbook.createworkbook (New file ("D:\\myfile.xls"), workbook);
    
   Copy a Output.xls//Writableworkbook copy2 =workbook.createworkbook (New File ("D:\\output.xls"), workbook);
    
   or directly modify the D:\\myfile.xls file Writablesheet Sheet1 = copy1.getsheet (0);
    
   New Excel file, copy first page worksheet to Output.xls file, (0) on behalf of the first page//writablesheet Sheet2 =copy2.getsheet (0);  Get row No. 0, second column data (0,2)// Writablecell cell1 =sheet1.getwritablecell (0,2);
 
     New Excel file, get row No. 0, second column data (0,2)//Writablecell cell2 =sheet2.getwritablecell (0,2);
     Label label =new label (0,2, "new Record");
      
     Sheet1.addcell (label);
      
     Number number =new number (3,4,3.141591);
      
   Sheet1.addcell (number);
     
    Modify to get the contents of row No. 0, second column data (0,2)//Get cell type//if (Cell1.gettype () ==celltype.label) {label L = (LABEL) cell1;
   Modified content l.setstring ("Modify myfile Data Cell");
   *///modify data, must close file Copy1.write ();
    
  Copy1.close ();
  Copy2.write ();
    
  Copy2.close ();
  }catch (biffexception e) {//TODO auto-generated catch block E.printstacktrace ();
  }catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();
  }catch (WriteException e) {//TODO auto-generated catch block E.printstacktrace (); }
 
 }
  
}


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.