惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Latest news
Latest news
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
博客园 - Franky
博客园_首页
爱范儿
爱范儿
博客园 - 聂微东
月光博客
月光博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
IT之家
IT之家
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
Scott Helme
Scott Helme
The Hacker News
The Hacker News
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件
WordPress大学
WordPress大学
N
News and Events Feed by Topic
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
美团技术团队
D
Darknet – Hacking Tools, Hacker News & Cyber Security
宝玉的分享
宝玉的分享
Spread Privacy
Spread Privacy
S
SegmentFault 最新的问题
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
雷峰网
雷峰网
Martin Fowler
Martin Fowler
C
Cybersecurity and Infrastructure Security Agency CISA
A
Arctic Wolf
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
N
News and Events Feed by Topic

博客园 - foward.molly.宝儿

jenkins和sonar的几个问题 Test class should have exactly one public constructor解决办法 ubuntu安装和查看已安装 rails mysql2问题 axis2依赖的其他jar, 版本不是最新的 mysql: 启动和停止服务 mysql: 安装后的目录结构 msyql: mysql rpm安装手记 - foward.molly.宝儿 velocity: velocty转义html xml等 testng: testng使用小结 IE, firefox竖向 横向滚动条处理 ruby: rdoc生成文档的好工具 spring: 一些基本配置--也许只有自己能够读懂 - foward.molly.宝儿 - 博客园 spring: web学习笔记1--异常处理:No adapter for handler - foward.molly.宝儿 maven: maven创建工程,web工程等-普通java app, web app maven: maven编译时指定maven库,即指定profile ssh免密码登录, 发送命令到多个Linux php: eclipse 编辑 php ruby: 使用netbeans debug ruby
POI 生成excel(大数据量) SXSSF
foward.molly.宝儿 · 2019-01-04 · via 博客园 - foward.molly.宝儿

使用POI 的SXSSF (Streaming Usermodel API)生成较大的excel,同时开启压缩

 1 import junit.framework.Assert;
 2 import org.apache.poi.ss.usermodel.Cell;
 3 import org.apache.poi.ss.usermodel.Row;
 4 import org.apache.poi.ss.usermodel.Sheet;
 5 import org.apache.poi.ss.usermodel.Workbook;
 6 import org.apache.poi.ss.util.CellReference;
 7 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 8 
 9     public static void main(String[] args) throws Throwable {
10         SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
11         Sheet sh = wb.createSheet();
12         for(int rownum = 0; rownum < 1000; rownum++){
13             Row row = sh.createRow(rownum);
14             for(int cellnum = 0; cellnum < 10; cellnum++){
15                 Cell cell = row.createCell(cellnum);
16                 String address = new CellReference(cell).formatAsString();
17                 cell.setCellValue(address);
18             }
19 
20         }
21 
22         // Rows with rownum < 900 are flushed and not accessible
23         for(int rownum = 0; rownum < 900; rownum++){
24           Assert.assertNull(sh.getRow(rownum));
25         }
26 
27         // ther last 100 rows are still in memory
28         for(int rownum = 900; rownum < 1000; rownum++){
29             Assert.assertNotNull(sh.getRow(rownum));
30         }
31         
32         FileOutputStream out = new FileOutputStream("/temp/sxssf.xlsx");
33         wb.write(out);
34         out.close();
35 
36         // dispose of temporary files backing this workbook on disk
37         wb.dispose();
38     }

遇到的问题:

错误是NPE错误,类似如下,原因是缺少字体或者环境变量未设置,需要安装"ttf-dejavu"字体,具体可以参考:

https://stackoverflow.com/questions/30626136/cannot-load-font-in-jre-8

https://www.jianshu.com/p/c05b5fc71bd0

 1 java.lang.NullPointerException
 2     at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
 3     at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
 4     at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
 5     at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
 6     at sun.font.SunFontManager$2.run(SunFontManager.java:431)
 7     at java.security.AccessController.doPrivileged(Native Method)
 8     at sun.font.SunFontManager.<init>(SunFontManager.java:376)
 9     at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
10     at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
11     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
12     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
13     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
14     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
15     at java.lang.Class.newInstance(Class.java:442)
16     at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
17     at java.security.AccessController.doPrivileged(Native Method)
18     at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
19     at java.awt.Font.getFont2D(Font.java:495)
20     at java.awt.Font.canDisplayUpTo(Font.java:2080)
21     at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
22     at java.awt.font.TextLayout.<init>(TextLayout.java:531)
23     at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:275)
24     at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
25     at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:79)
26     at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:656)
27     at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:677)
28     at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:83)

还有一种,easyexcel,没用过,可以参考https://github.com/alibaba/easyexcel