|
@@ -0,0 +1,109 @@
|
|
|
+package com.huimv.farm.test;
|
|
|
+
|
|
|
+import com.huimv.farm.damsubsidy.entity.BillSubsidy;
|
|
|
+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.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class Print2 {
|
|
|
+ /**
|
|
|
+ * 打印方法 不插入图片
|
|
|
+ * @throws Exception
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static void print(List<BillSubsidy> subsidies) throws Exception {
|
|
|
+ //准备数据
|
|
|
+ String path ="G://mount.xls";
|
|
|
+ //获取模板文件,你自己当前模板的位置 我这里为当前项目下
|
|
|
+ //如果为系统路径 为: InputStream is = new FileInputStream("F://student.xlsx");
|
|
|
+ InputStream is = new FileInputStream("G://amount.xlsx");
|
|
|
+// InputStream is = Print.class.getClassLoader().getResourceAsStream("student.xlsx");
|
|
|
+// InputStream is = Print.class.getClassLoader().getResourceAsStream("order_contract.xls");
|
|
|
+ //根据模板生成的文件保存路径 我这里保存在本地D盘
|
|
|
+ OutputStream os = new FileOutputStream(path);
|
|
|
+ //绑定数据
|
|
|
+ List<BillSubsidy> list = new ArrayList<>();
|
|
|
+ Context context = new Context();
|
|
|
+ //涉及太多只写了一个单独的
|
|
|
+ for (int i = 0; i < subsidies.size(); i++) {
|
|
|
+ BillSubsidyVo subsidyVo = new BillSubsidyVo();
|
|
|
+ subsidyVo.setId(i);
|
|
|
+ subsidyVo.setName(subsidies.get(i).getBriefAddress());
|
|
|
+ if (subsidies.get(i).getFarmerType()==0) {
|
|
|
+ subsidyVo.setType1("1");
|
|
|
+ } else if (subsidies.get(i).getFarmerType()==1) {
|
|
|
+ subsidyVo.setType2("2");
|
|
|
+ } else {
|
|
|
+ subsidyVo.setType3("2");
|
|
|
+ }
|
|
|
+ if (subsidies.get(i).getRewardType() == 0) {
|
|
|
+
|
|
|
+
|
|
|
+ subsidyVo.setNumber(subsidies.get(i).getRewardNum());
|
|
|
+
|
|
|
+ } else if (subsidies.get(i).getRewardType() == 1) {
|
|
|
+
|
|
|
+ } else if (subsidies.get(i).getRewardType() == 2) {
|
|
|
+
|
|
|
+ } else if (subsidies.get(i).getRewardType() == 3){
|
|
|
+
|
|
|
+ } else if (subsidies.get(i).getRewardType() == 4) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+// context.putVar("orderTime", new Date());
|
|
|
+
|
|
|
+ //生成
|
|
|
+ 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();
|
|
|
+// }
|
|
|
+
|
|
|
+}
|