使用apache-poi在excel中绘制一条线

任何人都可以给我写几行代码,说明如何在excel中使用apache poi在单元格中写一行代码? 在普通的Excel中,我会去插入 – 形状 – 线。 基础,做这样的代码:

Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row=sheet.createRow(0); Cell cell = row.createCell(0); 

现在,缺less代码会在这里。 当我searchnetworking时,我应该使用类HSSFSimpleShape和OBJECT_TYPE_LINE。 但我不知道如何实现它在我的代码:(

我想我应该有我想画的线或一些像素作为coordinaets或东西的细胞。

帮帮我 ! 🙂

看看这个例子:

 Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch(); /* Here is the thing: the line will go from top left in cell (0,0) to down left of cell (0,1) */ HSSFClientAnchor anchor = new HSSFClientAnchor( 0, 0, 0, 255, (short) 0, 0,(short) 1, 0); HSSFSimpleShape shape = patriarch.createSimpleShape(anchor); shape.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); shape.setLineStyleColor(10, 10, 10); shape.setFillColor(90, 10, 200); shape.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT); shape.setLineStyle(HSSFShape.LINESTYLE_SOLID); // you don't even need the cell, but if you also want to write anything... Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue("Test"); 

我也build议看看HSSFClientAnchor Javadoc