﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-KE-文章分类-java excel</title><link>http://www.blogjava.net/keweibo/category/39083.html</link><description>As long as you are there to lead me ,I won't lose my way </description><language>zh-cn</language><lastBuildDate>Thu, 16 Apr 2009 12:09:33 GMT</lastBuildDate><pubDate>Thu, 16 Apr 2009 12:09:33 GMT</pubDate><ttl>60</ttl><item><title>使用POI往EXCEL中插入行</title><link>http://www.blogjava.net/keweibo/articles/265998.html</link><dc:creator>KE</dc:creator><author>KE</author><pubDate>Thu, 16 Apr 2009 08:43:00 GMT</pubDate><guid>http://www.blogjava.net/keweibo/articles/265998.html</guid><wfw:comment>http://www.blogjava.net/keweibo/comments/265998.html</wfw:comment><comments>http://www.blogjava.net/keweibo/articles/265998.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/keweibo/comments/commentRss/265998.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/keweibo/services/trackbacks/265998.html</trackback:ping><description><![CDATA[<p>部分代码如下(POI的版本为3.2)<br />
public void insertRow() throws IOException {</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp; POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("workbook.xls"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HSSFWorkbook wb = new HSSFWorkbook(fs);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HSSFSheet sheet = wb.getSheet("new sheet");<br />
&nbsp;&nbsp;&nbsp; &nbsp; int starRow = 4;<br />
&nbsp;&nbsp;&nbsp; &nbsp; int rows = 5;<br />
&nbsp;&nbsp;&nbsp; &nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sheet.shiftRows(starRow + 1, sheet.getLastRowNum(), rows,true,false);<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//Parameters:<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//startRow - the row to start shifting<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//endRow - the row to end shifting<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//n - the number of rows to shift<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//copyRowHeight - whether to copy the row height during the shift<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//resetOriginalRowHeight - whether to set the original row's height to the default<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; starRow = starRow - 1;</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; rows; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HSSFRow sourceRow = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HSSFRow targetRow = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HSSFCell sourceCell = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HSSFCell targetCell = null;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; short m;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; starRow = starRow + 1;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sourceRow = sheet.getRow(starRow);<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetRow = sheet.createRow(starRow + 1);<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetRow.setHeight(sourceRow.getHeight());<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (m = sourceRow.getFirstCellNum(); m &lt; sourceRow.getLastCellNum(); m++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sourceCell = sourceRow.getCell(m);<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetCell = targetRow.createCell(m);<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //targetCell.setEncoding(sourceCell.getEncoding());<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetCell.setCellStyle(sourceCell.getCellStyle());<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetCell.setCellType(sourceCell.getCellType());<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targetCell.setCellValue(i);//設置值<br />
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; &nbsp;FileOutputStream fileOut = new FileOutputStream("workbook.xls");<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; wb.write(fileOut);<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; fileOut.close();<br />
&nbsp;&nbsp; }</p>
<span class="Apple-style-span" style="word-spacing: 0px; font: 12px/18px Arial; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; text-align: left; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0">参考了http://blog.csdn.net/daemon_boy/archive/2007/09/15/1786384.aspx的代码</span>
<img src ="http://www.blogjava.net/keweibo/aggbug/265998.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/keweibo/" target="_blank">KE</a> 2009-04-16 16:43 <a href="http://www.blogjava.net/keweibo/articles/265998.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>