poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From milan777 <milan79pa...@gmail.com>
Subject Getting error while reading .xlsx file in using poi
Date Thu, 06 Jun 2013 06:01:37 GMT
Please help me i am getting error like this.......

Exception in thread "main" org.apache.poi.POIXMLException:
java.lang.reflect.InvocationTargetException
	at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
	at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
	at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
	at Excel.Test.main(Test.java:28)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at
org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
	... 4 more
Caused by: java.lang.ExceptionInInitializerError
	at
org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown
Source)
	at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:44)
	... 9 more
Caused by: java.lang.IllegalStateException: Cannot load build: verify that
xbean.jar is on the classpath
	at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:181)
	at
org.apache.xmlbeans.XmlBeans.buildTypeLoaderBuilderMethod(XmlBeans.java:216)
	at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:129)
	... 11 more
Caused by: java.lang.NoSuchMethodException:
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build([Lorg.apache.xmlbeans.SchemaTypeLoader;,
org.apache.xmlbeans.ResourceLoader, java.lang.ClassLoader)
	at java.lang.Class.getMethod(Unknown Source)
	at org.apache.xmlbeans.XmlBeans.buildMethod(XmlBeans.java:174)
	... 13 more




my code is.....

package Excel;


 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;

 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Test {
 public static void main(String[] args) throws IOException {
 String fname = "D:\\test.xlsx"; // or "C:\\Test.xls" C:\\SDI-XL.xls
 InputStream inp = new FileInputStream(fname);
 String fileExtn = GetFileExtension(fname);
 Workbook wb_xssf; //Declare XSSF WorkBook
 Workbook wb_hssf; //Declare HSSF WorkBook
 Sheet sheet = null; // sheet can be used as common for XSSF and HSSF
WorkBook
 if (fileExtn.equalsIgnoreCase("xlsx"))
 {
 wb_xssf = new XSSFWorkbook(inp);
 log("xlsx="+wb_xssf.getSheetName(0));
 sheet = wb_xssf.getSheetAt(0);
 }
 if (fileExtn.equalsIgnoreCase("xls"))
 {
 POIFSFileSystem fs = new POIFSFileSystem(inp);
 wb_hssf = new HSSFWorkbook(fs);
 log("xls="+wb_hssf.getSheetName(0));
 sheet = wb_hssf.getSheetAt(0);
 }
 Iterator rows = sheet.rowIterator(); // Now we have rows ready from the
sheet
 while (rows.hasNext())
 {
 Row row = (Row) rows.next();
 log("row#="+row.getRowNum()+"");
 log("**********************");
 //log(row.getPhysicalNumberOfCells()+"");
 Iterator cells = row.cellIterator();
 while (cells.hasNext())
 {
 Cell cell = (Cell) cells.next();

 switch ( cell.getCellType() )
 {
 case Cell.CELL_TYPE_STRING:
 log(cell.getRichStringCellValue().getString());
 break;
 case Cell.CELL_TYPE_NUMERIC:
 if(DateUtil.isCellDateFormatted(cell)) {
 log(cell.getDateCellValue()+"");
 } else {

 System.out.println(cell.getNumericCellValue());
 }
 break;
 case Cell.CELL_TYPE_BOOLEAN:
 log(cell.getBooleanCellValue()+"");
 break;
 case Cell.CELL_TYPE_FORMULA:
 log(cell.getCellFormula());
 break;
 default:
 }
 }
 }
 inp.close();
 }

 private static void log(String message)
 {
 System.out.println(message);
 }
 private static String GetFileExtension(String fname2)
 {
 String fileName = fname2;
 String fname="";
 String ext="";
 int mid= fileName.lastIndexOf(".");
 fname=fileName.substring(0,mid);
 ext=fileName.substring(mid+1,fileName.length());
 return ext;
 }
 }



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Getting-error-while-reading-xlsx-file-in-using-poi-tp5712947.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message