// 3.9だとXSSFRichTextStringにフォントの設定が効かない //@Grab(group='org.apache.poi', module='poi-ooxml', version='3.9') @Grab(group='org.apache.poi', module='poi-ooxml', version='3.10-beta2') import org.apache.poi.xssf.usermodel.*; import org.apache.poi.ss.usermodel.*; workbook = new XSSFWorkbook() sheet = workbook.createSheet("sheet1") XSSFDrawing patriarch = sheet.createDrawingPatriarch() // ----------------------------------------------- // データベース形を描画 ca1 = new XSSFClientAnchor( 0, 0, 0, 0, /* top-left */ (short)1, 1, /* right-bottom */ (short)3, 5 ) ca1.setAnchorType(ca1.MOVE_AND_RESIZE) db1 = patriarch.createSimpleShape(ca1) db1.setShapeType(ShapeTypes.CAN) font1 = workbook.createFont() font1.setColor(XSSFFont.DEFAULT_FONT_COLOR) font1.setFontName("MS Pゴシック") font1.setFontHeightInPoints((short)12) rts = new XSSFRichTextString("Database1") rts.applyFont(font1) db1.setText(rts) // 線の色と太さ db1.setLineStyleColor(0x00, 0x00, 0x00) db1.setLineWidth(1) // 塗りつぶし無しに設定 db1.setNoFill(true) // ----------------------------------------------- // 文書形を描画 ca2 = new XSSFClientAnchor( 0, 0, 0, 0, /* top-left */ (short)1, 6, /* right-bottom */ (short)3, 8 ) ca2.setAnchorType(ca1.MOVE_AND_RESIZE) doc1 = patriarch.createSimpleShape(ca2) doc1.setShapeType(ShapeTypes.FOLDED_CORNER ) rts2 = new XSSFRichTextString("Document1") rts2.applyFont(font1) doc1.setText(rts2) // 線の色と太さ doc1.setLineStyleColor(0x00, 0x00, 0x00) doc1.setLineWidth(1) // 塗りつぶし無しに設定 doc1.setNoFill(true) // ----------------------------------------------- // 角丸四角を描画 ca3 = new XSSFClientAnchor( 0, 0, 0, 0, /* top-left */ (short)1, 9, /* right-bottom */ (short)3, 11 ) ca3.setAnchorType(ca1.MOVE_AND_RESIZE) rr1 = patriarch.createSimpleShape(ca3) rr1.setShapeType(ShapeTypes.ROUND_RECT ) rts3 = new XSSFRichTextString("角丸") rts3.applyFont(font1) rr1.setText(rts3) // 線の色と太さ rr1.setLineStyleColor(0x00, 0x00, 0x00) rr1.setLineWidth(1) // 塗りつぶし無しに設定 rr1.setNoFill(true) workbook.write(new FileOutputStream("test.xlsx"))出力画面
動作環境
groovy 2.1.7, JDK7 update40
0 件のコメント:
コメントを投稿