package com.excel.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import jxl.Cell;
import jxl.CellType;
import jxl.LabelCell;
import jxl.Sheet;
import jxl.Workbook;
public class ExcelOperater
{
public static void main(String[] args)
{
jxl.Workbook readwb = null;
try
{
//構建Workbook對象, 只讀Workbook對象
//直接從本地文件創建Workbook
InputStream instream = new FileInputStream("F:/tomcat7/webapps/Excel/upload/1.xls");
readwb = Workbook.getWorkbook(instream);
//Sheet的下標是從0開始
//獲取第一張Sheet表
Sheet readsheet = readwb.getSheet(0);
//獲得第一行第一列單元的值
Cell c00 = readsheet.getCell(1,1);
//通用的獲取cell值的方式,返回字符串
String strc00 = c00.getContents();
System.out.println("-----------------");
System.out.println(c00.getContents());
System.out.println("------------------");
//獲得cell具體類型值的方式
if(c00.getType() == CellType.LABEL)
{
LabelCell labelc00 = (LabelCell)c00;
strc00 = labelc00.getString();
}
//獲取Sheet表中所包含的總列數
int rsColumns = readsheet.getColumns();
//獲取Sheet表中所包含的總行數
int rsRows = readsheet.getRows();
//獲取指定單元格的對象引用
for (int i = 0; i < rsRows; i++)
{
for (int j = 0; j < rsColumns; j++)
{
Cell cell = readsheet.getCell(j, i);
System.out.print(cell.getContents() + " ");
}
System.out.println();
}
//利用已經創建的Excel工作薄,創建新的可寫入的Excel工作薄
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(new File(
"F:/tomcat7/webapps/Excel/upload/11.xls"), readwb);
//讀取第一張工作表
jxl.write.WritableSheet ws = wwb.getSheet(0);
//獲得第一個單元格對象
jxl.write.WritableCell wc = ws.getWritableCell(0, 0);
//寫入Excel對象
wwb.write();
wwb.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
readwb.close();
}
}
}
http://blog.csdn.net/xionglangs/article/details/50036553,基本復制這個就可以了,但是要注意這裡是通過數據查出了所有的數據,類的字段跟你的不太相同。