FileInputStream fi = new FileInputStream(路径);
HSSFWorkbook wb = new HSSFWorkbook(fi);
HSSFSheet sheet = wb.getSheetAt(0);
int rowNum = sheet.getLastRowNum()+1; //行
T_BCity city=new T_BCity();
for(int i=1;i<rowNum;i++){
HSSFRow row = sheet.getRow(i);
int cellNum = row.getLastCellNum(); //列
for(short j=0;j<cellNum;j++){
HSSFCell cell = row.getCell(j);
//里面怎么写啊?
//循环取出excel里的值,放入city中
//
}
}
roleList.add(city);
HSSFWorkbook wb = new HSSFWorkbook(fi);
HSSFSheet sheet = wb.getSheetAt(0);
int rowNum = sheet.getLastRowNum()+1; //行
T_BCity city=new T_BCity();
for(int i=1;i<rowNum;i++){
HSSFRow row = sheet.getRow(i);
int cellNum = row.getLastCellNum(); //列
for(short j=0;j<cellNum;j++){
HSSFCell cell = row.getCell(j);
//里面怎么写啊?
//循环取出excel里的值,放入city中
//
}
}
roleList.add(city);
-------------------------------------------------------
/**
* 输出成excel附档。
* @param response HttpServletResponse类型
* @param slipNo 单号。
*/
public void outExcel(HttpServletResponse response,String slipNo)
{
String fileName = slipNo+"-"+Udate.getDate("yyyyMMddHHmmss")+".xls";
String ext = Ufile.getExt(fileName);
response.setContentType(ctype.getContentType(ext));
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
ServletOutputStream output = null;
try {
output = response.getOutputStream();
if(output==null)
return;
WritableWorkbook book = Workbook.createWorkbook(output);
//生成名为“第一页”的工作表,参数0表示这是第一页
WritableSheet sheet = book.createSheet( " 第一页 " , 0 );
this.addString(sheet,"公司",0,0);
this.addString(sheet,"总配料单",1,0);
this.addString(sheet,"订购单号",2,0);
this.addString(sheet,"品名",3,0);
this.addString(sheet,"单价",4,0);
this.addString(sheet,"币别",5,0);
this.addString(sheet,"数量",6,0);
this.addString(sheet,"订单交期",7,0);
this.addString(sheet,"订购日期",8,0);
this.addString(sheet,"订购人",9,0);
Cec220 cec220 = new Cec220();
List list = cec220.listBySlipNo(slipNo);
if(list!=null)
if(list.size()>0)
for(int i=0;i<list.size();i++)
{
Ec220 obj = (Ec220)list.get(i);
this.addString(sheet,obj.getFactory_name(),0,i+1);
this.addString(sheet,obj.getEc220_sum_no(),1,i+1);
this.addString(sheet,obj.getEc220_pur_no(),2,i+1);
this.addString(sheet,obj.getMtr_name(),3,i+1);
this.addString(sheet,obj.getEc220_price(),4,i+1);
this.addString(sheet,obj.getEc220_currency(),5,i+1);
this.addString(sheet,obj.getEc220_qty(),6,i+1);
this.addString(sheet,obj.getDate_to(),7,i+1);
this.addString(sheet,obj.getPur_date(),8,i+1);
this.addString(sheet,obj.getEc220_linkman(),9,i+1);
}
// 写入数据并关闭文件
book.write();
book.close();
} catch (IOException e) {
return;
}catch(WriteException e){
return;
}finally{
try {
if(output!=null)
output.close();
} catch (IOException e) {
//e.printStackTrace();
}
}
}public void addString(WritableSheet sheet,String str,int x,int y)
{
if(sheet!=null && Ustring.getNotNull(str))
{
Label label = new Label( x , y , str);
try {
sheet.addCell(label);
} catch (RowsExceededException e) {
//e.printStackTrace();
} catch (WriteException e) {
//e.printStackTrace();
}
}
}