[英]reading excel file using XMLStreamReader ( read number as string, not as a number )
I am reading an excel file using XMLStreamReader object. 我正在使用XMLStreamReader对象读取Excel文件。 The initialization of this object is somewhat like this :
这个对象的初始化有点像这样:
opcPkg = OPCPackage.open(excelPath, PackageAccess.READ);
xssfReader = new XSSFReader(opcPkg);
factory = XMLInputFactory.newInstance();
iterator = xssfReader.getSheetsData();
inputStream = iterator.next();
xmlReader = factory.createXMLStreamReader(inputStream);
The contents of a cell are read using this statement, 使用此语句读取单元格的内容,
xmlReader.getElementText();
The problem is that a simple number string 10.2 contained in a cell is being read as 10.199999999999999. 问题在于,单元格中包含的简单数字字符串10.2被读取为10.199999999999999。 I want it to be read as 10.2 only.
我希望将其仅阅读为10.2。 Is there a way to solve this ?
有办法解决吗?
When you read it as a String, do you parse it with 当您将其读取为字符串时,是否使用
Double.parseDouble(...getText() );
That would be the surest way to get a number out of a line of text 那是从一行文本中获取数字的最可靠方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.