Return-Path: X-Original-To: apmail-poi-user-archive@www.apache.org Delivered-To: apmail-poi-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 562CA10746 for ; Thu, 6 Jun 2013 09:51:41 +0000 (UTC) Received: (qmail 89945 invoked by uid 500); 6 Jun 2013 09:51:40 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 89666 invoked by uid 500); 6 Jun 2013 09:51:32 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Delivered-To: moderator for user@poi.apache.org Received: (qmail 43589 invoked by uid 99); 6 Jun 2013 06:02:22 -0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: encountered temporary error during SPF processing of domain of milan79patel@gmail.com) Date: Wed, 5 Jun 2013 23:01:37 -0700 (PDT) From: milan777 To: user@poi.apache.org Message-ID: <1370498497365-5712947.post@n5.nabble.com> Subject: Getting error while reading .xlsx file in using poi MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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.(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.(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.(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