Commit adb62261de9895751302b205de5d816fead1c62c

Authored by liquanyu
1 parent 602c20f1ab

excl

Showing 1 changed file with 57 additions and 40 deletions

platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java View file @ adb6226
... ... @@ -7,6 +7,7 @@
7 7  
8 8  
9 9 import jxl.Cell;
  10 +import jxl.Range;
10 11 import jxl.Sheet;
11 12 import jxl.Workbook;
12 13 import jxl.format.*;
13 14  
... ... @@ -244,9 +245,8 @@
244 245 wb = Workbook.getWorkbook(file);
245 246 WritableWorkbook book = wb.createWorkbook(file, wb);
246 247 WritableSheet ws = book.getSheet(0);
  248 + List<Integer> columNames = new ArrayList<>();
247 249  
248   - List<Integer> columNames = new ArrayList<>();
249   -
250 250 for (int i = 0, len = 37; i < len; i++)
251 251 {
252 252 columNames.add(i);
253 253  
254 254  
255 255  
256 256  
257 257  
258 258  
259 259  
260 260  
... ... @@ -255,65 +255,82 @@
255 255 WritableFont contentFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
256 256 WritableCellFormat contentFormt = new WritableCellFormat(contentFont);
257 257 contentFormt.setAlignment(jxl.format.Alignment.CENTRE);
  258 + contentFormt.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
258 259 contentFormt.setVerticalAlignment(VerticalAlignment.CENTRE);
259 260  
260 261 WritableFont leftFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
261 262 WritableCellFormat leftFormt = new WritableCellFormat(leftFont);
  263 + leftFormt.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
262 264 leftFormt.setAlignment(Alignment.LEFT);
263 265 leftFormt.setVerticalAlignment(VerticalAlignment.CENTRE);
264 266  
265 267  
266   -
267   -
268   -
269 268 WritableFont title = new WritableFont(WritableFont.ARIAL, 18, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
270 269 WritableCellFormat titleFormt = new WritableCellFormat(title);
  270 + titleFormt.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
271 271 titleFormt.setAlignment(jxl.format.Alignment.CENTRE);
272 272 titleFormt.setVerticalAlignment(VerticalAlignment.CENTRE);
273 273  
  274 +
  275 + ws.insertColumn(26);
  276 + ws.insertColumn(27);
  277 + ws.insertColumn(28);
  278 +
  279 + ws.mergeCells(26, 3, 29, 3);
  280 + ws.addCell(new Label(26, 3, "本市户籍", contentFormt));
  281 +
  282 + ws.addCell(new Label(26, 4, "区1", contentFormt));
  283 + ws.addCell(new Label(27, 4, "区2", contentFormt));
  284 + ws.addCell(new Label(28, 4, "区3", contentFormt));
  285 + ws.addCell(new Label(29, 4, "区4", contentFormt));
  286 +
274 287 for (int i = 0; i < ws.getRows() ; i++) {
275 288 for (int j = 0; j < ws.getColumns(); j++) {
276   - if(i == 0 && j == 0){
277   - Label label = new Label(j, i, "四川省成都市统计",titleFormt);
278   - ws.addCell(label);
279   - }
280 289  
281   - if(i == 1 && j == 0){
282   - Label label = new Label(j, i, "成都市",leftFormt);
283   - ws.addCell(label);
284   - }
  290 + Cell cell = ws.getCell(i, j);
  291 + System.out.println(i + "==" + j + " " +cell.getContents());
285 292  
286   - if(i == 1 && j == 19){
287   - Label label = new Label(j, i, "2018-08-20",leftFormt);
288   - ws.addCell(label);
289   - }
  293 +// if(i == 0 && j == 0){
  294 +// Label label = new Label(j, i, "四川省成都市统计",titleFormt);
  295 +// ws.addCell(label);
  296 +// }
  297 +//
  298 +// if(i == 1 && j == 0){
  299 +// Label label = new Label(j, i, "成都市",leftFormt);
  300 +// ws.addCell(label);
  301 +// }
  302 +//
  303 +// if(i == 1 && j == 19){
  304 +// Label label = new Label(j, i, "2018-08-20",leftFormt);
  305 +// ws.addCell(label);
  306 +// }
290 307 }
291 308 }
292 309  
293 310  
294   - for (int i = 5, len = 30; i < len; i++)
295   - {
296   - for (int j = 0; j < columNames.size() ; j++)
297   - {
298   - WritableCellFormat wcfN = new WritableCellFormat(contentFont);
299   - wcfN.setAlignment(jxl.format.Alignment.CENTRE);
300   - wcfN.setVerticalAlignment(VerticalAlignment.CENTRE);
301   - Number labelNF = new Number(j, i,j, wcfN);
302   - ws.addCell(labelNF);
303   - }
304   -
305   - }
306   -
307   - ws.addCell(new Label(0, 30, "注:统计时限:上月26日至本月25日;分娩方式中其他包括:吸引产、臀助产、臀牵引、产钳产等。", leftFormt));
308   -
309   - ws.mergeCells(0, 30, 36, 30);
310   -
311   - ws.addCell(new Label(0, 31, "填报单位:", leftFormt));
312   - ws.mergeCells(0, 31, 5, 31);
313   - ws.addCell(new Label(6, 31, "填报人:", leftFormt));
314   - ws.mergeCells(6, 31, 10, 31);
315   - ws.addCell(new Label(11, 31, "填报日期:", leftFormt));
316   - ws.mergeCells(11, 31,36, 31);
  311 +// for (int i = 5, len = 30; i < len; i++)
  312 +// {
  313 +// for (int j = 0; j < columNames.size() ; j++)
  314 +// {
  315 +// WritableCellFormat wcfN = new WritableCellFormat(contentFont);
  316 +// wcfN.setAlignment(jxl.format.Alignment.CENTRE);
  317 +// wcfN.setVerticalAlignment(VerticalAlignment.CENTRE);
  318 +// Number labelNF = new Number(j, i,j, wcfN);
  319 +// ws.addCell(labelNF);
  320 +// }
  321 +//
  322 +// }
  323 +//
  324 +// ws.addCell(new Label(0, 30, "注:统计时限:上月26日至本月25日;分娩方式中其他包括:吸引产、臀助产、臀牵引、产钳产等。", leftFormt));
  325 +//
  326 +// ws.mergeCells(0, 30, 36, 30);
  327 +//
  328 +// ws.addCell(new Label(0, 31, "填报单位:", leftFormt));
  329 +// ws.mergeCells(0, 31, 5, 31);
  330 +// ws.addCell(new Label(6, 31, "填报人:", leftFormt));
  331 +// ws.mergeCells(6, 31, 10, 31);
  332 +// ws.addCell(new Label(11, 31, "填报日期:", leftFormt));
  333 +// ws.mergeCells(11, 31,36, 31);
317 334  
318 335 book.write();
319 336 book.close();