|
@@ -0,0 +1,108 @@
|
|
|
+package com.huimv.farm.test;
|
|
|
+
|
|
|
+import com.huimv.farm.damsubsidy.entity.BillSubsidy;
|
|
|
+import com.huimv.farm.damsubsidy.entity.vo.BillSubsidyPayVo;
|
|
|
+import com.huimv.farm.damsubsidy.entity.vo.BillSubsidyReportVo;
|
|
|
+import com.huimv.farm.damsubsidy.entity.vo.BillSubsidyVo;
|
|
|
+import org.jxls.common.Context;
|
|
|
+import org.jxls.util.JxlsHelper;
|
|
|
+
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class Print3 {
|
|
|
+ /**
|
|
|
+ * 打印方法 不插入图片
|
|
|
+ * @throws Exception
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static void print(List<BillSubsidy> subsidies, String address, String date) throws Exception {
|
|
|
+ //准备数据
|
|
|
+ String path ="/opt/subsidy/pay.xls";
|
|
|
+ //获取模板文件,你自己当前模板的位置 我这里为当前项目下
|
|
|
+ //如果为系统路径 为: InputStream is = new FileInputStream("F://student.xlsx");
|
|
|
+ InputStream is = new FileInputStream("/opt/subsidy/pay.xlsx");
|
|
|
+
|
|
|
+ //根据模板生成的文件保存路径 我这里保存在本地D盘
|
|
|
+ OutputStream os = new FileOutputStream(path);
|
|
|
+ //绑定数据
|
|
|
+ List<BillSubsidyPayVo> list = new ArrayList<>();
|
|
|
+ Context context = new Context();
|
|
|
+ BigDecimal money = BigDecimal.valueOf(0);//奖补奖金
|
|
|
+ Integer number = 0;//新引进数量
|
|
|
+ Integer i = 1;
|
|
|
+ for (BillSubsidy subsidy : subsidies) {
|
|
|
+ BillSubsidyPayVo payVo = new BillSubsidyPayVo();
|
|
|
+ payVo.setId(i);
|
|
|
+ payVo.setCountry(subsidy.getBriefAddress());
|
|
|
+ payVo.setUserName(subsidy.getFarmerName());
|
|
|
+ payVo.setIdCard(subsidy.getIdCard());
|
|
|
+ payVo.setBankName(subsidy.getBankName());
|
|
|
+ payVo.setBankCard(subsidy.getBankCardId());
|
|
|
+ payVo.setFarmType(subsidy.getFarmerType());
|
|
|
+ payVo.setNumber(subsidy.getRewardNum());
|
|
|
+ payVo.setMoney(subsidy.getApplyMoney());
|
|
|
+ payVo.setPhone(subsidy.getPhone());
|
|
|
+ payVo.setSaleName(subsidy.getSaleName());
|
|
|
+ number = number + subsidy.getRewardNum();
|
|
|
+ money = money.add(subsidy.getApplyMoney());
|
|
|
+ list.add(payVo);
|
|
|
+ i = i + 1;
|
|
|
+ }
|
|
|
+ context.putVar("list", list);
|
|
|
+ context.putVar("address", address);
|
|
|
+ context.putVar("date", date);
|
|
|
+ context.putVar("numCount", number);
|
|
|
+ context.putVar("moneyCount", money);
|
|
|
+
|
|
|
+
|
|
|
+ //生成
|
|
|
+ JxlsHelper.getInstance().processTemplate(is, os, context);
|
|
|
+// String path = String.valueOf(os);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 打印方法 不插入图片
|
|
|
+// *
|
|
|
+// * 模板文件为student1.xlsx
|
|
|
+// * 注意事项:模板文件新加入了一行,所以整体范围也就有所改变,大家注意一下批注中的结束范围
|
|
|
+// * 图片所占用的范围为B2到C2
|
|
|
+// *
|
|
|
+// *
|
|
|
+// * @throws Exception
|
|
|
+// */
|
|
|
+// public static void print1() throws Exception {
|
|
|
+// //准备数据
|
|
|
+//
|
|
|
+// //获取模板文件,你自己当前模板的位置 我这里为当前项目下
|
|
|
+// //如果为系统路径 为: InputStream is = new FileInputStream("F://student.xlsx");
|
|
|
+// InputStream is = Print.class.getClassLoader().getResourceAsStream("student1.xlsx");
|
|
|
+// //根据模板生成的文件保存路径 我这里保存在本地D盘
|
|
|
+// OutputStream os = new FileOutputStream("D://student1.xlsx");
|
|
|
+//
|
|
|
+// //图片路径
|
|
|
+// InputStream imageInputStream =Print.class.getClassLoader().getResourceAsStream("a.png");
|
|
|
+// //转为字节码,插入的图片只能是字节码格式
|
|
|
+// byte[] imageBytes = Util.toByteArray(imageInputStream);
|
|
|
+// //绑定数据
|
|
|
+// Context context = new Context();
|
|
|
+// context.putVar("imageBytes", imageBytes);
|
|
|
+// context.putVar("title", "学上统计表");
|
|
|
+//// context.putVar("list", list);
|
|
|
+// //生成
|
|
|
+// JxlsHelper.getInstance().processTemplate(is, os, context);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static void main(String[] args) throws Exception {
|
|
|
+// print();
|
|
|
+//// print1();
|
|
|
+// }
|
|
|
+
|
|
|
+}
|