public class Download {spa
/**
* 将数据导出到Excel
*
* @param SaleslipDetail
* 销货单明细数据
* @return
* @throws Throwable
*/
@Bizlet()
public static int exportSaleSlip(DataObject[] SaleSlip) {.net
try {
DataObject dataObject0 = null, dataObject1=null;
ApplicationContext context = ApplicationContext.getInstance();
TododFile tododFile = new TododFile();
String uploadpath = context.getWarRealPath() + "\\upload"; // context.getRealPath("/upload");
File logFile = tododFile.createFile(uploadpath + "\\",
"SaleSlipDetail.xls");
ExcelWriter excelWriter = new ExcelWriter();
excelWriter = new ExcelWriter(new FileOutputStream(logFile));
/*标题*/
excelWriter.createRow(0); //建立一行
excelWriter.mergeCell(0, (short) 0, 0, (short) 11);
excelWriter.setFundTitleCell((short) 0, "中交天津工贸有限公司销货单");
dataObject1 = SaleSlip[0];
/*合同号 日期*/
excelWriter.createRow(1);
excelWriter.setCell((short) 0, "合同号");
excelWriter.mergeCell(1, (short) 1, 1, (short) 2);
excelWriter.setCell((short) 1,
dataObject1.getString("contractNum"));
excelWriter.setCell((short) 2, "");
excelWriter.setCell((short) 9, "日期");
excelWriter.mergeCell(1, (short)10, 1,(short) 11);
excelWriter.setCell((short) 10,
dataObject1.getString("orderDate"));
excelWriter.setCell((short) 11, "");
excelWriter.createRow(2);
excelWriter.setCell((short) 0, "客户:");
excelWriter.mergeCell(2, (short) 1, 2, (short) 4);
excelWriter.setCell((short) 1,
dataObject1.getString("shortName"));
excelWriter.setCell((short) 2, "");
excelWriter.setCell((short) 3, "");
excelWriter.setCell((short) 4, "");
excel
excelWriter.createRow(3);
excelWriter.setGreyCell((short) 0, "序号");
excelWriter.setGreyCell((short) 1, "名称");
excelWriter.setGreyCell((short) 2, "规格");
excelWriter.setGreyCell((short) 3, "单位");
excelWriter.setGreyCell((short) 4, "数量");
excelWriter.setGreyCell((short) 5, "不含税单价");
excelWriter.setGreyCell((short) 6, "不含税金额");
excelWriter.setGreyCell((short) 7, "税额");
excelWriter.setGreyCell((short) 8, "含税单价");
excelWriter.setGreyCell((short) 9, "含税金额");
excelWriter.setGreyCell((short) 10, "已销货数量");
excelWriter.setGreyCell((short) 11, "已销货金额");ip
for (int i = 0; i < SaleSlip.length; i++) {
dataObject0 = SaleSlip[i];
excelWriter.createRow(i+4);
excelWriter.setBorderCell((short) 0,
dataObject0.getString("materialCode"));
excelWriter.setBorderCell((short) 1,
dataObject0.getString("materialName"));
excelWriter.setBorderCell((short) 2, dataObject0.getString("spec"));
excelWriter.setBorderCell((short) 3, dataObject0.getString("dictname"));
excelWriter.setBorderCell((short) 4,
dataObject0.getString("quantity"));
excelWriter.setBorderCell((short) 5, dataObject0.getString("noPrice"));
excelWriter.setBorderCell((short) 6,
dataObject0.getString("noAmount"));
excelWriter.setBorderCell((short) 7,
dataObject0.getString("tax"));
excelWriter.setBorderCell((short) 8,
dataObject0.getString("price"));
excelWriter.setBorderCell((short) 9,
dataObject0.getString("amount"));
excelWriter.setBorderCell((short) 10,
dataObject0.getString("salesNum"));
excelWriter.setBorderCell((short) 11,
dataObject0.getString("amount"));
}
/*结尾合计1*/
int a= SaleSlip.length+4;
excelWriter.createRow(a);
excelWriter.mergeCell(a, (short) 0, a, (short) 1);
excelWriter.setBorderCell((short) 0,"合计:");
excelWriter.setBorderCell((short) 1, "");
excelWriter.setBorderCell((short) 2, "");
excelWriter.setBorderCell((short) 3, "");
excelWriter.setBorderCell((short) 4, "");
excelWriter.setBorderCell((short) 5, "");
excelWriter.setBorderCell((short) 6, "");
excelWriter.setBorderCell((short) 7, "");
excelWriter.setBorderCell((short) 8, "");
excelWriter.setBorderCell((short) 9, "");
excelWriter.setBorderCell((short) 10, "");
excelWriter.setBorderCell((short) 11, "");
/*大写合计*/
excelWriter.createRow(a+1);
excelWriter.mergeCell(a+1, (short) 1, a+1, (short) 11);
excelWriter.setBorderCell((short)0, "大写合计:");
for(int i=1;i<12;i++){
excelWriter.setBorderCell((short) i,"");
}
/*备注*/
excelWriter.createRow(a+2);
excelWriter.mergeCell(a+2, (short) 1, a+2, (short) 11);
excelWriter.setBorderCell((short)0, "备注:");
for(int i=1;i<12;i++){
excelWriter.setBorderCell((short) i,"");
}
excelWriter.createRow(a+3);
excelWriter.setCell((short) 0, "审核人:");
excelWriter.setCell((short) 9, "经办人:");
excelWriter.export();
} catch (Exception e) {get
e.printStackTrace();it
}
return 0;
}
}io