I am using POI XSSF for reading the xlsx file, I have the problem in reading the decimal values. For ex, value in sheet 34.56012 but returns as 34.560100234 for some specific values. Any solution for the problem could be appreciated!!..
How are you fetching the cell values, and what formatting are you applying to them?
Created attachment 32054 [details] MyXSSFSheetHandler
public ArrayList<ArrayList<String>> getSheetData() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { OPCPackage xlsxPackage = OPCPackage.open(fileName, PackageAccess.READ); ArrayList<ArrayList<String>> sheetData = new ArrayList<ArrayList<String>>(); ReadonlySharedStringsTable strings = new ReadonlySharedStringsTable( xlsxPackage); XSSFReader xssfReader = new XSSFReader(xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader .getSheetsData(); int index = 0; if (iter.hasNext()) { InputStream stream = iter.next(); String sheetName = iter.getSheetName(); this.output.println(); this.output.println(sheetName + " [index=" + index + "]:"); sheetData = processSheet(styles, strings, stream); stream.close(); ++index; } return sheetData; } public ArrayList<ArrayList<String>> processSheet(StylesTable styles, ReadonlySharedStringsTable strings, InputStream sheetInputStream) throws IOException, ParserConfigurationException, SAXException { InputSource sheetSource = new InputSource(sheetInputStream); SAXParserFactory saxFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxFactory.newSAXParser(); XMLReader sheetParser = saxParser.getXMLReader(); ContentHandler handler = new MyXSSFSheetHandler(styles, strings, this.minColumns, this.output); sheetParser.setContentHandler(handler); sheetParser.parse(sheetSource); return ((MyXSSFSheetHandler) handler).getData(); } Used this logic to read the data
What's the format string that Excel thinks is applied to the cell, and what is the one that POI sees? And what's the raw number stored by Excel in the file?
Created attachment 32056 [details] xlsx file used to read
There is no format applied in cell of the sheet as well as POI while reading the data.
If you don't set any formatting, you'll just get the raw number as stored by Excel If you want formatting rules to apply to a cell, you need to set a cell style that includes them!