how to read Images from an excelsheet via jexcel
how to read Images from an excelsheet via jexcel
This example demonstrates how can you read the images contained in the workbook.
For reading the images from a workbook firstly you have to import the jxl.read.biff package.
In this example we have used the getDrawing(int arg) method on the sheet to get the image. Also we have used the getImageFile(Image img) method to get the path of the image where the image is contained.
In this example we have created a class named ReadImagesFromSheetXL, in which we have created a main method which is reading an image from a sheet of an existing workbook.
package r4r.co.in;
import jxl.*;
import jxl.Workbook;
import jxl.read.biff.*;
import java.io.File;
import java.io.IOException;
import jxl.write.WriteException;
import java.util.Locale;
public class ReadImagesFromSheetXL {
/**
* @param args
*/
public static void main(String[] args) throws IOException, WriteException, BiffException{
// TODO Auto-generated method stub
try
{
File f1=new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls");
WorkbookSettings ws=new WorkbookSettings();
ws.setLocale(new Locale("er","ER"));
Workbook workbook=Workbook.getWorkbook(f1,ws); //opening an existing workbook
Sheet readsheet=workbook.getSheet(0);
System.out.println(readsheet.getName()); // getting the name of sheet contained in the workbook
LabelCell lcobj=readsheet.findLabelCell("Image");
System.out.println(lcobj.getString());
Image img=readsheet.getDrawing(0);
System.out.println(img.getImageFile());
}
catch(IOException e)
{
e.printStackTrace();
}
catch(BiffException e)
{
e.printStackTrace();
}
}
}