-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXCELObject.java
More file actions
274 lines (218 loc) · 6.5 KB
/
EXCELObject.java
File metadata and controls
274 lines (218 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package com.sunnada.edu.system.pub.common;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sunnada.edu.system.pub.common.EXCELTools.Elements;
import com.sunnada.edu.system.pub.common.EXCELTools.Rule;
/**
*
* @author thinkpad
*
*/
public class EXCELObject {
private String fname;
private String title;
private String[] pTit;
private String[] cols;
private String[] titH;
private String[] titN;
private String[] width;
private String[] widthP;
// 元素
private Elements[] e;
private Integer startRow;
private Integer endColumn;
private String iFilePath;//读取文件的路径
private String eFilePath;//导出文件的路径
private boolean isCheck;
private List<Map<String, String>> dataList;
private Integer pageSize;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String[] getWidthP() {
return widthP;
}
public void setWidthP(String[] widthP) {
this.widthP = widthP;
}
public String[] getWidth() {
return width;
}
public void setWidth(String[] width) {
this.width = width;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public List<Map<String, String>> getDataList() {
return dataList;
}
public void setDataList(List<Map<String, String>> dataList) {
this.dataList = dataList;
}
public Integer getStartRow() {
return startRow;
}
public void setStartRow(Integer startRow) {
startRow = startRow - 1;
this.startRow = startRow;
}
public Integer getEndColumn() {
return endColumn;
}
public void setEndColumn(Integer endColumn) {
this.endColumn = endColumn;
}
public String getiFilePath() {
return iFilePath;
}
public void setiFilePath(String iFilePath) {
this.iFilePath = iFilePath;
}
public String geteFilePath() {
return eFilePath;
}
public void seteFilePath(String eFilePath) {
this.eFilePath = eFilePath;
}
public boolean isCheck() {
return isCheck;
}
public void setCheck(boolean isCheck) {
this.isCheck = isCheck;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String[] getpTit() {
return pTit;
}
public void setpTit(String[] pTit) {
this.pTit = pTit;
}
public String[] getCols() {
return cols;
}
public void setCols(String[] cols) {
this.cols = cols;
}
public String[] getTitH() {
return titH;
}
public void setTitH(String[] titH) {
this.titH = titH;
}
public String[] getTitN() {
return titN;
}
public void setTitN(String[] titN) {
this.titN = titN;
}
public Elements[] getE() {
return e;
}
public void setE(Elements[] e) {
this.e = e;
}
public Elements getElementsClass() {
return EXCELTools.getInstance().getElementsInstance();
}
public Rule getRuleInstance() {
return EXCELTools.getInstance().getRuleInstance();
}
public Map<String, Object> getData() {
File file = new File(iFilePath);
EXCELTools tools = new EXCELTools();
if (isCheck != true) {
e = new Elements[8];
for (int i = 0; i < 8; i++) {
e[i] = getElementsClass();
}
}
return (Map<String, Object>) tools.getData(file, startRow, endColumn,
e, isCheck);
}
public File setData() throws Exception {
if (pageSize == null) {
return EXCELTools.xlsWrite(eFilePath, fname,title, pTit, cols, titH,
titN, dataList,width,widthP);
} else {
return EXCELTools.xlsWritePage(eFilePath, fname,title, pTit, cols, titH,
titN, dataList, pageSize,width,widthP);
}
}
public File modelSetData() throws Exception {
if (pageSize == null) {
return EXCELTools.modelXlsWrite(eFilePath, fname,title, pTit, cols, titH,
titN, dataList,width,widthP);
} else {
return EXCELTools.modelXlsWritePage(eFilePath, fname,title, pTit, cols, titH,
titN, dataList, pageSize,width,widthP);
}
}
public File weixinsetData() throws Exception {
if (pageSize == null) {
return EXCELTools.weixinxlsWrite(eFilePath, fname,title, pTit, cols, titH,
titN, dataList,width,widthP);
} else {
return EXCELTools.weixinxlsWritePage(eFilePath, fname,title, pTit, cols, titH,
titN, dataList, pageSize,width,widthP);
}
}
public void exportExcel(String moderName,String excelName,File exportFile,HttpServletRequest request ,HttpServletResponse response) {
FileInputStream fs = null;
try {
fs = new FileInputStream(exportFile);
} catch (FileNotFoundException e) {
//LogInfo.getInstance().info(request,LogController.class,"["+moderName+"][生成excel错误! 日志管理 不存在!]["+e+"]");
return;
}
//这个一定要设定,告诉浏览器这次请求是一个下载的数据流
response.setContentType("APPLICATION/OCTET-STREAM");
// String excelName="日志管理.xls";
try {
excelName = new String(excelName.getBytes("gb2312"), "iso-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + excelName + "\"");//这里设置一下让浏览
response.addHeader("Content-Length", "" + exportFile.length());
// response.setHeader("Content-Disposition", "attachment; filename=" + "中文文件名".getBytes("GBK"), "ISO-8859-1") + ".xls");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
//LogInfo.getInstance().info(request,LogController.class,"["+moderName+"][Excel文件名称编码报错!]");
e1.printStackTrace();
}
// 写出流信息
int b = 0;
try {
//这里的 response 就是你 servlet 的那个传参进来的 response
PrintWriter out = response.getWriter();
while ((b = fs.read()) != -1) {
out.write(b);
}
fs.close();
out.close();
// LogInfo.getInstance().info(request,LogController.class,"["+moderName+"][下载完毕]");
} catch (Exception e) {
//LogInfo.getInstance().info(request,LogController.class,"["+moderName+"][下载文件失败!]["+e+"]");
}
// LogInfo.getInstance().info(request,LogController.class,"["+moderName+"][导出excel操作结束]");
if(exportFile.exists()) {
exportFile.delete();
}
}
}