在 jasperreports-0.6.8\lib 中,使用的apache poi 版本: poi-2.0-final-20040126.jar
此版本poi 还不支持图片的处理。
到现在 poi 3.0 alphal 已经发布,(2005-07-04) 这个版本已经加入插入图片的功能。
下载原代码:
http://apache.freelamp.com/jakarta/poi/dev/src/ poi-src-3.0-alpha1-20050704.zip 详细查看 sample 部分
src/examples/src
org.apache.poi.hssf.usermodel.examples
OfficeDrawing
于2005-05-01加入了新的示例代码:drawSheet5
public class OfficeDrawing
{
public static void main(String[] args)
throws IOException
{
// Create the workbook and sheets.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet5 = wb.createSheet("fifth sheet");
drawSheet5( sheet5, wb );
// Write the file out.
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
private static void drawSheet5( HSSFSheet sheet5, HSSFWorkbook wb ) throws IOException
{
// Create the drawing patriarch. This is the top level container for
// all shapes. This will clear out any existing shapes for that sheet.
HSSFPatriarch patriarch = sheet5.createDrawingPatriarch();
HSSFClientAnchor anchor;
anchor = new HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7);
anchor.setAnchorType( 2 );
patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
anchor = new HSSFClientAnchor(0,0,0,255,(short)4,2,(short)5,7);
anchor.setAnchorType( 2 );
patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4edited.png", wb ));
anchor = new HSSFClientAnchor(0,0,1023,255,(short)6,2,(short)8,7);
anchor.setAnchorType( 2 );
HSSFPicture picture = patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4s.png", wb ));
picture.setLineStyle( picture.LINESTYLE_DASHDOTGEL );
}
private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException
{
int pictureIndex;
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
try
{
fis = new FileInputStream( path);
bos = new ByteArrayOutputStream( );
int c;
while ( (c = fis.read()) != -1)
bos.write( c );
pictureIndex = wb.addPicture( bos.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG );
}
finally
{
if (fis != null)
fis.close();
if (bos != null)
bos.close();
}
return pictureIndex;
}
} 方向:分布式系统设计