自己用的测试类
package importTest;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.CellFormat;
import jxl.read.biff.BiffException;
import jxl.write.DateFormat;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.NumberFormat;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.CellFormat;
import jxl.read.biff.BiffException;
import jxl.write.DateFormat;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.NumberFormat;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class ImportTestClass {
private static final CellFormat DateTime = null;
public void doImport() throws BiffException, IOException
{
String fileurl="D:\\book.xls";
Workbook workbook=Workbook.getWorkbook(new File(fileurl));
Sheet sheet=workbook.getSheet(0);
int t=workbook.getNumberOfSheets();
System.out.println("number of sheets ="+t);
for(int i=1;i<sheet.getRows();i++)
{
Cell nameCell=sheet.getCell(0, i);
String name=nameCell.getContents();
int row=nameCell.getRow();
System.out.println("name in row="+row);
System.out.println(name);
Cell birthdayCell=sheet.getCell(3,i);
if(birthdayCell.getType()==CellType.DATE)
{
DateCell datecell=(DateCell)birthdayCell;
Date birtyday=datecell.getDate();
System.out.println(birtyday);
}
}
workbook.close();
}
public void writeExcel() throws IOException, RowsExceededException, WriteException
{
//创建工作簿
WritableWorkbook wriworkbook=Workbook.createWorkbook(new File("D:\\writableWorkbool.xls"));
//新建工作表
WritableSheet sheet=wriworkbook.createSheet("new workbook", 0);
//单元格格式 日期格式
WritableCellFormat format=new WritableCellFormat(new DateFormat("yyyy/MM/dd"));
WritableCellFormat numformat=new WritableCellFormat(new NumberFormat("0.00"));
//添加单元格
sheet.addCell(new Label(0,0,"日期"));
sheet.addCell(new Label(1,0,"金额"));
sheet.addCell(new Label(1,1,"26"));
Label lable=new Label(0,1 , "2010/5/6");
sheet.addCell(lable);
wriworkbook.write();
wriworkbook.close();
}
public void updaeExcel() throws BiffException, IOException, WriteException
{
Workbook workbook=Workbook.getWorkbook(new File("D:\\writableWorkbool.xls"));
WritableWorkbook wri=Workbook.createWorkbook(new File("D:\\writableWorkbool.xls"), workbook);
WritableSheet sheet=wri.getSheet("new workbook");
Cell cell=sheet.getCell(0,0);
Label lable1=(Label)cell;
lable1.setString("come here ");
wri.write();
wri.close();
workbook.close();
}
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException {
ImportTestClass im=new ImportTestClass();
im.doImport();
im.writeExcel();
im.updaeExcel();
}
{
String fileurl="D:\\book.xls";
Workbook workbook=Workbook.getWorkbook(new File(fileurl));
Sheet sheet=workbook.getSheet(0);
int t=workbook.getNumberOfSheets();
System.out.println("number of sheets ="+t);
for(int i=1;i<sheet.getRows();i++)
{
Cell nameCell=sheet.getCell(0, i);
String name=nameCell.getContents();
int row=nameCell.getRow();
System.out.println("name in row="+row);
System.out.println(name);
Cell birthdayCell=sheet.getCell(3,i);
if(birthdayCell.getType()==CellType.DATE)
{
DateCell datecell=(DateCell)birthdayCell;
Date birtyday=datecell.getDate();
System.out.println(birtyday);
}
}
workbook.close();
}
public void writeExcel() throws IOException, RowsExceededException, WriteException
{
//创建工作簿
WritableWorkbook wriworkbook=Workbook.createWorkbook(new File("D:\\writableWorkbool.xls"));
//新建工作表
WritableSheet sheet=wriworkbook.createSheet("new workbook", 0);
//单元格格式 日期格式
WritableCellFormat format=new WritableCellFormat(new DateFormat("yyyy/MM/dd"));
WritableCellFormat numformat=new WritableCellFormat(new NumberFormat("0.00"));
//添加单元格
sheet.addCell(new Label(0,0,"日期"));
sheet.addCell(new Label(1,0,"金额"));
sheet.addCell(new Label(1,1,"26"));
Label lable=new Label(0,1 , "2010/5/6");
sheet.addCell(lable);
wriworkbook.write();
wriworkbook.close();
}
public void updaeExcel() throws BiffException, IOException, WriteException
{
Workbook workbook=Workbook.getWorkbook(new File("D:\\writableWorkbool.xls"));
WritableWorkbook wri=Workbook.createWorkbook(new File("D:\\writableWorkbool.xls"), workbook);
WritableSheet sheet=wri.getSheet("new workbook");
Cell cell=sheet.getCell(0,0);
Label lable1=(Label)cell;
lable1.setString("come here ");
wri.write();
wri.close();
workbook.close();
}
public static void main(String[] args) throws BiffException, IOException, RowsExceededException, WriteException {
ImportTestClass im=new ImportTestClass();
im.doImport();
im.writeExcel();
im.updaeExcel();
}
}