如何通过apache poi在xlsx中编写一个非常大的数字
我需要写一个非常大的数字(> 91430000000000000000
)的Excel单元格的问题是,单元格的最大值是9143018315613270000
,所有值更大 – 将被replace为最大值。 如果撇号被添加到一个数字,这个问题将简单地通过手解决,例如'9143018315313276189
但是如何通过apache POI相同的技巧? 我有以下代码:
attrId.setCellValue(new XSSFRichTextString('\'' + value.getId().toString()));
但它不起作用:
这里的第一行没有任何撇号,第二行是用手写的,这是我正在寻找的结果。 第三是我的代码的结果。 我也尝试使用setCellValue,它采取双和string,他们都不帮我乙醚。
所以,这里有个问题:如何通过apache POI在excel中写入一个非常大的数字?
首先设置单元格样式
DataFormat format = workbook.createDataFormat(); CellStyle testStyle = workbook.createCellStyle(); testStyle.setDataFormat(format.getFormat("@")); String bigNumber = "9143018315313276189"; row.createCell(40).setCellStyle(testStyle); row.getCell(40).setCellValue(bigNumber);
你可以设置单元格types,看看会发生什么。 或者,如果你已经设置了,那么请发布你的代码,以便其他人看看它。
cell.setCellType(Cell.CELL_TYPE_STRING);
请参考这里的问题有关如何将string值设置为单元格的详细信息如何使用Apache POI读取Excel单元格中的数字string作为string(不是数字)?
我做了下面的例子,为我工作(poi-3.1.3)
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; public class WriteToExcel { public static void main(String[] args) throws IOException { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Sample sheet"); Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue("91430183153132761893333"); try { FileOutputStream out = new FileOutputStream(new File("C:\\test_stackoverflow\\new.xls")); workbook.write(out); out.close(); System.out.println("Excel written successfully.."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
- Excel:在另一个工作表中从命名范围创builddynamic表
- Java的Apache poi错误:java.lang.IllegalArgumentException:未知的错误types:-60
- 添加更多图像时POI的问题
- 打印Excel文件的单元格值
- org.apache.poi.POIXMLException:使用Libre Office更新.xls文件后POI API中的java.lang.reflect.InvocationTargetException
- 如何使用Java中的Apache POI库对数据透视表数据进行sorting
- 如何使用POI SS处理HYPERLINKfunction?
- 用javaparsing网页到excel和使用超链接
- 如何保存从Java创build的Excel文档