diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java index de6f483..e6966a8 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java @@ -9,15 +9,13 @@ import java.util.*; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; +import jxl.format.*; +import jxl.format.Alignment; import jxl.format.Colour; -import jxl.format.UnderlineStyle; +import jxl.format.VerticalAlignment; import jxl.read.biff.BiffException; -import jxl.write.Label; -import jxl.write.WritableCellFormat; -import jxl.write.WritableFont; -import jxl.write.WritableSheet; -import jxl.write.WritableWorkbook; -import jxl.write.WriteException; +import jxl.write.*; +import jxl.write.Number; import jxl.write.biff.RowsExceededException; /** @@ -237,8 +235,98 @@ public class ExcelUtil } + + public static void readExclFile(String filePath) + { + File file = new File(filePath); + Workbook wb = null; + try { + wb = Workbook.getWorkbook(file); + WritableWorkbook book = wb.createWorkbook(file, wb); + WritableSheet ws = book.getSheet(0); + + List columNames = new ArrayList<>(); + + for (int i = 0, len = 37; i < len; i++) + { + columNames.add(i); + } + + WritableFont contentFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); + WritableCellFormat contentFormt = new WritableCellFormat(contentFont); + contentFormt.setAlignment(jxl.format.Alignment.CENTRE); + contentFormt.setVerticalAlignment(VerticalAlignment.CENTRE); + + WritableFont leftFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); + WritableCellFormat leftFormt = new WritableCellFormat(leftFont); + leftFormt.setAlignment(Alignment.LEFT); + leftFormt.setVerticalAlignment(VerticalAlignment.CENTRE); + + + + + + WritableFont title = new WritableFont(WritableFont.ARIAL, 18, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); + WritableCellFormat titleFormt = new WritableCellFormat(title); + titleFormt.setAlignment(jxl.format.Alignment.CENTRE); + titleFormt.setVerticalAlignment(VerticalAlignment.CENTRE); + + for (int i = 0; i < ws.getRows() ; i++) { + for (int j = 0; j < ws.getColumns(); j++) { + if(i == 0 && j == 0){ + Label label = new Label(j, i, "四川省成都市统计",titleFormt); + ws.addCell(label); + } + + if(i == 1 && j == 0){ + Label label = new Label(j, i, "成都市",leftFormt); + ws.addCell(label); + } + + if(i == 1 && j == 19){ + Label label = new Label(j, i, "2018-08-20",leftFormt); + ws.addCell(label); + } + } + } + + + for (int i = 5, len = 30; i < len; i++) + { + for (int j = 0; j < columNames.size() ; j++) + { + WritableCellFormat wcfN = new WritableCellFormat(contentFont); + wcfN.setAlignment(jxl.format.Alignment.CENTRE); + wcfN.setVerticalAlignment(VerticalAlignment.CENTRE); + Number labelNF = new Number(j, i,j, wcfN); + ws.addCell(labelNF); + } + + } + + ws.addCell(new Label(0, 30, "注:统计时限:上月26日至本月25日;分娩方式中其他包括:吸引产、臀助产、臀牵引、产钳产等。", leftFormt)); + + ws.mergeCells(0, 30, 36, 30); + + ws.addCell(new Label(0, 31, "填报单位:", leftFormt)); + ws.mergeCells(0, 31, 5, 31); + ws.addCell(new Label(6, 31, "填报人:", leftFormt)); + ws.mergeCells(6, 31, 10, 31); + ws.addCell(new Label(11, 31, "填报日期:", leftFormt)); + ws.mergeCells(11, 31,36, 31); + + book.write(); + book.close(); + wb.close(); + }catch (Exception e) + { + e.printStackTrace(); + } + + } + public static void main(String[] args) { - ExcelUtil.readExcl("F:\\1.xls"); + ExcelUtil.readExclFile("F:\\需求文档\\my.xls"); } }