如何通过apache poi在xlsx中写一个非常大的数字(How to write a very large number in xlsx via apache poi)

编程入门 行业动态 更新时间:2024-10-11 07:27:19
如何通过apache poi在xlsx中写一个非常大的数字(How to write a very large number in xlsx via apache poi)

我需要写一个excel单元格非常大(> 91430000000000000000 )问题是单元格的最大值是9143018315613270000 ,所有更大的值 - 将被最大值替换。 如果将撇号添加到数字中,这个问题将简单地用手解决,例如'9143018315313276189但是如何通过apache POI使用相同的技巧? 我有以下代码:

attrId.setCellValue(new XSSFRichTextString('\'' + value.getId().toString()));

但它不起作用:

这里第一行根本没有任何撇号,第二行是用手写的,这是我正在寻找的结果。 第三是我的代码的结果。 我也尝试使用带有double和String的setCellValue,它们都不能帮助我。

所以,这里提出了一个问题:如何通过apache POI在excel中写入非常大的数字?

I need to write to an excel cell a very large numbers(>91430000000000000000) The issue is that max value for cell is 9143018315613270000, and all values which is larger - would be replaced by max value. This issue will simply resolved by hands if an apostrophe is added to an number, for example '9143018315313276189 But how to the same trick via apache POI? I have follow code:

attrId.setCellValue(new XSSFRichTextString('\'' + value.getId().toString()));

But it doesn't work:

Here the first row haven't any apostrophe at all, second one is written by hands and it is the result I'm looking for. Third is a result of my code. I also tried to use setCellValue which takes double and String, both of them doesn't help me ether.

So, here goes the question: How to write in excel a very large numbers via apache POI?

最满意答案

首先设置单元格样式

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);

Set the cell style first

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);

更多推荐

本文发布于:2023-08-06 08:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1447618.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:非常大   数字   xlsx   apache   poi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!