java与Excel (3)

利用java excel api 修改一个excel文件。

package modifyexcel;
import java.io.File;
import java.io.IOException;

import jxl.*;
import jxl.read.biff.BiffException;
import jxl.write.*;

public class Modifyexcel {

 public static void main(String[] args) throws BiffException, IOException, WriteException {
  Workbook srcxls = Workbook.getWorkbook(new File("E:\\java-SRC\\ExcelAPILearning\\myfile.xls"));
  WritableWorkbook copy = Workbook.createWorkbook(new File("E:\\java-SRC\\ExcelAPILearning\\output.xls"),srcxls);
  WritableSheet sheet1 = copy.getSheet(0);
  WritableCell cell1 = sheet1.getWritableCell(0,0);
  if (cell1.getContents().length()==0){
   Label labelcell = (Label) cell1;
   labelcell.setString("haha");
  }
  Label label = new Label(0,3,"xixi");
  sheet1.addCell(label);
  copy.write();
  copy.close();
 }
}

你可能感兴趣的:(Excel)