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