- 浏览: 461099 次
- 性别:
- 来自: 青岛
文章分类
最新评论
-
此去经年雪123:
为啥生成的是乱码 你好
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名 -
alonglw:
zxf0089216 写道1.为什么每次都是10001RSAK ...
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名 -
zxf0089216:
1.为什么每次都是10001RSAKeyPair(" ...
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名 -
dunhanson:
后台的测试main方法都能加密解密。前台加密后的密文交给后台解 ...
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名 -
map612:
wula0010 写道仔细看了下,可以运行RSAUtil.ma ...
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名
一般导出Excel可以选择POI或者JXL,poi比较方便但是处理大数据量效果不佳,jxl可以支持较大数据量,但是超过5W条也会报OOM错误。
那么如果有上百万条的数据怎么到处Excel呢?
其实Excel可以保存成HTML格式的文档(包括图片),我们可以研究html文件格式,然后用io方式往里面输出数据就可以了。
html格式如下:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> <meta name=ProgId content=Excel.Sheet> <meta name=Generator content="Microsoft Excel 11"> <link rel=File-List href="Book1.files/filelist.xml"> <link rel=Edit-Time-Data href="Book1.files/editdata.mso"> <link rel=OLE-Object-Data href="Book1.files/oledata.mso"> <!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} x\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>www.jujumao.com</o:Author> <o:LastAuthor>www.jujumao.com</o:LastAuthor> <o:Created>2010-05-24T10:00:21Z</o:Created> <o:LastSaved>2010-05-25T01:00:34Z</o:LastSaved> <o:Company>微软</o:Company> <o:Version>11.5606</o:Version> </o:DocumentProperties> </xml><![endif]--> <style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .75in 1.0in .75in; mso-header-margin:.5in; mso-footer-margin:.5in;} tr {mso-height-source:auto; mso-ruby-visibility:none;} col {mso-width-source:auto; mso-ruby-visibility:none;} br {mso-data-placement:same-cell;} .style0 {mso-number-format:General; text-align:general; vertical-align:middle; white-space:nowrap; mso-rotate:0; mso-background-source:auto; mso-pattern:auto; color:windowtext; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; border:none; mso-protection:locked visible; mso-style-name:常规; mso-style-id:0;} td {mso-style-parent:style0; padding:0px; mso-ignore:padding; color:windowtext; font-size:12.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; mso-number-format:General; text-align:general; vertical-align:middle; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} .xl24 {mso-style-parent:style0; white-space:normal;} ruby {ruby-align:left;} rt {color:windowtext; font-size:9.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:宋体; mso-generic-font-family:auto; mso-font-charset:134; mso-char-type:none; display:none;} --> </style> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>Sheet1</x:Name> <x:WorksheetOptions> <x:DefaultRowHeight>285</x:DefaultRowHeight> <x:Selected/> <x:Panes> <x:Pane> <x:Number>3</x:Number> <x:ActiveRow>2</x:ActiveRow>//默认选中的行 <x:ActiveCol>2</x:ActiveCol>//默认选中的列 </x:Pane> </x:Panes> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>Sheet2</x:Name> <x:WorksheetOptions> <x:DefaultRowHeight>285</x:DefaultRowHeight> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> <x:ExcelWorksheet> <x:Name>Sheet3</x:Name> <x:WorksheetOptions> <x:DefaultRowHeight>285</x:DefaultRowHeight> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> <x:WindowHeight>9225</x:WindowHeight> <x:WindowWidth>17100</x:WindowWidth> <x:WindowTopX>120</x:WindowTopX> <x:WindowTopY>105</x:WindowTopY> <x:ProtectStructure>False</x:ProtectStructure> <x:ProtectWindows>False</x:ProtectWindows> </x:ExcelWorkbook> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="1027"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--> </head> <body link=blue vlink=purple> //正文内容 <table x:str border=0 cellpadding=0 cellspacing=0 width=912 style='border-collapse: collapse;table-layout:fixed;width:684pt'> <col width=72 style='width:54pt'> <col width=237 style='mso-width-source:userset;mso-width-alt:7584;width:178pt'> <col width=215 style='mso-width-source:userset;mso-width-alt:6880;width:161pt'> <col width=28 style='mso-width-source:userset;mso-width-alt:896;width:21pt'> <col width=72 span=5 style='width:54pt'> <tr height=76 style='height:57.0pt'><!--数据列--> <td height=76 width=72 style='height:57.0pt;width:54pt'>萨地方</td> <td class=xl24 width=237 style='width:178pt'>阿送大幅大赛sadf<br> dsafsafds<br> <><''"><br> afdsa----</td> <td align=right width=215 style='width:161pt' x:num>1</td> <td width=28 style='width:21pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 align=right style='height:14.25pt' x:num>2</td> <td align=right x:num>2</td> <td align=right x:num>2</td> <td colspan=6 style='mso-ignore:colspan'></td> </tr> <tr height=57 style='height:42.75pt;mso-xlrowspan:3'> <td height=57 colspan=9 style='height:42.75pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> <td colspan=7 rowspan=14 height=266 width=603 style='mso-ignore:colspan-rowspan; height:199.5pt;width:452pt'><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_s1026" type="#_x0000_t75" style='position:absolute; margin-left:68.25pt;margin-top:7.5pt;width:347.25pt;height:186pt;z-index:1' fillcolor="windowText [64]" strokecolor="window [65]" strokeweight="3e-5mm" o:insetmode="auto"> <v:fill color2="window [65]"/> <v:imagedata src="Book1.files/image001.png" o:title=""/> <x:ClientData ObjectType="Pict"> <x:MoveWithCells/> <x:SizeWithCells/> <x:Locked>False</x:Locked> <x:AutoFill>False</x:AutoFill> <x:AutoLine>False</x:AutoLine> <x:CF>Bitmap</x:CF> </x:ClientData> </v:shape><![endif]--><![if !vml]><span style='mso-ignore:vglayout'> <table cellpadding=0 cellspacing=0> <tr> <td width=91 height=10></td> </tr> <tr> <td></td> <td><img width=463 height=248 src="Book1.files/image002.jpg" v:shapes="_x0000_s1026"></td> <td width=49></td> </tr> <tr> <td height=8></td> </tr> </table> </span><![endif]><!--[if !mso & vml]><span style='width:452.25pt;height:199.5pt'></span><![endif]--></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <tr height=19 style='height:14.25pt'> <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td> </tr> <![if supportMisalignedColumns]> <tr height=0 style='display:none'> <td width=72 style='width:54pt'></td> <td width=237 style='width:178pt'></td> <td width=215 style='width:161pt'></td> <td width=28 style='width:21pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> <td width=72 style='width:54pt'></td> </tr> <![endif]> </table> </body> </html>
在项目中,我们可以先定制出一个excel模板并填充一两条数据(比如包含头、体、尾),在输出的时候,我们只需要把正文内容(文件体)那一部分用JAVA的IO输出就可以了,如果数据量很大,可以每隔一段时间就flush一下。
至此,可通过数据生成如上格式的HTML文本信息则避开大量对象的建立,如果将该HTML直接以application/excel返回浏览器时则Excel文件会比普通大一点,可以通过配置过滤器对该HTML进行压缩即可,如下:
response.reset(); response.setContentType("application/zip;charset=GBK"); String s = "查询-" + new java.sql.Date(System.currentTimeMillis()).toString().replaceAll("-","") + ".xls"; String filename = s + ".zip"; response.addHeader("Content-Disposition", "inline;filename=" + filename);
---简单总结----
先建一个excel文件,如a.xls。填上两条伪数据。然后另存为网页,即htm格式,如a.htm。
然后,用记事本打开htm格式的a.htm,这样excel文件格式代码就暴露在你面前。
剩下的事,就是把a.htm源代码的伪数据部分,替成数据库里的数据,然后把替换后的整个a.htm源代码,用java的io写成一个后缀为xls的文件。就打完收工了。
注意:为了不给内存增加压力,要把a.htm源代码分成三部分:头(伪数据部分 前的代码) + 伪数据部分 + 尾(伪数据部分 后的代码)。
先把 头 写到文件,并flush。然后是 伪数据部分 ,替一条数据库里的记录就写到文件里,并flush。最后把 尾 写到文件,并flush。
重点就是要经常flush,不然数据大就OOM了;另外如果使用了list取数据,在使用完以后要及时list.clear().
不同版本下Excel数据量极限:
excel2000的工作表中最大只能有65536行数据,每一行最大只能有256列
2003下
行:65536
列:IV即230
2007下
行:1048576
列:XFD,26进制,16384列.
(在excel中atrl+shift+右箭头 atrl+shift+下箭头即可查看)
评论
这里说的是导出,至于打开慢,就和offie有关了。
ps:剑走偏锋,你可以设置一下response的head,弹出下载窗口而不是直接打开,这样就不会显得应用反应慢了。
发表评论
-
linux、win下用jmx监控tomcat运行情况
2012-03-14 15:52 1590for windows: 1、add below lin ... -
[转]Java缩略图类带水印(jpg,png)
2011-08-31 09:09 1503package com.example; import ... -
swing和awt的两个简单使用
2011-08-29 13:27 11651、swing: package frame; ... -
[转]笔记:Hibernate性能优化事项(持续更新)
2011-08-27 10:38 15711、针对Oracle数据库而言 ... -
自定义classloader实现
2011-08-09 14:19 1389package classloader; import ... -
[总结篇]Java中从键盘接收一个字符
2011-05-29 21:53 2131引言 从控制台中读 ... -
利用commons-net包实现ftp上传下载例子
2011-01-19 16:50 3975下载文件的时候注意一下,第一个参数要用iso-8859_ ... -
请使用Oracle新版本驱动
2010-11-09 11:08 2517今天使用apache dbutils连接oracle10G时, ... -
关于使用JS前台加密、JAVA后台解密的RSA实现,RSA加密和签名
2010-10-25 16:07 37649需求环境: 西安项目中,客户要求保护用户的密码信息,不 ... -
使用java.net.URL实现Post数据
2010-07-20 10:38 5924实现:利用URL访问URL并传递参数,然后获取返回结果。 可 ... -
java文件锁的实现
2010-07-02 16:37 7086项目使用到集群环境,流程发送时如果确保一个流程不会被两个流程同 ... -
Log4j使用总结
2010-01-09 09:50 925一、介绍 Log4j是Apa ... -
servlet下载文件不支持迅雷的解决方法
2009-11-18 13:42 3756servlet实现下载时,如果客户端安装了迅雷,发现不能正确下 ... -
JMS-ActiveMQ入门实例
2009-11-04 11:49 7172下载ActiveMQ http://activemq.a ... -
Lucene+HighLighter高亮显示实例
2009-11-03 18:37 5168今天搞了一个关于Lucene的例子,权当入门教程。网上有很多资 ... -
JAVA操作Excel参考
2009-11-03 10:33 980Java Excel是一开放源码项目,通过它Java开发人 ... -
freemarker根据模板生成文件的编码问题
2009-10-20 15:46 2572用freemarker生成html静态文件时,涉及的编码主要有 ... -
RSS基本知识、开发相关
2009-09-27 11:43 1193RSSLibJ是一个专门读 ... -
Ant+xFire生成客户端代码实战
2009-09-12 16:41 2693生成xfire客户端有多种方式,直接调用xFire暴露的接口、 ... -
Spring中JdbcTemplate相关的几个接口
2009-09-07 16:48 19201、org.springframew ...
相关推荐
Java_批量导出大数据量Excel方法.zip
这是我在公司实习的时候研究的课题,主要将大量数据从数据库导出到Excel文件。(一般是值Excel2007及以后版本)因为Excel2003及以前的版本中能保持的数据量是有限制的。Excel2007及以后版本中的数据能保持100万条...
导出大量数据到excel,本人已亲测,对几百万数据已测试过,导出数据比较乐观,里面自带压缩文件功能。
其次,在实验过程中,大数据量的导出很容易引发内存溢出,调整JVM的内存大小治标不治本。很多人建议保存为.CSV格式的文件。不过,.CSV方式导出也存在问题:首先,如果用excel来打开csv,超过65536行的数据都会看不见...
直接可以用的项目。数据量大,导出多个excel然后压缩成zip文件。。。
Excel数据批量导入与Excel文件的导出,Excel数据批量导入与Excel文件的导出
C#快速导出Excel文件,3秒可导10万行数据
java中将数据和图片导出到Excel文件
目前java框架中能够生成excel文件的的确不少,但是,能够生成大数据量的excel框架,我倒是没发现,一般数据量大了都会出现内存溢出,所以,生成大数据量的excel文件要返璞归真,用java的基础技术,IO流来实现。...
js 导出 Excel 【支持大量数据导出,亲测】、支持IE噢
30万的数据量,生成多个excel最后打包成zip下载,是工程,直接导入就行
plsql导出数据到excel常用的三种方法,(1)直接导出;(2)转换导出方式;(3)导出后转换格式;
java解决大批量数据导出Excel产生内存溢出的方案
轻松解决普通poi形式导出Excel的中出现的栈溢出问题,此资源可实现千万级数据分批导出csv文件,csv大数据量导出(千万级别,不会内存溢出),多线程导出 ,生产环境已经很稳定的使用着
背景:今天要把DataSet导入Excel,查询以前的贴子,一部分用Ole,速度太慢, 一部分用ADO连接到Excel文件,也很慢,一气之下把DBGrigEh的导出部分改了出来, 欢迎大家指教、改进。 功能:将数据集的数据...
本程序可以快速导出数据到EXCEL 测试环境celeron 3GHZ,512ram,xp 10000条数据15秒左右 可以自定义输出模板,在EXCEL定义好模板直接另存为.html文件即可 模板格式见例子模板
用开源 Apache POI 技术导出Excel,解决导出大数据出现OOM、栈溢出问题,此资源可实现百万级数据多线程分批导出Excel文件,不会内存溢出,生产环境已很稳定的使用者,所以用到的技术很核心、值得参考
我们经常会使用phpExcel导入或导入xls文件,但是如果一次导出数据比较大就会出现内存溢出错误,下面我来总结解决办法
对大数据量的导出excel,用多线程,用倒数计数器对文件进行生成,使用poi,可以支持大数据量的生成,项目中使用的poi是3.1的,上传的是4.1的。
TIA博途V17中DB块如何导出成源文件或XML文件或EXCEL中? 博途中导出DB块的3种方法介绍。