Sun May 13, 2012 2:52 pm
package com.android.testexcel;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class MyWorkBook {
void writeImageToExcel(String filePath, String imageFileName) {
int col = 1, row = 1;
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet testsheet = wb.createSheet("test");
System.out.println("The work book is created");
try {
FileOutputStream fos = new FileOutputStream(filePath);
System.out.println("File sample.xls is created");
FileInputStream fis = new FileInputStream(imageFileName);
ByteArrayOutputStream img_bytes = new ByteArrayOutputStream();
int b;
while ((b = fis.read()) != -1)
img_bytes.write(b);
fis.close();
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
(short) col, row, (short) ++col, ++row);
int index = wb.addPicture(img_bytes.toByteArray(),
HSSFWorkbook.PICTURE_TYPE_JPEG);
HSSFSheet sheet = wb.getSheet("test");
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
patriarch.createPicture(anchor, index);
anchor.setAnchorType(2);
wb.write(fos);
System.out.println("Writing data to the xls file");
fos.close();
System.out.println("File closed");
} catch (IOException ioe) {
System.out
.println("Hi ! You got an exception. " + ioe.getMessage());
ioe.printStackTrace();
}
}
}// end of class MyWorkBook
Sun May 13, 2012 8:45 pm
http://grepcode.com/file/repo1.maven.org/maven2/commons-codec/commons-codec/1.5/org/apache/commons/codec/digest/DigestUtils.java
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.