|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
|
|
<head> |
|
|
|
<link rel="canonical" href="http://blog.csdn.net/jerehedu/article/details/45195359"/> |
|
<meta http-equiv="Cache-Control" content="no-siteapp" /><link rel="alternate" media="handheld" href="#" /> |
|
|
|
<title>Java中导入、导出Excel |
|
- 博客频道 - CSDN.NET</title> |
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
<meta name="description" content="一、介绍 当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统、银行系统)。或者是:我们已经习惯用Excel打印。这样在我们实际的开发中,很多时候需要实现导入、导出Excel的应用。 目前,比较常用的实现Java导入、导出Excel的技术有两种Jakarta POI和Java Excel 下面我就" /> |
|
|
|
<script src="http://static.blog.csdn.net/scripts/blog_static_head.min.js" type="text/javascript"></script> |
|
|
|
|
|
|
|
<link rel="stylesheet" href="http://c.csdnimg.cn/public/common/toolbar/css/index.css"> |
|
|
|
|
|
<script language="javascript" type="text/javascript" src="http://ads.csdn.net/js/tracking.js"></script> |
|
|
|
|
|
<link rel="Stylesheet" type="text/css" href="http://static.blog.csdn.net/skin/skin-white/css/style.css?v=1.1" /> |
|
|
|
|
|
|
|
<link id="RSSLink" title="RSS" type="application/rss+xml" rel="alternate" href="/JerehEdu/rss/list" /> |
|
<link rel="shortcut icon" href="http://c.csdnimg.cn/public/favicon.ico" /> |
|
<link type="text/css" rel="stylesheet" href="http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/default.css" /> |
|
|
|
|
|
|
|
<link rel="stylesheet" href="http://static.blog.csdn.net/css/csdn_blog_detail.min.css" /> |
|
|
|
<script src="http://c.csdnimg.cn/rabbit/tracking-ad/fuckadblock.js" type="text/javascript" charset="utf-8"></script> |
|
<script src="http://c.csdnimg.cn/rabbit/tracking-ad/block.js" type="text/javascript" charset="utf-8"></script> |
|
|
|
|
|
</head> |
|
|
|
|
|
<body> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script id="toolbar-tpl-scriptId" fixed="true" prod="blog" skin="black" src="http://c.csdnimg.cn/public/common/toolbar/js/html.js" type="text/javascript"></script> |
|
|
|
<div id="container"> |
|
<div id="header"> |
|
<div class="header"> |
|
<div id="blog_title"> |
|
<h2> |
|
<a href="http://blog.csdn.net/jerehedu">杰瑞教育</a></h2> |
|
<h3>致力IT培训领域,打造一流人才服务平台</h3> |
|
<div class="clear"> |
|
</div> |
|
</div> |
|
<div class="clear"> |
|
</div> |
|
|
|
|
|
</div> |
|
</div> |
|
<div id="navigator"> |
|
<div class="navigator_bg"> |
|
</div> |
|
<div class="navigator"> |
|
<ul> |
|
<li id="btnContents"><a href="http://blog.csdn.net/jerehedu?viewmode=contents"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_mulu'])"> |
|
<img src="http://static.blog.csdn.net/images/ico_list.gif">目录视图</span></a></li> |
|
<li id="btnView"><a href="http://blog.csdn.net/jerehedu?viewmode=list"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_zhaiyao'])"> |
|
<img src="http://static.blog.csdn.net/images/ico_summary.gif">摘要视图</span></a></li> |
|
<li id="btnRss"><a href="http://blog.csdn.net/jerehedu/rss/list"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_RSS'])"> |
|
<img src="http://static.blog.csdn.net/images/ico_rss.gif">订阅</span></a></li> |
|
|
|
|
|
</ul> |
|
</div> |
|
</div> |
|
<script type="text/javascript"> |
|
var username = "JerehEdu"; |
|
var _blogger = username; |
|
var blog_address = "http://blog.csdn.net/jerehedu"; |
|
var static_host = "http://static.blog.csdn.net"; |
|
var currentUserName = "lzl110110"; |
|
</script> |
|
|
|
<div id="body"> |
|
<div id="main"> |
|
<div class="main"> |
|
<div class="ad_class"> |
|
<div class="notice tracking-ad" data-mod='popu_3' > |
|
|
|
|
|
<a href="http://blog.csdn.net/blogdevteam/article/details/71710010"> |
|
<font color=blue><strong>【活动】2017 CSDN博客专栏评选</strong></font></a> |
|
|
|
  |
|
|
|
<a href=" http://blog.csdn.net/broadview2006/article/details/72677185"> |
|
<font color=red><strong>【评论送书】SQL优化、深度学习、数据科学家</strong></font></a> |
|
  |
|
|
|
<a href="http://blog.csdn.net/blogdevteam/article/details/72725354"> |
|
<font color=blue><strong>CSDN日报20170525 ——《狗蛋的寻亲之路,结识嵌入式世界的那只狗》 |
|
</strong></font></a> |
|
|
|
  |
|
|
|
<a href=" http://blog.csdn.net/blogdevteam/article/details/72626843"> |
|
<font color=red><strong>Python创意编程活动结果公布</strong></font></a> |
|
|
|
|
|
</div> </div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/category.js"></script> |
|
|
|
<script type="text/ecmascript"> |
|
window.quickReplyflag = true; |
|
|
|
var isBole = false; |
|
|
|
|
|
var fasrc="http://my.csdn.net/my/favorite/miniadd?t=Java%e4%b8%ad%e5%af%bc%e5%85%a5%e3%80%81%e5%af%bc%e5%87%baExcel&u=http://blog.csdn.net/jerehedu/article/details/45195359" |
|
|
|
</script> |
|
<div id="article_details" class="details"> |
|
<div class="article_title"> |
|
<span class="ico ico_type_Original"></span> |
|
|
|
|
|
<h1> |
|
<span class="link_title"><a href="/jerehedu/article/details/45195359"> |
|
Java中导入、导出Excel |
|
</a></span> |
|
</h1> |
|
</div> |
|
|
|
|
|
|
|
<div class="article_manage clearfix"> |
|
<div class="article_r"> |
|
<span class="link_postdate">2015-04-22 15:03</span> |
|
<span class="link_view" title="阅读次数">2110人阅读</span> |
|
<span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(1)</span> |
|
<span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('Java%e4%b8%ad%e5%af%bc%e5%85%a5%e3%80%81%e5%af%bc%e5%87%baExcel','45195359');return false;" title="收藏">收藏</a></span> |
|
<span class="link_report"> <a href="#report" onclick="javascript:report(45195359,2);return false;" title="举报">举报</a></span> |
|
|
|
</div> |
|
</div> |
|
<div class="embody" style="display:none" id="embody"> |
|
<span class="embody_t">本文章已收录于:</span> |
|
<div class="embody_c" id="lib" value="{"err":0,"msg":"ok","data":[]}"></div> |
|
</div> |
|
<style type="text/css"> |
|
.embody{ |
|
padding:10px 10px 10px; |
|
margin:0 -20px; |
|
border-bottom:solid 1px #ededed; |
|
} |
|
.embody_b{ |
|
margin:0 ; |
|
padding:10px 0; |
|
} |
|
.embody .embody_t,.embody .embody_c{ |
|
display: inline-block; |
|
margin-right:10px; |
|
} |
|
.embody_t{ |
|
font-size: 12px; |
|
color:#999; |
|
} |
|
.embody_c{ |
|
font-size: 12px; |
|
} |
|
.embody_c img,.embody_c em{ |
|
display: inline-block; |
|
vertical-align: middle; |
|
} |
|
.embody_c img{ |
|
width:30px; |
|
height:30px; |
|
} |
|
.embody_c em{ |
|
margin: 0 20px 0 10px; |
|
color:#333; |
|
font-style: normal; |
|
} |
|
</style> |
|
<script type="text/javascript"> |
|
$(function () { |
|
try |
|
{ |
|
var lib = eval("("+$("#lib").attr("value")+")"); |
|
var html = ""; |
|
if (lib.err == 0) { |
|
$.each(lib.data, function (i) { |
|
var obj = lib.data[i]; |
|
//html += '<img src="' + obj.logo + '"/>' + obj.name + " "; |
|
html += ' <a href="' + obj.url + '" target="_blank">'; |
|
html += ' <img src="' + obj.logo + '">'; |
|
html += ' <em><b>' + obj.name + '</b></em>'; |
|
html += ' </a>'; |
|
}); |
|
if (html != "") { |
|
setTimeout(function () { |
|
$("#lib").html(html); |
|
$("#embody").show(); |
|
}, 100); |
|
} |
|
} |
|
} catch (err) |
|
{ } |
|
|
|
}); |
|
</script> |
|
<div class="category clearfix"> |
|
<div class="category_l"> |
|
<img src="http://static.blog.csdn.net/images/category_icon.jpg"> |
|
<span>分类:</span> |
|
</div> |
|
<div class="category_r"> |
|
<label onclick="GetCategoryArticles('2807947','JerehEdu','top','45195359');"> |
|
<span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">java技术分享<em>(14)</em></span> |
|
<img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;"> |
|
<img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;"> |
|
<div class="subItem"> |
|
<div class="subItem_t"><a href="http://blog.csdn.net/JerehEdu/article/category/2807947" target="_blank">作者同类文章</a><i class="J_close">X</i></div> |
|
<ul class="subItem_l" id="top_2807947"> |
|
</ul> |
|
</div> |
|
</label> |
|
</div> |
|
</div> |
|
<div class="bog_copyright"> |
|
<p class="copyright_p" >版权声明:本文为博主原创文章,未经博主允许不得转载。</p> |
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div id="article_content" class="article_content tracking-ad" data-mod=popu_307 data-dsm = "post" > |
|
|
|
<table border="0" style="border:0px solid #000000; border-collapse:collapse; word-break:break-word; color:#333333; font-family:Georgia,'Times New Roman',Times,sans-serif; font-size:14px; line-height:25px; width:100%; height:38px; background-color:#1570a6"> |
|
<tbody> |
|
<tr> |
|
<td style="border-style:solid; border-color:silver; border-collapse:collapse; padding:3px"> |
|
<span style="font-family:'Microsoft YaHei'"><strong><span style="color:#ffffff; font-size:14pt">一、介绍</span></strong></span></td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"> 当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统、银行系统)。或者是:我们已经习惯用Excel打印。这样在我们实际的开发中,很多时候需要实现导入、导出Excel的应用。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 目前,比较常用的实现Java导入、导出Excel的技术有两种Jakarta POI和Java Excel</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 下面我就分别讲解一下如何使用这两个技术实现导入、导出Excel</span></p> |
|
<table border="0" style="border:0px solid #000000; border-collapse:collapse; word-break:break-word; color:#333333; font-family:Georgia,'Times New Roman',Times,sans-serif; font-size:14px; line-height:25px; width:100%; height:38px; background-color:#1570a6"> |
|
<tbody> |
|
<tr> |
|
<td style="border-style:solid; border-color:silver; border-collapse:collapse; padding:3px"> |
|
<span style="font-family:'Microsoft YaHei'"><strong><span style="color:#ffffff; font-size:14pt">二、使用Jakarta POI导入、导出Excel</span></strong></span></td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> Jakarta POI 是一套用于访问微软格式文档的Java API。Jakarta POI有很多组件组成,其中有用于操作Excel格式文件的HSSF和用于操作Word的HWPF,在各种组件中目前只有用于操作Excel的HSSF相对成熟。官方主页<a target="_blank" href="http://poi.apache.org/index.html">http://poi.apache.org/index.html</a>,API文档<a target="_blank" href="http://poi.apache.org/apidocs/index.html">http://poi.apache.org/apidocs/index.html</a></span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.1 环境配置</h3> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2.1.1下载jar</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 官方下载:<a target="_blank" href="http://poi.apache.org/download.html">http://poi.apache.org/download.html</a>这里可以下载到它的最新版本和文档,目前最新版本是3.7,这里使用比较稳定的3.6版。</span></p> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2.1.2加入jar包</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 将根目录下的poi-3.6-20091214.jar和Lib目录下三个通用包 commons-logging-1.1.jar junit-3.8.1.jar log4j-1.2.13.jar拷贝到项目的Lib下</span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.2 Jakarta POI HSSF API组件</h3> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"> HSSF(用于操作Excel的组件)提供给用户使用的对象在rg.apache.poi.hssf.usermodel包中,主要部分包括Excel对象,样式和格式,还有辅助操作。有以下几种对象:</span><span style="font-family:'Microsoft YaHei'"> </span></p> |
|
<blockquote> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"><strong>常用组件:</strong></span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFWorkbook excel的文档对象</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFSheet excel的表单</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFRow excel的行</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFCell excel的格子单元</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFFont excel字体</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFDataFormat 日期格式</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFHeader sheet头</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFFooter sheet尾(只有打印的时候才能看到效果)</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"><strong>样式:</strong></span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFCellStyle cell样式</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"><strong>辅助操作包括:</strong></span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFDateUtil 日期</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFPrintSetup 打印</span></p> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px">HSSFErrorConstants 错误信息表</span></p> |
|
</blockquote> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.3 基本操作步骤</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 首先,理解一下一个Excel的文件的组织形式,一个Excel文件对应于一个workbook(HSSFWorkbook),一个workbook可以有多个sheet(HSSFSheet)组成,一个sheet是由多个row(HSSFRow)组成,一个row是由多个cell(HSSFCell)组成。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> <strong>基本操作步骤:</strong></span></p> |
|
<blockquote> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">1、用HSSFWorkbook打开或者创建“Excel文件对象”</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">2、用HSSFWorkbook对象返回或者创建Sheet对象</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">3、用Sheet对象返回行对象,用行对象得到Cell对象</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">4、对Cell对象读写。</span></p> |
|
</blockquote> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 下面来看一个动态生成Excel文件的例子:</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">//创建HSSFWorkbook对象 |
|
HSSFWorkbook wb = new HSSFWorkbook(); |
|
//创建HSSFSheet对象 |
|
HSSFSheet sheet = wb.createSheet("sheet0"); |
|
//创建HSSFRow对象 |
|
HSSFRow row = sheet.createRow(0); |
|
//创建HSSFCell对象 |
|
HSSFCell cell=row.createCell(0); |
|
//设置单元格的值 |
|
cell.setCellValue("单元格中的中文"); |
|
//输出Excel文件 |
|
FileOutputStream output=new FileOutputStream("d:\\workbook.xls"); |
|
wkb.write(output); |
|
output.flush();</pre></pre> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> HSSF读取文件同样还是使用这几个对象,只是把相应的createXXX方法变成了getXXX方法即可。可见只要理解了其中原理,不管是读还是写亦或是特定格式都可以轻松实现,正所谓知其然更要知其所以然。</span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.4 导出Excel应用实例</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; line-height:1.5"> 在2.3中我们寥寥几行代码实际上就已经就是实现了导出Excel一个简单示例,下面我们在看如何实现导出如图所示的Excel表格?</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; line-height:1.5"><img src="http://images.cnitblog.com/blog2015/708076/201503/170838550954408.png" alt=""></span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; line-height:1.5"> 代码如下:(实际开发中应封装到业务层组件中,然后在控制层中调用。这里直接写在控制层组件,如Servlet的doGet/doPost方法或Struts框架的execute方法中)</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">//创建HSSFWorkbook对象(excel的文档对象) |
|
HSSFWorkbook wb = new HSSFWorkbook(); |
|
//建立新的sheet对象(excel的表单) |
|
HSSFSheet sheet=wkb.createSheet("成绩表"); |
|
//在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个 |
|
HSSFRow row1=sheet.createRow(0); |
|
//创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个 |
|
HSSFCell cell=row1.createCell(0); |
|
//设置单元格内容 |
|
cell.setCellValue("学员考试成绩一览表"); |
|
//合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列 |
|
sheet.addMergedRegion(new CellRangeAddress(0,0,0,3)); |
|
//在sheet里创建第二行 |
|
HSSFRow row2=sheet.createRow(1); |
|
//创建单元格并设置单元格内容 |
|
row2.createCell(0).setCellValue("姓名"); |
|
row2.createCell(1).setCellValue("班级"); |
|
row2.createCell(2).setCellValue("笔试成绩"); |
|
row2.createCell(3).setCellValue("机试成绩"); |
|
//在sheet里创建第三行 |
|
HSSFRow row3=sheet.createRow(2); |
|
row3.createCell(0).setCellValue("李明"); |
|
row3.createCell(1).setCellValue("As178"); |
|
row3.createCell(2).setCellValue(87); |
|
row3.createCell(3).setCellValue(78); |
|
//.....省略部分代码 |
|
|
|
|
|
//输出Excel文件 |
|
OutputStream output=response.getOutputStream(); |
|
response.reset(); |
|
response.setHeader("Content-disposition", "attachment; filename=details.xls"); |
|
response.setContentType("application/msexcel"); |
|
wkb.write(output); |
|
output.close(); |
|
retrun null;</pre></pre> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 加下划线这部分代码是B/S模式中采用的输出方式,而不是输出到本地指定的磁盘目录。该代码表示将details.xls的Excel文件通过应答实体(response)输出给请求的客户端浏览器,客户端可保存或直接打开。</span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.5 样式设置</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 在实际应用中导出的Excel文件往往需要阅读和打印的,这就需要对输出的Excel文档进行排版和样式的设置,主要操作有合并单元格、设置单元格样式、设置字体样式等。</span></p> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2.5.1单元格合并</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 使用HSSFSheet的addMergedRegion()方法</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">public int addMergedRegion(CellRangeAddress region)</pre></pre> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 参数CellRangeAddress 表示合并的区域,构造方法如下:</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)</pre></pre> |
|
</div> |
|
<p class="p0"><span style="font-family:'Microsoft YaHei'; font-size:14px"> 构造参数依次表示起始行,截至行,起始列, 截至列。</span><span style="font-family:'Microsoft YaHei'">示例代码参照2.4部分</span></p> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px">2.5.2设置单元格的行高、列宽</span></h3> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">HSSFSheet sheet=wb.createSheet(); |
|
|
|
sheet.setDefaultRowHeightInPoints(10);//设置缺省列高sheet.setDefaultColumnWidth(20);//设置缺省列宽 |
|
|
|
//设置指定列的列宽,256 * 50这种写法是因为width参数单位是单个字符的256分之一 |
|
|
|
sheet.setColumnWidth(cell.getColumnIndex(), 256 * 50);</pre></pre> |
|
</div> |
|
</div> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2.5.2单元格样式</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 1、创建HSSFCellStyle</span></p> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java"> HSSFCellStyle cellStyle=wkb.createCellStyle()</pre></pre> |
|
</div> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2、设置样式</span></p> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java"> // 设置单元格的横向和纵向对齐方式,具体参数就不列了,参考HSSFCellStyle |
|
|
|
cellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY); |
|
|
|
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); |
|
|
|
/* 设置单元格的填充方式,以及前景颜色和背景颜色 |
|
|
|
三点注意: |
|
|
|
1.如果需要前景颜色或背景颜色,一定要指定填充方式,两者顺序无所谓; |
|
|
|
2.如果同时存在前景颜色和背景颜色,前景颜色的设置要写在前面; |
|
|
|
3.前景颜色不是字体颜色。 |
|
|
|
*/ |
|
|
|
//设置填充方式(填充图案) |
|
|
|
cellStyle.setFillPattern(HSSFCellStyle.DIAMONDS); |
|
|
|
//设置前景色 |
|
|
|
cellStyle.setFillForegroundColor(HSSFColor.RED.index); |
|
|
|
//设置背景颜色 |
|
|
|
cellStyle.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index); |
|
|
|
// 设置单元格底部的边框及其样式和颜色 |
|
|
|
// 这里仅设置了底边边框,左边框、右边框和顶边框同理可设 |
|
|
|
cellStyle.setBorderBottom(HSSFCellStyle.BORDER_SLANTED_DASH_DOT); |
|
|
|
cellStyle.setBottomBorderColor(HSSFColor.DARK_RED.index); |
|
|
|
//设置日期型数据的显示样式 |
|
|
|
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); </pre></pre> |
|
</div> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3、将样式应用于单元格</span></p> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java"> cell.setCellStyle(cellStyle); |
|
|
|
//将样式应用到行,但有些样式只对单元格起作用 |
|
|
|
row.setRowStyle(cellStyle);</pre></pre> |
|
</div> |
|
</div> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2.5.2设置字体样式</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 1、创建HSSFFont对象(调用HSSFWorkbook 的createFont方法)</span></p> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">HSSFWorkbook wb=new HSSFWorkbook(); |
|
|
|
HSSFFont fontStyle=wb.createFont(); |
|
|
|
HSSFWorkbook wb=new HSSFWorkbook ();</pre></pre> |
|
</div> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 2、设置字体各种样式</span></p> |
|
<div> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java"> //设置字体样式 |
|
|
|
fontStyle.setFontName("宋体"); |
|
|
|
//设置字体高度 |
|
|
|
fontStyle.setFontHeightInPoints((short)20); |
|
|
|
//设置字体颜色 |
|
|
|
font.setColor(HSSFColor.BLUE.index); |
|
|
|
//设置粗体 |
|
|
|
fontStyle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
|
|
|
//设置斜体 |
|
|
|
font.setItalic(true); |
|
|
|
//设置下划线 |
|
|
|
font.setUnderline(HSSFFont.U_SINGLE);</pre></pre> |
|
</div> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3、将字体设置到单元格样式</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"></span><pre name="code" class="java">//字体也是单元格格式的一部分,所以从属于HSSFCellStyle |
|
|
|
// 将字体对象赋值给单元格样式对象 |
|
|
|
cellStyle.setFont(font); |
|
|
|
// 将单元格样式应用于单元格 |
|
|
|
cell.setCellStyle(cellStyle);</pre></p> |
|
<div class="cnblogs_code"> |
|
<pre></pre> |
|
</div> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
2.6 导入Excel应用实例</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 实现将已存在的Excel文件中的数据导入到系统中的基本步骤同导出十分的类似,关键在于要了解要导入Excel文件的结构,比如数据有哪些列、读取数据起始位置(有效数据从第几行几列开始)等。在实际项目中由于这些数据(Excel文件)往往来自于日常办公人员或其他系统平台产生的业务数据,因此这些Excel文件的数据格式要有统一的要求,并提供访问接口(指访问途径),这样在所需数据的系统中就可通过提供这个访问接口调用方法,从而获得数据。解决方案采用Web |
|
Service是不错的选择。这里,我们就以导入2..4所产生的excel表为例,重点掌握如何编写导入Excel代码</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">public List<ScoreInfo> loadScoreInfo(String xlsPath) throws IOException{ |
|
List temp = new ArrayList(); |
|
FileInputStream fileIn = new FileInputStream(xlsPath); |
|
//根据指定的文件输入流导入Excel从而产生Workbook对象 |
|
Workbook wb0 = new HSSFWorkbook(fileIn); |
|
//获取Excel文档中的第一个表单 |
|
Sheet sht0 = wb0.getSheetAt(0); |
|
//对Sheet中的每一行进行迭代 |
|
for (Row r : sht0) { |
|
//如果当前行的行号(从0开始)未达到2(第三行)则从新循环 |
|
If(r.getRowNum()<1){ |
|
continue; |
|
} |
|
//创建实体类 |
|
ScoreInfo info=new ScoreInfo(); |
|
//取出当前行第1个单元格数据,并封装在info实体stuName属性上 |
|
info.setStuName(r.getCell(0).getStringCellValue()); |
|
info.setClassName(r.getCell(1).getStringCellValue()); |
|
info.setRscore(r.getCell(2).getNumericCellValue()); |
|
info.setLscore(r.getCell(3).getNumericCellValue()); |
|
temp.add(info); |
|
} |
|
fileIn.close(); |
|
return temp; |
|
}</pre></pre> |
|
</div> |
|
<table border="0" style="border:0px solid #000000; border-collapse:collapse; word-break:break-word; color:#333333; font-family:Georgia,'Times New Roman',Times,sans-serif; font-size:14px; line-height:25px; width:100%; height:38px; background-color:#1570a6"> |
|
<tbody> |
|
<tr> |
|
<td style="border-style:solid; border-color:silver; border-collapse:collapse; padding:3px"> |
|
<span style="font-family:'Microsoft YaHei'"><strong><span style="color:#ffffff; font-size:14pt">三、使用java Excel操作Excel文件</span></strong></span></td> |
|
</tr> |
|
</tbody> |
|
</table> |
|
<p style="text-align:left"> <span style="font-family:'Microsoft YaHei'">Java Excel是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容、创建新的Excel文件、更新已经存在的Excel文件。jxl 由于其小巧 易用的特点, 逐渐已经取代了 POI-excel的地位, 成为了越来越多的java开发人员生成excel文件的首选。Java Excel的特征:</span></p> |
|
<blockquote> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">● 支持Excel 95-2000的所有版本 |
|
</span><br> |
|
<span style="font-family:'Microsoft YaHei'; font-size:14px"> ● 生成Excel 2000标准格式 |
|
</span><br> |
|
<span style="font-family:'Microsoft YaHei'; font-size:14px"> ● 支持字体、数字、日期格式化操作 |
|
</span><br> |
|
<span style="font-family:'Microsoft YaHei'; font-size:14px"> ● 支持对单元格加阴影和加色彩; |
|
</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">● 修改存在的工作表;</span><br> |
|
<span style="font-family:'Microsoft YaHei'; font-size:14px"> ● 支持图像和图表 </span> |
|
</p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">● 日志记录可以定制</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">● 更小更快更省内存</span></p> |
|
</blockquote> |
|
<p style="text-align:left"><span style="font-family:'Microsoft YaHei'; font-size:14px"> 应该说以上功能已经能够大致满足我们的需要。最关键的是这套API是纯Java的,并不依赖Windows系统,即使运行在Linux下,它同样能够正确的处理Excel文件。另外需要说明的是,这套API对图形和图表的支持很有限,而且仅仅识别PNG格式。在线帮助文档</span><span style="font-family:'Microsoft YaHei'"><a target="_blank" href="http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/index.html">http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/index.html</a></span></p> |
|
<p style="text-align:left"><span style="font-family:'Microsoft YaHei'; font-size:14px"> 在这里我们将通过一些实例,学习掌握读取、新建、更新,其中也包括常见格式的设置:字体、颜色、背景、合并单元格等操作,有这些其实已经基本足够应付大部分问题了。</span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
3.1环境配置</h3> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3.1.1下载</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 下载地址 <a target="_blank" href="http://www.andykhan.com/jexcelapi/"> |
|
http://www.andykhan.com/jexcelapi/</a></span></p> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3.1.2 加入jar包</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 将jxl.jar拷贝到项目的Lib下</span></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
3.2 使用Java Excel Api 导出 Excel文件</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 下面我们在看如何使用Java Excel实现导出Excel表格?</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 代码如下:(实际开发中应封装到业务层组件中,然后在控制层中调用。这里直接写在控制层组件,如Servlet的doGet/doPost方法或Struts框架的execute方法中)</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"></span><pre name="code" class="java">//获得输出流,该输出流的输出介质是客户端浏览器 |
|
|
|
OutputStream output=response.getOutputStream(); |
|
|
|
response.reset(); |
|
|
|
response.setHeader("Content-disposition","attachment; filename=temp.xls"); |
|
|
|
response.setContentType("application/msexcel"); |
|
|
|
//创建可写入的Excel工作薄,且内容将写入到输出流,并通过输出流输出给客户端浏览 |
|
|
|
WritableWorkbook wk=Workbook.createWorkbook(output); |
|
|
|
|
|
///创建可写入的Excel工作表 |
|
|
|
WritableSheet sheet=wk.createSheet("成绩表", 0); |
|
|
|
//把单元格(column, row)到单元格(column1, row1)进行合并。 |
|
|
|
//mergeCells(column, row, column1, row1); |
|
|
|
sheet.mergeCells(0,0, 4,0);//单元格合并方法 |
|
|
|
//创建WritableFont 字体对象,参数依次表示黑体、字号12、粗体、非斜体、不带下划线、亮蓝色 |
|
|
|
WritableFont titleFont=new WritableFont(WritableFont.createFont("黑体"),12,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.LIGHT_BLUE); |
|
|
|
//创建WritableCellFormat对象,将该对象应用于单元格从而设置单元格的样式 |
|
|
|
WritableCellFormat titleFormat=new WritableCellFormat(); |
|
|
|
//设置字体格式 |
|
|
|
titleFormat.setFont(titleFont); |
|
|
|
//设置文本水平居中对齐 |
|
|
|
titleFormat.setAlignment(Alignment.CENTRE); |
|
|
|
//设置文本垂直居中对齐 |
|
|
|
titleFormat.setVerticalAlignment(VerticalAlignment.CENTRE); |
|
|
|
//设置背景颜色 |
|
|
|
titleFormat.setBackground(Colour.GRAY_25); |
|
|
|
//设置自动换行 |
|
|
|
titleFormat.setWrap(true); |
|
|
|
//添加Label对象,参数依次表示在第一列,第一行,内容,使用的格式 |
|
|
|
Label lab_00=new Label(0,0,"学员考试成绩一览表",titleFormat); |
|
|
|
//将定义好的Label对象添加到工作表上,这样工作表的第一列第一行的内容为‘学员考试成绩一览表’并应用了titleFormat定义的样式 |
|
|
|
sheet.addCell(lab_00); |
|
|
|
WritableCellFormat cloumnTitleFormat=new WritableCellFormat(); |
|
|
|
cloumnTitleFormat.setFont(new WritableFont(WritableFont.createFont("宋体"),10,WritableFont.BOLD,false)); |
|
|
|
cloumnTitleFormat.setAlignment(Alignment.CENTRE); |
|
|
|
Label lab_01=new Label(0,1,"姓名",cloumnTitleFormat); |
|
|
|
Label lab_11=new Label(1,1,"班级",cloumnTitleFormat); |
|
|
|
Label lab_21=new Label(2,1,"笔试成绩",cloumnTitleFormat); |
|
|
|
Label lab_31=new Label(3,1,"上机成绩",cloumnTitleFormat); |
|
|
|
Label lab_41=new Label(4,1,"考试日期",cloumnTitleFormat); |
|
|
|
sheet.addCell(lab_01); |
|
|
|
sheet.addCell(lab_11); |
|
|
|
sheet.addCell(lab_21); |
|
|
|
sheet.addCell(lab_31); |
|
|
|
sheet.addCell(lab_41); |
|
|
|
sheet.addCell(new Label(0,2,"李明")); |
|
|
|
sheet.addCell(new Label(1,2,"As178")); |
|
|
|
//定义数字格式 |
|
|
|
NumberFormat nf=new NumberFormat("0.00"); |
|
|
|
WritableCellFormat wcf=new WritableCellFormat(nf); |
|
|
|
//类似于Label对象,区别Label表示文本数据,Number表示数值型数据 |
|
|
|
Number numlab_22=new Number(2,2,78,wcf); |
|
|
|
sheet.addCell(numlab_22); |
|
|
|
sheet.addCell(newNumber(3,2,87,new WritableCellFormat(new NumberFormat("#.##") ))); |
|
|
|
//定义日期格式 |
|
|
|
DateFormat df=new DateFormat("yyyy-MM-dd hh:mm:ss"); |
|
|
|
//创建WritableCellFormat对象 |
|
|
|
WritableCellFormat datewcf=new WritableCellFormat(df); |
|
|
|
//类似于Label对象,区别Label表示文本数据,DateTime表示日期型数据 |
|
|
|
DateTime dtLab_42=new DateTime(4,2,new Date(),datewcf); |
|
|
|
sheet.addCell(dtLab_42); |
|
|
|
//将定义的工作表输出到之前指定的介质中(这里是客户端浏览器) |
|
|
|
wk.write(); |
|
|
|
//操作完成时,关闭对象,释放占用的内存空间 |
|
|
|
wk.close(); |
|
加下划线这部分代码是B/S模式中采用的输出方式,而不是输出到本地指定的磁盘目录。该代码表示将temp.xls的Excel文件通过应答实体(response)输出给请求的客户端浏览器,下载到客户端本地(保存或直接打开)。若要直接输出到磁盘文件可采用下列代码替换加下划线这部分代码 |
|
File file=new File("D://temp.xls"); |
|
WritableWorkbook wwb = Workbook.createWorkbook(file); </pre></p> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
3.3高级操作</h3> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3.3.1数据格式化</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 在Excel中不涉及复杂的数据类型,能够比较好的处理字串、数字和日期已经能够满足一般的应用即可。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 数据的格式化涉及到的是字体、粗细、字号等元素,这些功能主要由 WritableFont和WritableCellFormat类来负责。例如:</span></p> |
|
<blockquote> |
|
<p align="left"><span style="font-family:'Microsoft YaHei'; font-size:14px">① WritableFont font=new WritableFont(WritableFont.createFont("宋体"),12,WritableFont.NO_BOLD );</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">② WritableCellFormat format1=new WritableCellFormat(font);</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">③ Label label=new Label(0,0,”data 4 test”,format1);</span></p> |
|
</blockquote> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 其中</span></p> |
|
<blockquote> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">I.指定了字串格式:字体为宋体,字号16,加粗显示。WritableFont有非常丰富的构造子,供不同情况下使用,jExcelAPI的java-doc中有详细列表,这里不再列出。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">II. 处代码使用了WritableCellFormat类,这个类非常重要,通过它可以指定单元格的各种属性,如上例代码所示。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">III. 处使用了Label类的构造子,指定了显示的位置,文本内容,字串被赋予的格式。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px">与Label类似的Number、DateTime,区别Label表示文本数据;Number表示数值数据,可使NumberFormat格式化数据;用DateTime表示日期型数据,可应用DateFormat格式化数据。</span></p> |
|
</blockquote> |
|
<h3><span style="font-family:'Microsoft YaHei'; font-size:14px"> 3.3.2单元格操作</span></h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> Excel中很重要的一部分是对单元格的操作,比如行高、列宽、单元格合并等,所幸jExcelAPI提供了这些支持。这些操作相对比较简单,下面只介绍一下相关的API。</span></p> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"><strong> 1、 合并单元格</strong></span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">WritableSheet.mergeCells(int m,int n,int p,int q); |
|
|
|
//作用是从(m,n)到(p,q)的单元格全部合并,比如: |
|
|
|
WritableSheet sheet=book.createSheet(“第一页”,0); |
|
|
|
//合并第一列第一行到第六列第一行的所有单元格 |
|
|
|
sheet.mergeCells(0,0,5,0); |
|
|
|
//合并既可以是横向的,也可以是纵向的。合并后的单元格不能再次进行合并,否则会触发异常。</pre></pre> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"><strong> 2、 行高和列宽</strong></span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java"> writableSheet.setRowView(int i,int height); |
|
|
|
//作用是指定第i+1行的高度,比如: |
|
|
|
// 将第一行的高度设为200 |
|
|
|
sheet.setRowView(0,200); |
|
|
|
WritableSheet.setColumnView(int i,int width); |
|
|
|
//作用是指定第i+1列的宽度,比如: |
|
|
|
//将第一列的宽度设为30 |
|
|
|
sheet.setColumnView(0,30); </pre></pre> |
|
</div> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
3.4 从Excel文件读取数据表</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 我们就以导入3.2所产生的excel表为例,掌握如何编写导入Excel代码(该代码封装在业务层方法</span>)</p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">public List<ScoreInfo> loadScoreInfo(String xlsPath) throws IOException, BiffException{ |
|
|
|
//导入已存在的Excel文件,获得只读的工作薄对象 |
|
FileInputStream fis=new FileInputStream(xlsPath); |
|
Workbook wk=Workbook.getWorkbook(fis); |
|
//获取第一张Sheet表 |
|
Sheet sheet=wk.getSheet(0); |
|
//获取总行数 |
|
int rowNum=sheet.getRows(); |
|
//从数据行开始迭代每一行 |
|
for(int i=2;i<rowNum;i++){ |
|
ScoreInfo info=new ScoreInfo(); |
|
//getCell(column,row),表示取得指定列指定行的单元格(Cell) |
|
//getContents()获取单元格的内容,返回字符串数据。适用于字符型数据的单元格 |
|
//使用实体类封装单元格数据 |
|
info.setStuName(sheet.getCell(0, i).getContents()); |
|
info.setClassName(sheet.getCell(1, i).getContents()); |
|
//判断单元格的类型,单元格主要类型LABEL、NUMBER、DATE if(sheet.getCell(2,i).getType==CellType.NUMBER){ |
|
|
|
//转化为数值型单元格 |
|
NumberCell numCell=(NumberCell)sheet.getCell(2,i); |
|
//NumberCell的getValue()方法取得单元格的数值型数据 |
|
info.setRscore(numCell.getValue()); |
|
|
|
} |
|
if(sheet.getCell(3,i).getType==CellType.NUMBER){ |
|
NumberCell numCell=(NumberCell)sheet.getCell(3,i); |
|
info.setRscore(numCell.getValue); |
|
} |
|
|
|
if(sheet.getCell(4,i).getType==CellType.DATE){ |
|
DateCell dateCell=(DateCell)sheet.getCell(4,i); |
|
//DateCell的getDate()方法取得单元格的日期型数据 |
|
info.setDate(dateCell.getDate()); |
|
} |
|
} |
|
fis.close(); |
|
wk.close(); |
|
}</pre></pre> |
|
</div> |
|
<h3 style="padding:5px 0px; color:#3399cc; font-size:18px; font-family:微软雅黑,宋体,黑体,Arial; height:25px; line-height:25px; border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:#3399cc; margin:15px!important"> |
|
3.4 更新已存在的Excel文件</h3> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 将3.2所产生的excel表(temp.xls)的第一条记录(excel文件的指第三行)的班级名称改为As179,代码如下:</span></p> |
|
<div class="cnblogs_code"> |
|
<pre><pre name="code" class="java">File file=new File("d://temp.xls"); |
|
//导入已存在的Excel文件,获得只读的工作薄对象 |
|
Workbook wk=Workbook.getWorkbook(file); |
|
//根据只读的工作薄对象(wk)创建可写入的Excel工作薄对象 |
|
WritableWorkbook wwb=Workbook.createWorkbook(file, wk); |
|
//读取第一张工作表 |
|
WritableSheet sheet=wwb.getSheet(0); |
|
///获得要编辑的单元格对象 |
|
WritableCell cell=sheet.getWritableCell(1, 2); |
|
//判断单元格的类型, 做出相应的转化 |
|
if(cell.getType()==CellType.LABEL){ |
|
Label lable=(Label)cell; |
|
//修改单元格的内容 |
|
lable.setString("As179"); |
|
} |
|
wwb.write(); |
|
wwb.close(); |
|
wk.close(); </pre></pre> |
|
</div> |
|
<p><span style="font-family:'Microsoft YaHei'; font-size:14px"> 对于更新已存在的Excel文件实际上就是获取已有工作薄对象(但是只读的),然后将获取的只读的工作薄对象转化为可写入的Excel工作薄对象(WritableWorkbook ),其他部分就是通过可写入WritableSheet 对象和可写入WritableCell 对象进行编辑。</span></p> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="bdsharebuttonbox tracking-ad" style="float: right;" data-mod="popu_172"> |
|
<a href="#" class="bds_more" data-cmd="more" style="background-position:0 0 !important; background-image: url(http://bdimg.share.baidu.com/static/api/img/share/icons_0_16.png?v=d754dcc0.png) !important"></a> |
|
<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间" style="background-position:0 -52px !important"></a> |
|
<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"style="background-position:0 -104px !important"></a> |
|
<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"style="background-position:0 -260px !important"></a> |
|
<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"style="background-position:0 -208px !important"></a> |
|
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"style="background-position:0 -1612px !important" ></a> |
|
</div> |
|
<script>window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "1", "bdMiniList": false, "bdPic": "", "bdStyle": "0", "bdSize": "16" }, "share": {} }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];</script> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" id="bdshare_js" data="type=tools&uid=1536434" ></script> |
|
<script type="text/javascript" id="bdshell_js"></script> |
|
<script type="text/javascript"> |
|
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000) |
|
</script> |
|
|
|
|
|
<script type="text/javascript"> |
|
var fromjs = $("#fromjs"); |
|
if (fromjs.length > 0) { |
|
$("#fromjs .markdown_views pre").addClass("prettyprint"); |
|
prettyPrint(); |
|
|
|
$('pre.prettyprint code').each(function () { |
|
var lines = $(this).text().split('\n').length; |
|
var $numbering = $('<ul/>').addClass('pre-numbering').hide(); |
|
$(this).addClass('has-numbering').parent().append($numbering); |
|
for (i = 1; i <= lines; i++) { |
|
$numbering.append($('<li/>').text(i)); |
|
}; |
|
$numbering.fadeIn(1700); |
|
}); |
|
|
|
$('.pre-numbering li').css("color", "#999"); |
|
} |
|
|
|
|
|
$(".markdown_views a[target!='_blank']").attr("target", "_blank"); |
|
|
|
$(".toc a[target='_blank']").attr("target", ""); |
|
|
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<div id="digg" ArticleId="45195359" > |
|
<dl id="btnDigg" class="digg digg_enable" onclick="btndigga();"> |
|
|
|
<dt>顶</dt> |
|
<dd>3</dd> |
|
</dl> |
|
|
|
|
|
<dl id="btnBury" class="digg digg_enable" onclick="btnburya();"> |
|
|
|
<dt>踩</dt> |
|
<dd>0</dd> |
|
</dl> |
|
|
|
</div> |
|
<div class="tracking-ad" data-mod="popu_222"><a href="javascript:void(0);" > </a> </div> |
|
<div class="tracking-ad" data-mod="popu_223"> <a href="javascript:void(0);" > </a></div> |
|
<script type="text/javascript"> |
|
function btndigga() { |
|
$(".tracking-ad[data-mod='popu_222'] a").click(); |
|
} |
|
function btnburya() { |
|
$(".tracking-ad[data-mod='popu_223'] a").click(); |
|
} |
|
</script> |
|
|
|
<ul class="article_next_prev"> |
|
<li class="prev_article"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian']);location.href='/jerehedu/article/details/45195295';">上一篇</span><a href="/jerehedu/article/details/45195295" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_shangyipian'])">IOS开发中多线程的使用</a></li> |
|
<li class="next_article"><span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='/jerehedu/article/details/45195467';">下一篇</span><a href="/jerehedu/article/details/45195467" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">IOS数据持久化之归档NSKeyedArchiver</a></li> |
|
</ul> |
|
|
|
<div style="clear:both; height:10px;"></div> |
|
|
|
|
|
<div class="similar_article" > |
|
<h4></h4> |
|
<div class="similar_c"style="margin:20px 0px 0px 0px"> |
|
<div class="similar_c_t"> |
|
相关文章推荐 |
|
</div> |
|
|
|
<div class="similar_wrap tracking-ad" data-mod="popu_36" style="max-height:195px;"> |
|
<ul class="similar_list fl"> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/hgy413/article/details/6598043" title="3.IDA-数据显示窗口(导出窗口、导入窗口、String窗口、...窗口)" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">3.IDA-数据显示窗口(导出窗口、导入窗口、String窗口、...窗口)</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/liuliuniu1987/article/details/6184588" title="HOWTO: 使用命令行方式导入导出多语言String Tables" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">HOWTO: 使用命令行方式导入导出多语言String Tables</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/JQ_AK47/article/details/52727727" title="關於JAVA中String类以形参传递到函数里面,修改后外面引用不能获取到更改后的值" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">關於JAVA中String类以形参传递到函数里面,修改后外面引用不能获取到更改后的值</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/xyc_csdn/article/details/72582016" title="关于Java的String字符串常量的长度问题" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">关于Java的String字符串常量的长度问题</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/qq516230226/article/details/72017415" title="Java 中 String 类的常用方法" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">Java 中 String 类的常用方法</a> |
|
</li> |
|
</ul> |
|
<ul class="similar_list fr"> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/qq_36503884/article/details/71603367" title="Java String字符串自动填补0或空格" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">Java String字符串自动填补0或空格</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/u011277123/article/details/71600469" title="Java String探索" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">Java String探索</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/qq_36752632/article/details/71601284" title="使用封装类进行转换时候报错,java.lang.NumberFormatException: For input string: """ strategy="SearchAlgorithm" target="_blank" style="width: 290px;">使用封装类进行转换时候报错,java.lang.NumberFormatException: For input string: ""</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/u010296640/article/details/52809878" title="java正则表达式、命令行参数、String常用方法" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">java正则表达式、命令行参数、String常用方法</a> |
|
</li> |
|
<li> |
|
<em>•</em> |
|
<a href="http://blog.csdn.net/u013276277/article/details/72377229" title="JAVA中int,string,char之间的互相转换" strategy="SearchAlgorithm" target="_blank" style="width: 290px;">JAVA中int,string,char之间的互相转换</a> |
|
</li> |
|
</ul> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
</div> |
|
|
|
<div> |
|
|
|
|
|
<script type="text/javascript"> |
|
/*博客内容页下方Banner1-960*90,创建于2016-12-13*/ |
|
var cpro_id = "u2843955"; |
|
</script> |
|
<script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script> |
|
</div> |
|
|
|
<div id="suggest"></div> |
|
<script language="javascript" type='text/javascript'> |
|
$(function(){ |
|
$.get("/JerehEdu/svc/GetSuggestContent/45195359",function(data){ |
|
$("#suggest").html(data); |
|
}); |
|
}); |
|
</script> |
|
|
|
|
|
<style> |
|
.blog-ass-articl dd { |
|
color: #369; |
|
width: 99%; /*修改行*/ |
|
float: left; |
|
overflow: hidden; |
|
font: normal normal 12px/23px "SimSun"; |
|
height: 23px; |
|
margin: 0; |
|
padding: 0 0 0 10px; |
|
margin-right: 30px; |
|
background: url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px; |
|
} |
|
</style> |
|
|
|
|
|
<div id="relate" data-mod="popu_218" class="tracking-ad"> |
|
<div class="relate_t"> |
|
<h3><span>参考知识库</span></h3> |
|
</div> |
|
<div class="relate_c"> |
|
</div> |
|
</div> |
|
|
|
|
|
<dl class="blog-ass-articl tracking-ad" id="res-relatived" data-mod="popu_84" > |
|
<div class="embody embody_b" id="libkeyparent" style="display:none"> |
|
<span class="embody_t">更多资料请参考:</span> |
|
<div class="embody_c" id="libkey"></div> |
|
</div> |
|
|
|
|
|
<dt><span>猜你在找</span></dt> |
|
|
|
|
|
|
|
|
|
|
|
<div id="adcollegedata" style="display:none"></div> |
|
|
|
<div id="adCollege" style="width: 42%;float: left;"> |
|
</div> |
|
|
|
|
|
<div id="resforAd" style="width: 42%;float: left;margin-right: 30px;"></div> |
|
|
|
<script src="http://csdnimg.cn/jobreco/job_reco.js" type="text/javascript"></script> |
|
<script type="text/javascript"> |
|
csdn.position.showEdu({ |
|
sourceType: "blog", |
|
searchType: "detail", |
|
searchKey: "45195359", |
|
username: "lzl110110", |
|
recordcount: "10", |
|
containerId: "adcollegedata" //容器DIV的id。 |
|
}); |
|
|
|
//setEduLoc(); |
|
|
|
//function setEduLoc() { |
|
// var edus = $("#adCollege div dd a"); |
|
// if (edus.length == 0) { |
|
// setTimeout(function () { |
|
// setEduLoc(); |
|
// }, 500); |
|
// } |
|
// else { |
|
// var eduLoc = "?ref=blog&loc=0"; |
|
// $.each(edus, function (index, item) { |
|
// var href = $(this).attr("href") + eduLoc; |
|
// $(this).attr("href", href); |
|
// }); |
|
// } |
|
//} |
|
|
|
|
|
setTimeout(function () { |
|
var adcolleges = $("#adcollegedata div dd"); |
|
for (var i = 0; i < adcolleges.length; i++) { |
|
if (i < 5) { |
|
$("#adCollege").append("<dd>" + $(adcolleges[i]).html() + "</dd"); |
|
} |
|
else { |
|
$("#resforAd").append("<dd>" + $(adcolleges[i]).html() + "</dd"); |
|
} |
|
} |
|
}, 1500); |
|
|
|
|
|
</script> |
|
|
|
</dl> |
|
|
|
|
|
|
|
|
|
|
|
<div id="ad_cen"> |
|
<div> |
|
<div class="tracking-ad" data-view="true" data-mod="ad_popu_199" data-mtp="43" data-order="114" data-con="ad_content_1843" style="width: 960px; height: 90px;"> |
|
<script type="text/javascript"> |
|
/*博客内容页下方Banner2-960*90,创建于,2016-11-28*/ |
|
var cpro_id = "u2831143"; |
|
</script> |
|
<script type="text/javascript" src="http://cpro.baidustatic.com/cpro/ui/c.js"></script> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
|
|
|
|
<div class="tracking-ad" data-view="true" data-mod="ad_popu_72" data-mtp="62" data-order="40" data-con="ad_content_2072"> |
|
<script id="popuLayer_js_q" src="http://ads.csdn.net/js/popuLayer.js" defer="defer" type="text/javascript"></script> |
|
<div id="layerd" style="position: fixed;bottom:0px;right:0px;line-height:0px;z-index:1000"> |
|
<div class="J_close layer_close" style="display:;background-color:#efefef;padding:0px;color:#333;font:12px/24px Helvetica,Tahoma,Arial,sans-serif;text-align:right;">关闭</div><div id="cpro_u2895327"></div></div> |
|
<script> document.getElementById("popuLayer_js_q").onload=function(){ var styObjd=styObj={width:"300px","height":parseInt(250)+28};window.CSDN.Layer.PopuLayer("#layerd",{storageName:"layerd",styleObj:styObjd,total:50,expoire:1000*60}); }</script><script type="text/javascript"> /*服务器频道首页置顶Banner960*90,创建于2014-7-3*/ (window.cproArray = window.cproArray || []).push({ id: "u2895327" }); </script> <script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> |
|
|
|
</div> |
|
|
|
<div class="comment_class"> |
|
<div id="comment_title" class="panel_head"> |
|
<span class="see_comment">查看评论</span><a name="comments"></a></div> |
|
<div id="comment_list"> |
|
</div> |
|
<div id="comment_bar"> |
|
</div> |
|
<div id="comment_form"> |
|
</div> |
|
<div class="announce"> |
|
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场<a name="reply"></a><a name="quote"></a></div> |
|
</div> |
|
|
|
<script type="text/javascript"> |
|
var fileName = '45195359'; |
|
var commentscount = 1; |
|
var islock = false |
|
</script> |
|
|
|
<div id="ad_bot"> |
|
</div> |
|
<div id="report_dialog"> |
|
</div> |
|
|
|
<div id="d-top" style="bottom:60px;"> |
|
|
|
<a id="quick-reply" class="btn btn-top q-reply" title="快速回复" style="display:none;"> |
|
<img src="http://static.blog.csdn.net/images/blog-icon-reply.png" alt="快速回复"> |
|
</a> |
|
<a id="d-top-a" class="btn btn-top backtop" style="display: none;" title="返回顶部" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_huidaodingbu'])" style=""> |
|
<img src="http://static.blog.csdn.net/images/top.png" alt="TOP"> |
|
</a> |
|
</div> |
|
<script type="text/javascript"> |
|
$(function () |
|
{ |
|
$("#ad_frm_0").height("90px"); |
|
|
|
setTimeout(function(){ |
|
$("#ad_frm_2").height("200px"); |
|
},1000); |
|
}); |
|
|
|
</script> |
|
<style type="text/css"> |
|
.tag_list |
|
{ |
|
background: none repeat scroll 0 0 #FFFFFF; |
|
border: 1px solid #D7CBC1; |
|
color: #000000; |
|
font-size: 12px; |
|
line-height: 20px; |
|
list-style: none outside none; |
|
margin: 10px 2% 0 1%; |
|
padding: 1px; |
|
} |
|
.tag_list h5 |
|
{ |
|
background: none repeat scroll 0 0 #E0DBD3; |
|
color: #47381C; |
|
font-size: 12px; |
|
height: 24px; |
|
line-height: 24px; |
|
padding: 0 5px; |
|
margin: 0; |
|
} |
|
.tag_list h5 a |
|
{ |
|
color: #47381C; |
|
} |
|
.classify |
|
{ |
|
margin: 10px 0; |
|
padding: 4px 12px 8px; |
|
} |
|
.classify a |
|
{ |
|
margin-right: 20px; |
|
white-space: nowrap; |
|
} |
|
</style> |
|
|
|
|
|
<div class="tag_list" style="display:none"></div> |
|
<script type='text/javascript'> |
|
$(function(){ |
|
setTimeout(function(){ |
|
$.get("/JerehEdu/svc/GetTagContent",function(data){ |
|
$(".tag_list").html(data).show(); |
|
}); |
|
}); |
|
},500); |
|
</script> |
|
|
|
|
|
<div id="pop_win" style="display:none ;position: absolute; z-index: 10000; border: 1px solid rgb(220, 220, 220); top: 222.5px; left: 630px; opacity: 1; background: none 0px 0px repeat scroll rgb(255, 255, 255);"> |
|
|
|
</div> |
|
<div id="popup_mask"></div> |
|
<style> |
|
#popup_mask |
|
{ |
|
position: absolute; |
|
width: 100%; |
|
height: 100%; |
|
background: #000; |
|
z-index: 9999; |
|
left: 0px; |
|
top: 0px; |
|
opacity: 0.3; |
|
filter: alpha(opacity=30); |
|
display: none; |
|
} |
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
$(function(){ |
|
|
|
setTimeout(function(){ |
|
$(".comment_body:contains('回复')").each(function(index,item){ |
|
var u=$(this).text().split(':')[0].toString().replace("回复","") |
|
var thisComment=$(this); |
|
if(u) |
|
{ |
|
$.getJSON("https://passport.csdn.net/get/nick?callback=?", {users: u}, function(a) { |
|
if(a!=null&&a.data!=null&&a.data.length>0) |
|
{ |
|
nick=a.data[0].n; |
|
if(u!=nick) |
|
{ |
|
thisComment.text(thisComment.text().replace(u,nick)); |
|
} |
|
} |
|
}); |
|
} |
|
}); |
|
|
|
},200); |
|
|
|
setTimeout(function(){ |
|
$(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); }) |
|
},5000); |
|
|
|
setTimeout(function(){ |
|
$(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); }) |
|
},10000); |
|
|
|
setTimeout(function(){ |
|
$(".math").each(function(index,value){$(this).find("span").last().css("color","#fff"); }) |
|
},15000); |
|
|
|
setTimeout(function(){ |
|
$("a img[src='http://js.tongji.linezing.com/stats.gif']").parent().css({"position":"absolute","left":"50%"}); |
|
},300); |
|
}); |
|
|
|
function loginbox(){ |
|
var $logpop=$("#pop_win"); |
|
$logpop.html('<iframe src="https://passport.csdn.net/account/loginbox?service=http://static.blog.csdn.net/callback.htm" frameborder="0" height="600" width="400" scrolling="no"></iframe>'); |
|
|
|
$('#popup_mask').css({ |
|
opacity: 0.5, |
|
width: $( document ).width() + 'px', |
|
height: $( document ).height() + 'px' |
|
}); |
|
$('#popup_mask').css("display","block"); |
|
|
|
$logpop.css( { |
|
top: ($( window ).height() - $logpop.height())/ 2 + $( window |
|
).scrollTop() + 'px', |
|
left:($( window ).width() - $logpop.width())/ 2 |
|
} ); |
|
|
|
setTimeout( function () { |
|
$logpop.show(); |
|
$logpop.css( { |
|
opacity: 1 |
|
} ); |
|
}, 200 ); |
|
|
|
$('#popup_mask').unbind("click"); |
|
$('#popup_mask').bind("click", function(){ |
|
$('#popup_mask').hide(); |
|
var $clopop = $("#pop_win"); |
|
$("#common_ask_div_sc").css("display","none"); |
|
$clopop.css( { |
|
opacity: 0 |
|
} ); |
|
setTimeout( function () { |
|
$clopop.hide(); |
|
}, 350 ); |
|
return false; |
|
}); |
|
} |
|
|
|
var articletitle='Java中导入、导出Excel'; |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="clear"> |
|
</div> |
|
</div> |
|
|
|
</div> |
|
|
|
<div id="side"> |
|
|
|
<div class="side"> |
|
<div id="panel_Profile" class="panel"> |
|
<ul class="panel_head"><span>个人资料</span></ul> |
|
<ul class="panel_body profile"> |
|
<div id="blog_userface"> |
|
<a href="http://my.csdn.net/JerehEdu" target="_blank"> |
|
<img src="http://avatar.csdn.net/9/5/4/1_jerehedu.jpg" title="访问我的空间" style="max-width:90%"/> |
|
</a> |
|
<br /> |
|
<span><a href="http://my.csdn.net/JerehEdu" class="user_name" target="_blank">JerehEdu</a></span> |
|
</div> |
|
<div class="interact"> |
|
|
|
<a href="javascript:void(0);" class="attent" id="span_add_follow" title="[加关注]"></a> |
|
|
|
<a href="javascript:void(0);" class="letter" title="[发私信]" onclick="window.open('http://msg.csdn.net/letters/model?receiver=JerehEdu','_blank','height=350,width=700');_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_sixin'])"></a> |
|
</div> |
|
<div id="blog_medal"> |
|
<div id="bms_box"> |
|
</div> |
|
</div> |
|
<ul id="blog_rank"> |
|
<li>访问:<span>86235次</span></li> |
|
<li>积分:<span>2359</span> </li> |
|
<li >等级: <span style="position:relative;display:inline-block;z-index:1" > |
|
<img src="http://c.csdnimg.cn/jifen/images/xunzhang/jianzhang/blog5.png" alt="" style="vertical-align: middle;" id="leveImg"> |
|
<div id="smallTittle" style=" position: absolute; left: -24px; top: 25px; text-align: center; width: 101px; height: 32px; background-color: #fff; line-height: 32px; border: 2px #DDDDDD solid; box-shadow: 0px 2px 2px rgba (0,0,0,0.1); display: none; z-index: 999;"> |
|
<div style="left: 42%; top: -8px; position: absolute; width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 8px solid #EAEAEA;"></div> |
|
积分:2359 </div> |
|
</span> </li> |
|
<li>排名:<span>第14494名</span></li> |
|
</ul> |
|
<ul id="blog_statistics"> |
|
<li>原创:<span>151篇</span></li> |
|
<li>转载:<span>0篇</span></li> |
|
<li>译文:<span>0篇</span></li> |
|
<li>评论:<span>27条</span></li> |
|
</ul> |
|
</ul> |
|
</div> |
|
|
|
|
|
<div class="panel" id="panel_Search"> |
|
<ul class="panel_head"><span>文章搜索</span></ul> |
|
<ul class="panel_body" class="form_search"> |
|
<form id="frmSearch" action="http://so.csdn.net/search" class="form_search csdn-tracking-statistics" target="_blank" data-mod="popu_306"> |
|
<span><input id="inputSearch" type="text" class="blogsearch" title="请输入关键字" /></span> |
|
<input id="btnSubmit" type="button" value="搜索" title="search in blog" /> |
|
<input type="hidden" name="q" id="inputQ" /> |
|
<input type="hidden" name="t" value="blog" /> |
|
<a id="btnSearchBlog" target="_blank"></a> |
|
</form> |
|
</ul> |
|
</div> |
|
|
|
<script type="text/javascript"> |
|
|
|
|
|
$(function () { |
|
$("#btnSubmit").unbind("click"); |
|
$("#btnSubmit").click(function () { |
|
search(); |
|
}); |
|
|
|
$("#frmSearch").submit(function () { |
|
search(); |
|
return false; |
|
}); |
|
|
|
function search() |
|
{ |
|
if ($("#inputSearch").val() == "") { |
|
alert("请录入搜索关键词!"); |
|
return false; |
|
} |
|
//var url = "http://so.csdn.net/so/search/s.do?q=" + encodeURIComponent($("#inputSearch").val()) + "&u=" + username + "&t=blog"; |
|
var url = "https://www.baidu.com/s?wd=" + encodeURIComponent($("#inputSearch").val()) + "%20site%3Ablog.csdn.net" |
|
window.location.href = url; |
|
} |
|
}); |
|
</script><div id="panel_Category" class="panel"> |
|
<ul class="panel_head"><span>文章分类</span></ul> |
|
<ul class="panel_body"> |
|
<li> |
|
<a href="/JerehEdu/article/category/2807943" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">Android技术分享</a><span>(82)</span> |
|
</li> |
|
<li> |
|
<a href="/JerehEdu/article/category/2807945" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">IOS技术分享</a><span>(54)</span> |
|
</li> |
|
<li> |
|
<a href="/JerehEdu/article/category/2807947" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">java技术分享</a><span>(15)</span> |
|
</li> |
|
<li> |
|
<a href="/JerehEdu/article/category/6076723" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_wenzhangfenlei']); ">原创教材</a><span>(1)</span> |
|
</li> |
|
</ul> |
|
</div><div id="hotarticls" class="panel"> |
|
<ul class="panel_head"> |
|
<span> |
|
阅读排行 </span> |
|
</ul> |
|
|
|
<ul class="panel_body itemlist"> |
|
<li> |
|
<a href="/jerehedu/article/details/45192091" title="SVN详细配置与使用 ——一步步教会您使用">SVN详细配置与使用 ——一步步教会您使用</a><span>(2192)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45195359" title="Java中导入、导出Excel">Java中导入、导出Excel</a><span>(2106)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/46911955" title="Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换">Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换</a><span>(1928)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45746369" title="Android生成带图片的二维码">Android生成带图片的二维码</a><span>(1556)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45196019" title="Android实现图片轮显效果——自定义ViewPager控件">Android实现图片轮显效果——自定义ViewPager控件</a><span>(1408)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45822251" title="Android实现仿qq侧边栏效果">Android实现仿qq侧边栏效果</a><span>(1219)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/47319345" title="Android典型界面设计(4)——使用ActionBar+Fragment实现tab切换">Android典型界面设计(4)——使用ActionBar+Fragment实现tab切换</a><span>(1188)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45196185" title="Android studio导入开源项目">Android studio导入开源项目</a><span>(1138)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45196125" title="IOS实现自动循环滚动广告--ScrollView的优化和封装">IOS实现自动循环滚动广告--ScrollView的优化和封装</a><span>(1012)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45390165" title="微信二维码扫描下载APK">微信二维码扫描下载APK</a><span>(1002)</span> |
|
</li> |
|
</ul> |
|
</div> |
|
<div id="hotarticls2" class="panel"> |
|
<ul class="panel_head"><span>评论排行</span></ul> |
|
<ul class="panel_body itemlist"> |
|
<li> |
|
<a href="/jerehedu/article/details/45196019" title="Android实现图片轮显效果——自定义ViewPager控件">Android实现图片轮显效果——自定义ViewPager控件</a><span>(4)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/46911955" title="Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换">Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换</a><span>(3)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45193205" title="Android界面设计之对话框——定制Toast、AlertDialog">Android界面设计之对话框——定制Toast、AlertDialog</a><span>(2)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/47021541" title="Android GUI之Activity、Window、View">Android GUI之Activity、Window、View</a><span>(2)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45196185" title="Android studio导入开源项目">Android studio导入开源项目</a><span>(2)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45746369" title="Android生成带图片的二维码">Android生成带图片的二维码</a><span>(2)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45195553" title="ActionBar+DrawerLayout实现网易新闻客户端首页">ActionBar+DrawerLayout实现网易新闻客户端首页</a><span>(1)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45716123" title="基于VlC的视频播放器">基于VlC的视频播放器</a><span>(1)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45191863" title="使用极光推送实现分组发送和服务端集成">使用极光推送实现分组发送和服务端集成</a><span>(1)</span> |
|
</li> |
|
<li> |
|
<a href="/jerehedu/article/details/45390165" title="微信二维码扫描下载APK">微信二维码扫描下载APK</a><span>(1)</span> |
|
</li> |
|
</ul> |
|
</div> |
|
<div id="newcomments" class="panel"> |
|
<ul class="panel_head"><span>最新评论</span></ul> |
|
<ul class="panel_body itemlist"> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/45196019#comments">Android实现图片轮显效果——自定义ViewPager控件</a> |
|
<p style="margin:0px;"><a href="/qq_24578531" class="user_name">qq_24578531</a>: |
|
myPager.start方法里的参数能分别解释下吗 |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/45196019#comments">Android实现图片轮显效果——自定义ViewPager控件</a> |
|
<p style="margin:0px;"><a href="/Cat_swam" class="user_name">Cat_swam</a>: |
|
那个我是个Android新手 ,请问一下 com.jereh.view. MyScrollImage... |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/45195359#comments">Java中导入、导出Excel</a> |
|
<p style="margin:0px;"><a href="/gdfy0616" class="user_name">gdfy0616</a>: |
|
太好了!多谢分享啊!介绍的真是全面 |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46453371#comments">android实现gif图与文字混排</a> |
|
<p style="margin:0px;"><a href="/qq_25211337" class="user_name">qq_25211337</a>: |
|
内存溢出 |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46424813#comments">Android之官方导航栏之Toolbar(Toolbar+DrawerLayout+ViewPager+PagerSlidingTabStrip)</a> |
|
<p style="margin:0px;"><a href="/roadcow" class="user_name">roadcow</a>: |
|
右边能显示菜单吗? |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46424813#comments">Android实现图片轮显效果——自定义ViewPager控件</a> |
|
<p style="margin:0px;"><a href="/Amazing_Kenboo" class="user_name">Amazing_Kenboo</a>: |
|
@android_I_t:正好我也看到这里,楼主在注释里面说了* @param mainActivi... |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46424813#comments">Android实现图片轮显效果——自定义ViewPager控件</a> |
|
<p style="margin:0px;"><a href="/android_I_t" class="user_name">android_I_t</a>: |
|
mainActivit中 myPager.start第六个参数获取不到啊 |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46911955#comments">Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换</a> |
|
<p style="margin:0px;"><a href="/CTU24CAT" class="user_name">CTU24CAT</a>: |
|
感觉很有用 ,谢谢了! |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/46236013#comments">使用ECharts实现数据图表分析</a> |
|
<p style="margin:0px;"><a href="/Renfr" class="user_name">Renfr</a>: |
|
好 |
|
</p> |
|
</li> |
|
<li> |
|
|
|
<a href="/jerehedu/article/details/45365531#comments">NSURLSession下载和断点续传</a> |
|
<p style="margin:0px;"><a href="/iOS_MingXing" class="user_name">iOS_MingXing</a>: |
|
NSURL * url=这个是做什么的啊????? |
|
</p> |
|
</li> |
|
</ul> |
|
</div> |
|
<div id="panel_Archive" class="panel"> |
|
<ul class="panel_head"><span>文章存档</span></ul> |
|
<ul class="panel_body"> |
|
<div id="archive_list"> |
|
|
|
<li><a href="/JerehEdu/article/month/2016/02">2016年02月</a><span>(18)</span></li><li><a href="/JerehEdu/article/month/2016/01">2016年01月</a><span>(2)</span></li><li><a href="/JerehEdu/article/month/2015/10">2015年10月</a><span>(9)</span></li><li><a href="/JerehEdu/article/month/2015/08">2015年08月</a><span>(10)</span></li><li><a href="/JerehEdu/article/month/2015/07">2015年07月</a><span>(16)</span></li><li><a href="/JerehEdu/article/month/2015/06">2015年06月</a><span>(20)</span></li><li><a href="/JerehEdu/article/month/2015/05">2015年05月</a><span>(20)</span></li><li><a href="/JerehEdu/article/month/2015/04">2015年04月</a><span>(57)</span></li> |
|
</div> |
|
</ul> |
|
</div> |
|
<div id="homepageArticles" class="panel tracking-ad" data-mod="popu_4"> |
|
<ul class="panel_head"><span>推荐文章</span></ul> |
|
<ul class="panel_body" id="ad_commend"> |
|
<ul> |
|
<li><a href="http://blog.csdn.net/turingbooks/article/details/72416875" target="_blank">* 5月书讯:流畅的Python,终于等到你!</a></li> |
|
<li><a href="http://blog.csdn.net/blogdevteam/article/details/72526177" |
|
target="_blank">*【新收录】CSDN日报 —— Kotlin 专场</a></li> |
|
<li><a href="http://blog.csdn.net/jiangwei0910410003/article/details/70483088"target="_blank">* Android中带你开发一款自动爆破签名校验工具kstools</a></li> |
|
<li><a href="http://blog.csdn.net/guolin_blog/article/details/54895665" |
|
target="_blank">* Android图片加载框架最全解析——深入探究Glide的缓存机制</a></li> |
|
<li><a href="http://blog.csdn.net/lmj623565791/article/details/72667669" |
|
target="_blank">* Android 热修复 Tinker Gradle Plugin解析</a></li> |
|
<li><a href="http://blog.csdn.net/puppet_master/article/details/72455945" |
|
target="_blank">* Unity Shader-死亡溶解效果</a></li> |
|
|
|
</ul></ul> |
|
</div> |
|
|
|
|
|
</div> |
|
<div class="clear"> |
|
</div> |
|
|
|
|
|
|
|
|
|
<div class="tracking-ad" data-view="true" data-mod="ad_popu_189" data-mtp="63" data-order="40" data-con="ad_content_1259" style="width: 250px; height: 250px;"> |
|
<div id="nav_show_top_stop" style="width: 250px;height: 250px;z-index:1000"><div id="cpro_u2734133"></div></div> |
|
</div> |
|
<script> |
|
|
|
setTimeout(function () { |
|
var naviga_offsetTop = 0; function naviga_stay_top() { |
|
var scrollTop = jQuery(document).scrollTop(); |
|
if (scrollTop > naviga_offsetTop) { |
|
jQuery("#nav_show_top_stop").css({ "position": "fixed" }); |
|
jQuery("#nav_show_top_stop").css({ "top": "0px" }); |
|
} else { jQuery("#nav_show_top_stop").css({ "position": "fixed" }); jQuery("#nav_show_top_stop").css({ "top": naviga_offsetTop - scrollTop + "px" }); } |
|
} |
|
function onload_function() { |
|
naviga_offsetTop = jQuery("#nav_show_top_stop").position().top; |
|
jQuery(window).bind("scroll", naviga_stay_top); jQuery(window).bind("mousewheel", naviga_stay_top); |
|
jQuery(document).bind("scroll", naviga_stay_top); jQuery(document).bind("mousewheel", naviga_stay_top); |
|
} jQuery(document).ready(onload_function); |
|
},200); |
|
|
|
</script> |
|
<script type="text/javascript"> (window.cproArray = window.cproArray || []).push({ id: "u2734133" }); </script> |
|
<script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script> |
|
|
|
</div> |
|
|
|
<div class="clear"> |
|
</div> |
|
</div> |
|
|
|
|
|
|
|
<script type="text/javascript" src="http://c.csdnimg.cn/rabbit/cnick/cnick.js"></script> |
|
|
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
$(function () { |
|
function __get_code_toolbar(snippet_id) { |
|
return $("<span class='tracking-ad' data-mod='popu_167'><a href='https://code.csdn.net/snippets/" |
|
+ snippet_id |
|
+ "' target='_blank' title='在CODE上查看代码片' style='text-indent:0;'><img src='https://code.csdn.net/assets/CODE_ico.png' width=12 height=12 alt='在CODE上查看代码片' style='position:relative;top:1px;left:2px;'/></a></span>" |
|
+ "<span class='tracking-ad' data-mod='popu_170'><a href='https://code.csdn.net/snippets/" |
|
+ snippet_id |
|
+ "/fork' target='_blank' title='派生到我的代码片' style='text-indent:0;'><img src='https://code.csdn.net/assets/ico_fork.svg' width=12 height=12 alt='派生到我的代码片' style='position:relative;top:2px;left:2px;'/></a></span>"); |
|
} |
|
|
|
$("[code_snippet_id]").each(function () { |
|
__s_id = $(this).attr("code_snippet_id"); |
|
if (__s_id != null && __s_id != "" && __s_id != 0 && parseInt(__s_id) > 70020) { |
|
__code_tool = __get_code_toolbar(__s_id); |
|
$(this).prev().find(".tools").append(__code_tool); |
|
} |
|
}); |
|
|
|
$(".bar").show(); |
|
}); |
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<script type="text/javascript" src="http://c.csdnimg.cn/pubfooter/js/tracking.js" charset="utf-8"></script> |
|
|
|
|
|
|
|
|
|
<link href="http://c.csdnimg.cn/comm_ask/css/ask_float_block.css" type="text/css" rel="stylesheet" /> |
|
<script language='JavaScript' type='text/javascript' src='http://c.csdnimg.cn/comm_ask/js/libs/wmd.js'></script> |
|
<script language='JavaScript' type='text/javascript' src='http://c.csdnimg.cn/comm_ask/js/libs/showdown.js'></script> |
|
|
|
<script language='JavaScript' type='text/javascript' src='http://c.csdnimg.cn/comm_ask/js/apps/ask_float_block.js'></script> |
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="http://ads.csdn.net/js/async_new.js"></script> |
|
<script type="text/javascript" src="http://static.blog.csdn.net/public/res/bower-libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script> |
|
<script type="text/javascript" src="http://c.csdnimg.cn/rabbit/search-service/main.js"></script> |
|
<script type="text/javascript"> |
|
//$(function () { |
|
// setTimeout(function () { |
|
// var searchtitletags = articletitle + ',' + $("#tags").html(); |
|
// searchService({ |
|
// index: 'blog', |
|
// query: searchtitletags, |
|
// from: 5, |
|
// size: 5, |
|
// appendTo: '#res', |
|
// url: 'recommend', |
|
// his: 2, |
|
// client: "blog_cf_enhance", |
|
// tmpl: '<dd style="background:url(http://static.blog.csdn.net/skin/default/images/blog-dot-red3.gif) no-repeat 0 10px;"><a href="#{ url }" title="#{ title }" strategy="#{ strategy }">#{ title }</a></dd>' |
|
// }); |
|
// }, 1000); |
|
//}); |
|
|
|
</script> |
|
<script src="http://static.blog.csdn.net/scripts/csdn_blog_detail.min.js" type="text/javascript"></script> |
|
|
|
<script type="text/javascript" src="http://medal.blog.csdn.net/showblogmedal.ashx?blogid=4920449"></script> |
|
|
|
<script id="csdn-toolbar-id" btnId="header_notice_num" wrapId="note1" count="5" subCount="5" type="text/javascript" src="http://c.csdnimg.cn/public/common/toolbar/js/toolbar.js"></script> |
|
|
|
|
|
|
|
<div id="a52b5334d" style="width: 1px; height: 1px; display: none;"> |
|
<script id="adJs52b5334"></script> |
|
<script>document.getElementById("adJs52b5334").src = "http://ads.csdn.net/js/opt/52b5334.js?t=" + Math.random();</script> |
|
</div> |
|
|
|
|
|
<script type="text/javascript" src="http://static.blog.csdn.net/scripts/saveToCode.js"></script> |
|
<script type="text/javascript" src="//c.csdnimg.cn/rabbit/tracking-ad/main.js?75eacd8"></script> |
|
|
|
|
|
|
|
|
|
|
|
<div class="pop_CA_cover" style="display:none"></div> |
|
<div class="pop pop_CA" style="display:none"> |
|
<div class="CA_header"> |
|
收藏助手 |
|
<span class="cancel_icon" id="fapancle" onclick="$('.pop_CA').hide();$('.pop_CA_cover').hide();"></span> |
|
</div> |
|
<iframe src="" id="fa" frameborder="0" width="100%" height="360" scrolling="no" ></iframe> |
|
</div> |
|
|
|
</body> |
|
</html> |
|
|