> I'm not sure why its complaining PictureData has no method
> suggestFile
> Extension. Once I solve this I assume the next step
> is to save the output
> stream into a blob? I've downloaded poi 3.2.
Alyssa,
I believe the example in the link is using the newer 3.5 beta. Try using
version 3.5. Be sure to add the jars in the /ooxml-lib folder to your
classpath as well.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class GrabImages {
public static void main(String[] args) {
try {
File filePath = new File("C:/testImages.xls");
FileInputStream inStream = new FileInputStream(filePath);
Workbook workbook = WorkbookFactory.create(inStream);
List lst = workbook.getAllPictures();
int imageCount = 0;
for (Iterator it = lst.iterator(); it.hasNext(); ) {
PictureData pict = (PictureData)it.next();
String ext = pict.suggestFileExtension();
byte[] data = pict.getData();
if (ext.equals("jpeg")){
FileOutputStream out = new FileOutputStream("pict"+
imageCount +"."+ ext);
out.write(data);
out.close();
imageCount++;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
HTH
Leigh
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]