java excel 输出 急!!!!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java excel 输出 急!!!!!相关的知识,希望对你有一定的参考价值。
for(int i=0;i<GATE_List.size()-1;i++)
if(i% 2 == 0)
BigDecimal b1 = new BigDecimal(
(GATE_List.get(i).getFlightSpeed()+GATE_List.get(i+1).getFlightSpeed())/2);
double f1 = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
BigDecimal b2 = new BigDecimal((GATE_List.get(i).getFlightHeight()+GATE_List.get(i+1).getFlightHeight())/2);
double f2 = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
System.out.println(
// "GATE_List:"+
GATE_List.get(i).getFlight_ID()
+","+
GATE_List.get(i).getAC_Type()
+","+
f1
+","+
f2
);
以上我把数据装入在GATE_List里,它是ArrayList<GateDaten> GATE_List=new ArrayList<GateDaten>(), 里面分别是 flight ID,AC_Type,f1 是相对应一个flight ID 的飞机速度,f2 是高度。 我现在想输出到excel表格中
每一列的名称和上面名称相同 然后数据都自动在名称的下面。请高手指教!
String url="d:/sawen/";
//String url = "f:/openreport/";
try
WritableWorkbook wwb = Workbook.createWorkbook(new File(url
+ admin.getAdminname() + ".xls"));
wwb.setProtected(true);
// 创建Excel工作表
WritableSheet ws = wwb.createSheet(subject, 0);
SheetSettings ss = ws.getSettings();
ss.setLeftMargin(0.2);
ss.setRightMargin(0.2);
ss.setTopMargin(0.6);
ss.setBottomMargin(0.5);
ss.setHorizontalCentre(true);
// 题目列表
// 创建大字体:TAHOMA,大小为11号,粗体,非斜体
WritableFont wf = new WritableFont(WritableFont.TAHOMA, 11,
WritableFont.NO_BOLD, false);
// wcfF为正文格式:水平垂直居中
WritableCellFormat wcfF = new WritableCellFormat(wf);
// wcfFleftNoBorder为正文格式:水平居左 垂直居中 无表格
WritableCellFormat wcfFleftNoBorder = new WritableCellFormat(wf);
wcfFleftNoBorder.setWrap(true);
wcfFleftNoBorder.setAlignment(Alignment.LEFT);
wcfFleftNoBorder.setVerticalAlignment(VerticalAlignment.CENTRE);
// wcfF为正文格式:水平居左 垂直居中 带表格
WritableCellFormat wcfFleftWithBorder = new WritableCellFormat(wf);
wcfFleftWithBorder.setWrap(true);
wcfFleftWithBorder.setAlignment(Alignment.LEFT);
wcfFleftWithBorder.setVerticalAlignment(VerticalAlignment.CENTRE);
wcfFleftWithBorder.setBorder(jxl.format.Border.RIGHT,
BorderLineStyle.THIN);
wcfFleftWithBorder.setBorder(jxl.format.Border.LEFT,
BorderLineStyle.THIN);
wcfFleftWithBorder.setBorder(jxl.format.Border.BOTTOM,
BorderLineStyle.THIN);
wcfFleftWithBorder.setBorder(jxl.format.Border.TOP,
BorderLineStyle.THIN);
// titlewcfF为标题字体
WritableCellFormat titlewcfF = new WritableCellFormat(
new WritableFont(WritableFont.TAHOMA, 14,
WritableFont.BOLD, false));
// 标题水平居中
titlewcfF.setAlignment(Alignment.CENTRE);
// 标题垂直居中
titlewcfF.setVerticalAlignment(VerticalAlignment.CENTRE);
// 是否换行
wcfF.setWrap(true);
// 水平方向居中
wcfF.setAlignment(Alignment.CENTRE);
// 垂直方向举重
wcfF.setVerticalAlignment(VerticalAlignment.CENTRE);
// 设置顶部边框线为实线(默认是黑色--也可以设置其他颜色)
wcfF.setBorder(jxl.format.Border.TOP, BorderLineStyle.THIN);
// 设置右边框线为实线
wcfF.setBorder(jxl.format.Border.RIGHT, BorderLineStyle.THIN);
// 设置底部框线为实线
wcfF.setBorder(jxl.format.Border.BOTTOM, BorderLineStyle.THIN);
// 设置左边框线为实线
wcfF.setBorder(jxl.format.Border.LEFT, BorderLineStyle.THIN);
// 合并标题单元格
ws.mergeCells(0, 0, 11, 0);// 第一行的前8列
// 合并单位信息单元格
ws.mergeCells(0, 1, 11, 1);// 第二行的前8列
// 标题行的高度
ws.setRowView(0, 800);
ws.addCell(new Label(0, 0, subject, titlewcfF));
String tempstr = "制表人:"+admin.getRealname()+" 制表日期: "
+ new java.sql.Date(System.currentTimeMillis());
ws.addCell(new Label(0, 1, tempstr, wcfFleftNoBorder));
ws.setRowView(1, 400);
// 表头内容
ws.addCell(new Label(0, 2, "进厂日期", wcfF));
ws.setColumnView(0, 12);
ws.addCell(new Label(1, 2, "工件号", wcfF));
ws.setColumnView(1, 12);
ws.addCell(new Label(2, 2, "机型", wcfF));
ws.setColumnView(2, 20);
ws.addCell(new Label(3, 2, "船东", wcfF));
ws.setColumnView(3, 12);
ws.addCell(new Label(4, 2, "船名", wcfF));
ws.setColumnView(4, 12);
ws.addCell(new Label(5, 2, "工程内容", wcfF));
ws.setColumnView(5, 12);
ws.addCell(new Label(6, 2, "合同号", wcfF));
ws.setColumnView(6, 12);
ws.addCell(new Label(7, 2, "合同单价", wcfF));
ws.setColumnView(7, 10);
ws.addCell(new Label(8, 2, "合同手续", wcfF));
ws.setColumnView(8, 15);
ws.addCell(new Label(9, 2, "经手人", wcfF));
ws.setColumnView(9, 15);
ws.addCell(new Label(10, 2, "备注", wcfF));
ws.setColumnView(10, 15);
int i = 0;
for (; i < products.size(); i++)
Product p = (Product)products.get(i);
ws.addCell(new Label(0, i + 3, new Integer(i + 1).toString(),
wcfF));
ws.setColumnView(0, 5);
/*tempstr = svo.getTeacherid1().iterator().next().getName();
try
tempstr += "/"
+ svo.getTeacherid2().iterator().next().getName();
catch (RuntimeException e)
ws.addCell(new Label(1, i + 3, tempstr, wcfF));
ws.setColumnView(1, 15);
tempstr = svo.getTeacherid1().iterator().next().getTeachtitle();
try
tempstr += "/"
+ svo.getTeacherid2().iterator().next()
.getTeachtitle();
catch (Exception e)
*/
String isback="未回款";
Checks check = DAOFactory.getInstance().createProductDAO().getCheckByProduct(p.getId());
if(check==null) ;
else isback=check.getMaketime();
if(p.getContact().getIsback()==null) ;
else isback=p.getContact().getIsback();
ws.addCell(new Label(0, i + 3, p.getGettime(), wcfF));
ws.setColumnView(0, 12);
ws.addCell(new Label(1, i + 3, p.getProductid(), wcfF));
ws.setColumnView(1, 12);
ws.addCell(new Label(2, i + 3,p.getModel().getModelname()
, wcfFleftWithBorder));
ws.setColumnView(2, 20);
ws.addCell(new Label(3, i + 3, p.getCustomer().getCompanyname(), wcfF));
ws.setColumnView(3, 12);
ws.addCell(new Label(4, i + 3, p.getShip().getShipname(), wcfF));
ws.setColumnView(4, 12);
ws.addCell(new Label(5, i + 3, p.getRepairkind().getRepairname(), wcfF));
ws.setColumnView(5, 12);
ws.addCell(new Label(6, i + 3, ""+p.getContact().getContactid(), wcfF));
ws.setColumnView(6, 12);
ws.addCell(new Label(7, i + 3, ""+p.getPrice(), wcfF));
ws.setColumnView(7, 10);
ws.addCell(new Label(8,i + 3, isback, wcfF));
ws.setColumnView(8, 15);
ws.addCell(new Label(9, i + 3, p.getProducer().getRealname(), wcfF));
ws.setColumnView(9, 15);
ws.addCell(new Label(10, i + 3, p.getDescription(), wcfF));
ws.setColumnView(10, 15);
ws.mergeCells(0, i + 3, 11, i + 3);// 第二行的前9列
ws
.addCell(new Label(
0,
i + 3,
"",
wcfFleftNoBorder));
ws.setRowView(i + 3, 800);
wwb.write();
wwb.close();
return true;
catch (IOException e)
// Debug.writeDebug("ScoreDAO:createXls():" + e.getMessage());
return false;
catch (RowsExceededException e)
//Debug.writeDebug("ScoreDAO:createXls():" + e.getMessage());
return false;
catch (WriteException e)
//Debug.writeDebug("ScoreDAO:createXls():" + e.getMessage());
return false;
我这是在项目中应用的,数据格式稍微不同,但是这个程序肯定是正确的,你可以参考。。。。 参考技术A jxl.jar 自己找资料
以上是关于java excel 输出 急!!!!!的主要内容,如果未能解决你的问题,请参考以下文章
急!!!!!java System.out.println()输出规则!!!!!
java问题 输入20个10以内的正整数,输出每个数字出现的次数。急!!!