Java Code Examples for org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
The following examples show how to use
org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WatermarkExcelTests.java From kbase-doc with Apache License 2.0 | 6 votes |
@Test public void testExcel() throws IOException { String filepath = "E:\\ConvertTester\\excel\\abcd.xlsx"; File originFile = new File(filepath); InputStream in = new FileInputStream(originFile); XSSFWorkbook workbook = new XSSFWorkbook(in); XSSFSheet sheet = workbook.createSheet("testSheet"); XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1023, 255, (short) 2, 4, (short) 13, 26); XSSFTextBox textbox = drawing.createTextbox(anchor); XSSFRichTextString rtxt = new XSSFRichTextString("ekozhan"); XSSFFont font = workbook.createFont(); font.setColor((short) 27); font.setBold(true); font.setFontHeightInPoints((short) 192); font.setFontName("Verdana"); rtxt.applyFont(font); textbox.setText(rtxt); textbox.setLineStyle(XSSFShape.EMU_PER_POINT); textbox.setNoFill(true); workbook.write(new FileOutputStream(filepath)); workbook.close(); }
Example 2
Source File: WatermarkExcelTests.java From kbase-doc with Apache License 2.0 | 5 votes |
@Test public void test1() throws IOException { ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); String imgPath = "D:\\Xiaoi\\logo\\logo.png"; BufferedImage bufferImg = ImageIO.read(new File(imgPath)); //这里要注意,第二个参数将会决定插入图片形式,如果是一个png的图片,背景透明,但是此处设置为jpg格式将会自动添加黑色背景 ImageIO.write(bufferImg, "png", byteArrayOut); String filepath = "E:\\ConvertTester\\excel\\abcde.xlsx"; File originFile = new File(filepath); InputStream in = new FileInputStream(originFile); XSSFWorkbook workbook = new XSSFWorkbook(in); XSSFSheet sheet = workbook.createSheet("testSheet"); //画图的顶级管理器,一个sheet只能获取一个 XSSFDrawing drawing = sheet.createDrawingPatriarch(); //anchor主要用于设置图片的属性 // XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1023, 255, (short) 2, 4, (short) 13, 26); /* * 参数定义: * 第一个参数是(x轴的开始节点); * 第二个参数是(是y轴的开始节点); * 第三个参数是(是x轴的结束节点); * 第四个参数是(是y轴的结束节点); * 第五个参数是(是从Excel的第几列开始插入图片,从0开始计数); * 第六个参数是(是从excel的第几行开始插入图片,从0开始计数); * 第七个参数是(图片宽度,共多少列); * 第8个参数是(图片高度,共多少行); */ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, Short.MAX_VALUE, Integer.MAX_VALUE, 0, 0, 10, 10); anchor.setAnchorType(AnchorType.DONT_MOVE_DO_RESIZE); //插入图片 drawing.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), XSSFWorkbook.PICTURE_TYPE_PNG)); workbook.write(new FileOutputStream("E:\\ConvertTester\\excel\\abcd-011.xlsx")); workbook.close(); }
Example 3
Source File: WatermarkExcelTests.java From kbase-doc with Apache License 2.0 | 5 votes |
@Test public void testExcel2() throws IOException { String filepath = "E:\\ConvertTester\\excel\\abcd.xlsx"; File originFile = new File(filepath); InputStream in = new FileInputStream(originFile); XSSFWorkbook workbook = new XSSFWorkbook(in); XSSFSheet sheet = workbook.createSheet("testSheet"); XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1023, 255, (short) 2, 4, (short) 13, 26); }
Example 4
Source File: SimpleUtils.java From bamboobsc with Apache License 2.0 | 5 votes |
public static void setCellPicture(XSSFWorkbook wb, XSSFSheet sh, byte[] iconBytes, int row, int col) throws Exception { int myPictureId = wb.addPicture(iconBytes, XSSFWorkbook.PICTURE_TYPE_PNG); XSSFDrawing drawing = sh.createDrawingPatriarch(); XSSFClientAnchor myAnchor = new XSSFClientAnchor(); myAnchor.setCol1(col); myAnchor.setRow1(row); XSSFPicture myPicture = drawing.createPicture(myAnchor, myPictureId); myPicture.resize(); }