apache POIを使用して
こちらの書類を作成したいのですが、罫線をまとめて複数のセルに引く方法と、
こうなってしまう理由を教えてほしいです。
POITest.java public class POI { ※import部分は省略 @SuppressWarnings("resource") public static void main(String[] args){ Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Font font = wb.createFont(); font.setBold(true); sheet.setColumnWidth(0, 4096); sheet.setColumnWidth(1, 4096); Sheet sheet0 = wb.getSheetAt(0); sheet0.addMergedRegion(new CellRangeAddress(6, 7, 0, 1)); sheet0.addMergedRegion(new CellRangeAddress(6, 7, 2, 5)); CellStyle top = wb.createCellStyle(); top.setBorderTop(BorderStyle.MEDIUM); CellStyle left = wb.createCellStyle(); left.setBorderLeft(BorderStyle.MEDIUM); CellStyle bottom = wb.createCellStyle(); bottom.setBorderBottom(BorderStyle.MEDIUM); CellStyle right = wb.createCellStyle(); right.setBorderRight(BorderStyle.MEDIUM); Row row1 = sheet.createRow(1); Row row2 = sheet.createRow(2); Row row3 = sheet.createRow(3); Row row4 = sheet.createRow(4); Row row5 = sheet.createRow(5); Row row6 = sheet.createRow(6); Row row7 = sheet.createRow(7); Row row8 = sheet.createRow(8); Row row9 = sheet.createRow(9); Row row10 = sheet.createRow(10); Row row11 = sheet.createRow(11); Row row13 = sheet.createRow(13); Cell cell1_1 = row1.createCell(1); Cell cell3_0 = row3.createCell(0); Cell cell3_1 = row3.createCell(1); Cell cell3_2 = row3.createCell(2); Cell cell3_3 = row3.createCell(3); Cell cell3_4 = row3.createCell(4); Cell cell3_5 = row3.createCell(5); Cell cell3_6 = row3.createCell(6); Cell cell6_0 = row6.createCell(0); Cell cell6_2 = row6.createCell(2); Cell cell8_0 = row8.createCell(0); Cell cell8_1 = row8.createCell(1); Cell cell8_2 = row8.createCell(2); Cell cell8_3 = row8.createCell(3); Cell cell8_4 = row8.createCell(4); Cell cell9_0 = row9.createCell(0); Cell cell9_1 = row9.createCell(1); Cell cell9_3 = row9.createCell(3); Cell cell9_2 = row9.createCell(2); Cell cell9_4 = row9.createCell(4); Cell cell10_4 = row10.createCell(4); Cell cell11_4 = row11.createCell(4); Cell cell13_3 = row13.createCell(3); Cell cell13_4 = row13.createCell(4); cell1_1.setCellValue("旅費及び請求書(清算書)"); cell3_0.setCellStyle(top); cell3_0.setCellStyle(left); cell3_0.setCellValue("出張先名称"); cell3_1.setCellStyle(top); cell3_2.setCellStyle(top); cell3_2.setCellStyle(right); cell3_3.setCellValue("出張先所在地"); cell3_3.setCellStyle(top); cell3_3.setCellStyle(left); cell3_4.setCellStyle(top); cell3_5.setCellStyle(top); cell3_6.setCellStyle(top); cell3_6.setCellStyle(right); cell6_0.setCellValue("出張期間"); CellStyle style6_0 = wb.createCellStyle(); style6_0.setVerticalAlignment(VerticalAlignment.CENTER); style6_0.setAlignment(HorizontalAlignment.CENTER); cell6_0.setCellStyle(style6_0); cell6_2.setCellValue("1月6日 ~ 1月7日 迄(2日間)"); cell6_2.setCellStyle(style6_0); cell8_0.setCellValue("日付"); CellStyle style8_0 = wb.createCellStyle(); style8_0.setAlignment(HorizontalAlignment.CENTER); cell8_0.setCellStyle(style8_0); cell8_1.setCellValue("区間"); cell8_1.setCellStyle(style8_0); cell8_2.setCellValue("運賃"); cell8_2.setCellStyle(style8_0); cell8_3.setCellValue("宿泊"); cell8_3.setCellStyle(style8_0); cell8_4.setCellValue("計"); cell8_4.setCellStyle(style8_0); cell9_0.setCellValue("7月6日"); CellStyle style9_0 = wb.createCellStyle(); style9_0.setAlignment(HorizontalAlignment.RIGHT); cell9_0.setCellStyle(style9_0); cell9_1.setCellValue("A~B"); cell9_1.setCellStyle(style8_0); cell9_2.setCellValue("¥1.000"); CellStyle style9_2 = wb.createCellStyle(); style9_2.setAlignment(HorizontalAlignment.RIGHT); cell9_2.setCellStyle(style9_2); cell9_3.setCellValue("¥3.000"); cell9_3.setCellStyle(style9_2); cell9_4.setCellValue("¥3.000"); cell9_4.setCellStyle(style9_2); cell10_4.setCellValue("¥0"); cell10_4.setCellStyle(style9_2); cell11_4.setCellValue("¥0"); cell11_4.setCellStyle(style9_2); cell13_3.setCellValue("合計"); CellStyle style13_3 = wb.createCellStyle(); style13_3.setAlignment(HorizontalAlignment.LEFT); cell13_3.setCellStyle(style13_3); cell13_4.setCellValue("¥3.000"); cell13_4.setCellStyle(style9_2); FileOutputStream out = null; try{ out = new FileOutputStream("POITest.xls"); wb.write(out); }catch(IOException e){ System.out.println(e.toString()); }finally{ try { out.close(); }catch(IOException e){ System.out.println(e.toString()); } } } }
回答2件
あなたの回答
tips
プレビュー