package com.jy.pjbj.web.action.util;
import java.io.File;
import java.util.List;
import javax.xml.rpc.ServiceException;
import com.jy.pjbj.dto.ptcsppjjg.PtCsPjDTO;
import com.jy.pjbj.entity.PjGgSjcjbXtjgdr;
import jxl.Workbook;
public class WriteExcel {
/**
* 根据文件路径和信息列表写系统价格Excel
* @param pathURL
* @param resultList
* @throws ServiceException
*/
public void writeXtjgExcel(String pathURL,List resultList)
throws ServiceException {
List list = resultList;
jxl.write.Label labelC = null;
jxl.write.WritableSheet ws = null;
jxl.write.WritableWorkbook wwb = null;
try {
wwb = Workbook.createWorkbook(new File(pathURL));
ws = wwb.createSheet("系统价格导出", 0);
// 第一行
labelC = new jxl.write.Label(0, 0, "零件名称");
ws.addCell(labelC);
labelC = new jxl.write.Label(1, 0, "精友零件编码");
ws.addCell(labelC);
labelC = new jxl.write.Label(2, 0, "原厂零件编号");
ws.addCell(labelC);
labelC = new jxl.write.Label(3, 0, "原厂零件名称");
ws.addCell(labelC);
labelC = new jxl.write.Label(4, 0, "厂方指导价格");
ws.addCell(labelC);
labelC = new jxl.write.Label(5, 0, "市场价格1");
ws.addCell(labelC);
labelC = new jxl.write.Label(6, 0, "市场价格2");
ws.addCell(labelC);
labelC = new jxl.write.Label(7, 0, "市场价格3");
ws.addCell(labelC);
labelC = new jxl.write.Label(8, 0, "市场价格4");
ws.addCell(labelC);
// 从resultList中循环写入数据
int i = 0;
for(i=0;i<list.size();i++){
PjGgSjcjbXtjgdr dto = (PjGgSjcjbXtjgdr)list.get(i);
labelC = new jxl.write.Label(0, i+1, dto.getLjmc());
ws.addCell(labelC);
labelC = new jxl.write.Label(1, i+1, dto.getLjbh());
ws.addCell(labelC);
labelC = new jxl.write.Label(2, i+1, dto.getYcljh());
ws.addCell(labelC);
labelC = new jxl.write.Label(3, i+1, dto.getYcljmc());
ws.addCell(labelC);
labelC = new jxl.write.Label(4, i+1, dto.getCfzdj().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(5, i+1, dto.getScjg1().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(6, i+1, dto.getScjg2().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(7, i+1, dto.getScjg3().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(8, i+1, dto.getScjg4().toString());
ws.addCell(labelC);
}
// 写入Excel表
wwb.write();
// 关闭可写入的Excel对象
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据文件路径和信息列表写区域价格Excel
* @param pathURL
* @param resultList
* @throws ServiceException
*/
public void writeQyjgExcel(String pathURL,List resultList)
throws ServiceException {
List list = resultList;
jxl.write.Label labelC = null;
jxl.write.WritableSheet ws = null;
jxl.write.WritableWorkbook wwb = null;
try {
wwb = Workbook.createWorkbook(new File(pathURL));
ws = wwb.createSheet("区域价格导出", 0);
// 第一行
labelC = new jxl.write.Label(0, 0, "零件名称");
ws.addCell(labelC);
labelC = new jxl.write.Label(1, 0, "精友零件编码");
ws.addCell(labelC);
labelC = new jxl.write.Label(2, 0, "原厂零件编号");
ws.addCell(labelC);
labelC = new jxl.write.Label(3, 0, "原厂零件名称");
ws.addCell(labelC);
labelC = new jxl.write.Label(4, 0, "原厂件市场价");
ws.addCell(labelC);
labelC = new jxl.write.Label(5, 0, "OEM价格");
ws.addCell(labelC);
labelC = new jxl.write.Label(6, 0, "适用价格");
ws.addCell(labelC);
// 从resultList中循环写入数据
int i = 0;
for(i=0;i<list.size();i++){
PjGgSjcjbXtjgdr dto = (PjGgSjcjbXtjgdr)list.get(i);
labelC = new jxl.write.Label(0, i+1, dto.getLjmc());
ws.addCell(labelC);
labelC = new jxl.write.Label(1, i+1, dto.getLjbh());
ws.addCell(labelC);
labelC = new jxl.write.Label(2, i+1, dto.getYcljh());
ws.addCell(labelC);
labelC = new jxl.write.Label(3, i+1, dto.getYcljmc());
ws.addCell(labelC);
labelC = new jxl.write.Label(4, i+1, dto.getScjg().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(5, i+1, dto.getOemjg().toString());
ws.addCell(labelC);
labelC = new jxl.write.Label(6, i+1, dto.getSyjg().toString());
ws.addCell(labelC);
}
// 写入Excel表
wwb.write();
// 关闭可写入的Excel对象
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 写配套配件Excel表
* @param pathURL
* @param resultList
* @throws ServiceException
*/
public void writePtPjExcel (String pathURL,List resultList)
throws ServiceException {
List list = resultList;
jxl.write.Label labelC = null;
jxl.write.WritableSheet ws = null;
jxl.write.WritableWorkbook wwb = null;
try {
wwb = Workbook.createWorkbook(new File(pathURL));
ws = wwb.createSheet("配套配件导出", 0);
// 第一行
labelC = new jxl.write.Label(0, 0, "品牌件编码");
ws.addCell(labelC);
labelC = new jxl.write.Label(1, 0, "原厂零件编码");
ws.addCell(labelC);
labelC = new jxl.write.Label(2, 0, "配件名称");
ws.addCell(labelC);
labelC = new jxl.write.Label(3, 0, "规格型号");
ws.addCell(labelC);
labelC = new jxl.write.Label(4, 0, "计量单位");
ws.addCell(labelC);
labelC = new jxl.write.Label(5, 0, "包装规格");
ws.addCell(labelC);
labelC = new jxl.write.Label(6, 0, "商品产地");
ws.addCell(labelC);
labelC = new jxl.write.Label(7, 0, "价格");
ws.addCell(labelC);
labelC = new jxl.write.Label(8, 0, "是否通用");
ws.addCell(labelC);
labelC = new jxl.write.Label(9, 0, "备注");
ws.addCell(labelC);
labelC = new jxl.write.Label(10, 0, "适用车型");
ws.addCell(labelC);
// 从resultList中循环写入数据
int i = 0;
for(i=0;i<list.size();i++){
PtCsPjDTO pjb = (PtCsPjDTO)list.get(i);
labelC = new jxl.write.Label(0, i+1, pjb.getPpjbm());
ws.addCell(labelC);
labelC = new jxl.write.Label(1, i+1, pjb.getYcljbm());
ws.addCell(labelC);
labelC = new jxl.write.Label(2, i+1, pjb.getPjmc());
ws.addCell(labelC);
labelC = new jxl.write.Label(3, i+1, pjb.getGgxh());
ws.addCell(labelC);
labelC = new jxl.write.Label(4, i+1, pjb.getJldw());
ws.addCell(labelC);
labelC = new jxl.write.Label(5, i+1, pjb.getBzgg());
ws.addCell(labelC);
labelC = new jxl.write.Label(6, i+1, pjb.getSpcd());
ws.addCell(labelC);
labelC = new jxl.write.Label(7, i+1, pjb.getJg()+"");
ws.addCell(labelC);
labelC = new jxl.write.Label(8, i+1, pjb.getSfty());
ws.addCell(labelC);
labelC = new jxl.write.Label(9, i+1, pjb.getBz());
ws.addCell(labelC);
labelC = new jxl.write.Label(10, i+1, pjb.getSycx());
ws.addCell(labelC);
}
// 写入Excel表
wwb.write();
// 关闭可写入的Excel对象
wwb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)