<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>程序人生</title>
	<atom:link href="http://justdoblogger.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://justdoblogger.com/blog</link>
	<description>又一个 WordPress 博客</description>
	<lastBuildDate>Sun, 08 Aug 2010 08:41:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.NET做项目时发现Page_Load被执行两次</title>
		<link>http://justdoblogger.com/blog/201008/pageloadtwice.html</link>
		<comments>http://justdoblogger.com/blog/201008/pageloadtwice.html#comments</comments>
		<pubDate>Sun, 08 Aug 2010 08:36:35 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[imagebutton]]></category>
		<category><![CDATA[Page_Load]]></category>
		<category><![CDATA[执行两次]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/201008/asp-net%e5%81%9a%e9%a1%b9%e7%9b%ae%e6%97%b6%e5%8f%91%e7%8e%b0page_load%e8%a2%ab%e6%89%a7%e8%a1%8c%e4%b8%a4%e6%ac%a1.html</guid>
		<description><![CDATA[前几天,在做ASP.NET时,发现我在点击页面上的按钮时,该页面的Page_Load事件总是被执行两次.于是仔细检查代码,没发现有任何有问题的地方.后来没辙,就到google上寻求帮助,原来遇到和我同样问题的人还真不少,莫非是微软的BUG?呵呵.
]]></description>
			<content:encoded><![CDATA[<p>前几天,在做ASP.NET时,发现我在点击页面上的按钮时,该页面的Page_Load事件有时被执行两次.真是奇怪,不是每一次,而是有时.于是仔细检查代码,没发现有任何有问题的地方.后来没辙,就到google上寻求帮助,原来遇到和我同样问题的人还真不少,莫非是微软的BUG?呵呵.<br />
按照网上的说法:<br />
第一:页面属性定义AutoEventWireup=&#8221;false&#8221;有没有添加?(排除,因为页面创建时,这是默认被添加的)<br />
第二:有没有类似&lt;img src=&#8221;"&gt;这样的标签存在,如有,很可能就是执行两次的原因.发现网上遇到这种情况的人特多.都说如果去掉这样的空标签,问题就能得到解决.<br />
我一时兴奋了,貌似终于找到解决方法了.可是检查了我页面代码,这样的空标签还真没有,倒是有类似的,按钮我是使用的,翻译成HTML就是这样的&lt;input  type=&#8221;image&#8221; src=&#8221;&#8230;..&#8221;/&gt;,真的和这个图片按钮有关吗?可是不用图片按钮,按钮又太难看了.不管怎么说,先换成普通按钮试试吧.改按钮imagebutton为普通button之后,问题真的解决了.看来问题真是出在按钮类型上啊,可是不用这个,按钮也太难看了,怎么办呢?想了想,不用这个,那直接用image行不行呢?<br />
于是将按钮类型换成image,翻译成HTML&lt;img id=&#8221;imgbutton&#8221; src=&#8221;&#8230;&#8221; /&gt;.执行,OK,大功告成,解决了.<br />
至于为什么imagebutton的类型按钮按下后,Page_Load事件就有时被执行两次,实在是不能理解,在网上也搜索了,也没找到原因,希望有知道的能教教我哦.</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/201008/pageloadtwice.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NHK日本语视频讲座 01</title>
		<link>http://justdoblogger.com/blog/201007/nihongodekurasou-01.html</link>
		<comments>http://justdoblogger.com/blog/201007/nihongodekurasou-01.html#comments</comments>
		<pubDate>Sun, 25 Jul 2010 14:51:37 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[在线视频]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/201007/nhk%e6%97%a5%e6%9c%ac%e8%af%ad%e8%a7%86%e9%a2%91%e8%ae%b2%e5%ba%a7-01.html</guid>
		<description><![CDATA[第一次做自己的视频网站,感觉还不错,只是美中不足的是,我用的是试用版插件,所以在视频上总有去不掉的DEMO字样,不过应该不影响观看吧.以后有空再研究看看.

好了,先分享日本语讲座第一课吧.]]></description>
			<content:encoded><![CDATA[<p>第一次做自己的视频网站,感觉还不错,只是美中不足的是,我用的是试用版插件,所以在视频上总有去不掉的DEMO字样,不过应该不影响观看吧.以后有空再研究看看.</p>
<p>好了,先分享日本语讲座第一课吧.</p>
<p>
<span id="video0" class="HDFLV">
<a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</span>
<script type="text/javascript">
var s0 = new SWFObject("http://justdoblogger.com/blog/wp-content/plugins/contus-hd-flv-player/hdflvplayer/hdplayer.swf","n0","450","280","7");
s0.addParam("allowfullscreen","true");
s0.addParam("allowscriptaccess","always");
s0.addParam("wmode","opaque");
s0.addVariable("id","n0");
s0.addVariable("skin_autohide","true");
s0.addVariable("logoalpha","50");
s0.addVariable("normalscale","0");
s0.addVariable("fullscreenscale","0");
s0.addVariable("logopath","platoon.png");
s0.addVariable("stagecolor","0x000000");
s0.addVariable("autoplay","false");
s0.addVariable("buffer","1");
s0.addVariable("Volume","50");
s0.addVariable("height","280");
s0.addVariable("width","450");
s0.addVariable("skin","http://justdoblogger.com/blog/wp-content/plugins/contus-hd-flv-player/hdflvplayer/skin/skin_black/skin_black.swf");
s0.addVariable("zoom","true");
s0.addVariable("timer","true");
s0.addVariable("fullscreen","true");
s0.addVariable("display_logo","true");
s0.addVariable("share","true");
s0.addVariable("playlist","true");
s0.addVariable("usedefault","1");
s0.addVariable("","wp-content/uploads");
s0.addVariable("logo_target","http://hdflvplayer.net/wordpress/");
s0.addVariable("playlist","false");
s0.addVariable("logopath","http://justdoblogger.com/blog/wp-content/plugins/contus-hd-flv-player/hdflvplayer/images/platoon.png");
s0.addVariable("file","http://justdoblogger.com/blog/wp-content/uploads/2010/07/Nihongo de Kurasou 01 Asking Questions.flv");
s0.addVariable("Preview","");
s0.write("video0");
</script>
</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/201007/nihongodekurasou-01.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>POI设置单元格字体</title>
		<link>http://justdoblogger.com/blog/201005/setfontname.html</link>
		<comments>http://justdoblogger.com/blog/201005/setfontname.html#comments</comments>
		<pubDate>Sat, 22 May 2010 10:24:12 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[示例程序]]></category>
		<category><![CDATA[HSSFCellStyle]]></category>
		<category><![CDATA[HSSFROW]]></category>
		<category><![CDATA[POI]]></category>
		<category><![CDATA[setcellvalue]]></category>
		<category><![CDATA[setFontName]]></category>
		<category><![CDATA[setSheetName]]></category>
		<category><![CDATA[Sheet]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/201005/poi%e8%ae%be%e7%bd%ae%e5%8d%95%e5%85%83%e6%a0%bc%e5%ad%97%e4%bd%93.html</guid>
		<description><![CDATA[这一节来试试看，如何用POI来指定单元格文字或数字的字体。指定字体时，使用「HSSFCellStyle」类的「setFont」方法。]]></description>
			<content:encoded><![CDATA[<p>这一节来试试看，如何用POI来指定单元格文字或数字的字体。指定字体时，使用「HSSFCellStyle」类的「setFont」方法。</p>
<pre class="methodt">setFont
public void setFont(HSSFFont font)</pre>
<pre class="methodc">set the font for this style 

Parameters:
  font - a font object created or retreived
from the HSSFWorkbook object</pre>
<p>参数是表示字体的「HSSFFont」类对象。关于「HSSFFont」类的定义，详见如下：</p>
<h2>HSSFFont类定义</h2>
<div class="classwaku">
<ul class="classdirectory">
<li class="top">java.lang.Object</li>
<li class="row1">org.apache.poi.hssf.usermodel.HSSFFont</li>
<li class="detail">public class HSSFFont extends java.lang.Object</li>
</ul>
</div>
<p>虽然有一个构造方法，但仍然是protected的，还是不能直接使用。必须通过「HSSFWorkbook」类的「createFont」方法来生成。</p>
<pre class="methodt">createFont
public HSSFFont createFont()</pre>
<pre class="methodc">create a new Font and add it to the workbook's font table 

Returns:
  new font object</pre>
<p>使用方法如下：</p>
<pre class="fixmidcode">HSSFWorkbook workbook = new HSSFWorkbook();

HSSFFont font = workbook.createFont();
HSSFCellStyle style = workbook.createCellStyle();

style.setFont(font);</pre>
<h2>字体的指定</h2>
<p>下面就具体看看如何设定字体。指定字体使用「HSSFFont」类的「setFontName」方法。</p>
<pre class="methodt">setFontName
public void setFontName(java.lang.String name)</pre>
<pre class="methodc">set the name for the font (i.e. Arial) 

Parameters:
  name - String representing the name of the font to use</pre>
<p>参数是字体名称。如「Arial Black」和「华文彩云」等。另外还有一点要说明的是，如果你要设置中文字体，那必须还要再对单元格进行编码设置</p>
<p>(font.setCharSet(HSSFFont.DEFAULT_CHARSET))，否则无效。</p>
<h2>示例程序</h2>
<p>实际动手做做看吧。</p>
<pre class="fixsmallcode">import java.io.*;

import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row0 = sheet.createRow(0);
    HSSFCell cell0 = row0.createCell(1);

    HSSFCellStyle style0 = workbook.createCellStyle();
    HSSFFont font0 = workbook.createFont();
    font0.setFontName("Arial Black");
    style0.setFont(font0);
    cell0.setCellStyle(style0);
    cell0.setCellValue(new HSSFRichTextString("Arial Black"));

    HSSFRow row1 = sheet.createRow(1);
    HSSFCell cell1 = row1.createCell(1);

    HSSFCellStyle style1 = workbook.createCellStyle();
    HSSFFont font1 = workbook.createFont();
    font1.setFontName("华文彩云");
    font1.setCharSet(HSSFFont.DEFAULT_CHARSET);
    style1.setFont(font1);
    cell1.setCellStyle(style1);
    cell1.setCellValue(new HSSFRichTextString("华文彩云"));

    HSSFRow row2 = sheet.createRow(2);
    HSSFCell cell2 = row2.createCell(1);

    HSSFCellStyle style2 = workbook.createCellStyle();
    HSSFFont font2 = workbook.createFont();
    font2.setFontName("隶书");
    font2.setCharSet(HSSFFont.DEFAULT_CHARSET);
    style2.setFont(font2);
    cell2.setCellStyle(style2);
    cell2.setCellValue(new HSSFRichTextString("隶书"));

    HSSFRow row3 = sheet.createRow(3);
    HSSFCell cell3 = row3.createCell(1);

    HSSFCellStyle style3 = workbook.createCellStyle();
    HSSFFont font3 = workbook.createFont();
    font3.setFontName("华文行楷");
    //font3.setCharSet(HSSFFont.DEFAULT_CHARSET);
    style3.setFont(font3);
    cell3.setCellStyle(style3);
    cell3.setCellValue(new HSSFRichTextString("华文行楷"));

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}</pre>
<p>运行结果如下：</p>
<p><img src="./WS000000.JPG" alt="字体指定" width="400" height="338" /></p>
<p>另外，要取得可以指定的字体，最简单的方法就是，打开Excel文件，从字体选择的地方直接复制过来就可以了。</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/201005/setfontname.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://justdoblogger.com/blog/200910/Mr.Children_-_Shirushi.mp3" length="10365248" type="audio/mpeg" />
		</item>
		<item>
		<title>POI设置边框</title>
		<link>http://justdoblogger.com/blog/200912/setborder.html</link>
		<comments>http://justdoblogger.com/blog/200912/setborder.html#comments</comments>
		<pubDate>Sat, 05 Dec 2009 13:41:32 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[边框的种类]]></category>
		<category><![CDATA[边框的顔色]]></category>
		<category><![CDATA[边框的位置]]></category>
		<category><![CDATA[getCell]]></category>
		<category><![CDATA[HSSFWorkBook]]></category>
		<category><![CDATA[POI设置边框]]></category>
		<category><![CDATA[setBorder]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200912/poi%e8%ae%be%e7%bd%ae%e8%be%b9%e6%a1%86.html</guid>
		<description><![CDATA[在做一个电子表格时，边框的设置有时是必不可少的。这一节就来介绍边框，设置时，可以指定边框的位置，边框的种类，边框的顔色。]]></description>
			<content:encoded><![CDATA[<p>在做一个电子表格时，边框的设置有时是必不可少的。这一节就来介绍边框，设置时，可以指定边框的位置，边框的种类，边框的顔色。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<p>首先是边框的位置和种类。对单元格设置边框时，有上下左右位置之分，所以POI也准备了四个不同的方法。
			</p>
<p>
			上部的边框：
			</p>
<pre class="methodt">
setBorderTop
public void setBorderTop(short border)
</pre>
<pre class="methodc">
set the type of border to use for the top
border of the cell 

Parameters:
  border - type
</pre>
<p>
			下部的边框：
			</p>
<pre class="methodt">
setBorderBottom
public void setBorderBottom(short border)
</pre>
<pre class="methodc">
set the type of border to use for the
bottom border of the cell 

Parameters:
  border - type
</pre>
<p>
			左侧的边框：
			</p>
<pre class="methodt">
setBorderLeft
public void setBorderLeft(short border)
</pre>
<pre class="methodc">
set the type of border to use for the
left border of the cell 

Parameters:
  border - type
</pre>
<p>
			右侧的边框：
			</p>
<pre class="methodt">
setBorderRight
public void setBorderRight(short border)
</pre>
<pre class="methodc">
set the type of border to use for the
right border of the cell 

Parameters:
  border - type
</pre>
<p>参数通过表示边框种类的short型值来指定。下面是定义在「HSSFCellStyle」类里可以被指定值的一览表。
			</p>
<table class="pro">
<tr>
<th>值</th>
<th>说明</th>
</tr>
<tr>
<td>BORDER_DASH_DOT</td>
<td>dash-dot border</td>
</tr>
<tr>
<td>BORDER_DASH_DOT_DOT</td>
<td>dash-dot-dot border</td>
</tr>
<tr>
<td>BORDER_DASHED</td>
<td>dash border</td>
</tr>
<tr>
<td>BORDER_DOTTED</td>
<td>dot borderhair-line border</td>
</tr>
<tr>
<td>BORDER_DOUBLE</td>
<td>double-line border</td>
</tr>
<tr>
<td>BORDER_HAIR</td>
<td>hair-line border</td>
</tr>
<tr>
<td>BORDER_MEDIUM</td>
<td>Medium border</td>
</tr>
<tr>
<td>BORDER_MEDIUM_DASH_DOT</td>
<td>medium dash-dot border</td>
</tr>
<tr>
<td>BORDER_MEDIUM_DASH_DOT_DOT</td>
<td>medium dash-dot-dot border</td>
</tr>
<tr>
<td>BORDER_MEDIUM_DASHED</td>
<td>Medium dashed border</td>
</tr>
<tr>
<td>BORDER_NONE</td>
<td>No border</td>
</tr>
<tr>
<td>BORDER_SLANTED_DASH_DOT</td>
<td>slanted dash-dot border</td>
</tr>
<tr>
<td>BORDER_THICK</td>
<td>Thick border</td>
</tr>
<tr>
<td>BORDER_THIN</td>
<td>Thin border</td>
</tr>
</table>
<p>比如要在单元格下边框设置两重线的边框时，按如下方法：
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFCellStyle style = workbook.createCellStyle();
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
</pre>
<p>下面再看看指定边框顔色。同样也分为上下左右边框来操作。
			</p>
<p>
			上部的边框：
			</p>
<pre class="methodt">
setTopBorderColor
public void setTopBorderColor(short color)
</pre>
<pre class="methodc">
set the color to use for the top border 

Parameters:
  color -
</pre>
<p>
			下部的边框：
			</p>
<pre class="methodt">
setBottomBorderColor
public void setBottomBorderColor(short color)
</pre>
<pre class="methodc">
set the color to use for the bottom border 

Parameters:
  color -
</pre>
<p>
			左侧的边框：
			</p>
<pre class="methodt">
setLeftBorderColor
public void setLeftBorderColor(short color)
</pre>
<pre class="methodc">
set the color to use for the left border 

Parameters:
  color -
</pre>
<p>
			右侧的边框：
			</p>
<pre class="methodt">
setRightBorderColor
public void setRightBorderColor(short color)
</pre>
<pre class="methodc">
set the color to use for the right border 

Parameters:
  color -
</pre>
<p>仍然是通过参数来指定顔色，而且使用方法和前面一节也是一样。具体如下：
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFCellStyle style = workbook.createCellStyle();
style.setRightBorderColor(HSSFColor.RED.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
</pre>
<h2>示例程序</h2>
<p>实际动手做做吧。首先看看如何设置上下左右的边框。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.usermodel.HSSFPalette;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row = sheet.createRow(1);
    HSSFCell cell1 = row.createCell((short)1);
    HSSFCell cell2 = row.createCell((short)2);

    HSSFCellStyle style1 = workbook.createCellStyle();
    style1.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);
    style1.setBorderLeft(HSSFCellStyle.BORDER_DOUBLE);
    style1.setTopBorderColor(HSSFColor.GOLD.index);
    style1.setLeftBorderColor(HSSFColor.PLUM.index);
    cell1.setCellStyle(style1);

    HSSFCellStyle style2 = workbook.createCellStyle();
    style2.setBorderBottom(HSSFCellStyle.BORDER_DOUBLE);
    style2.setBorderRight(HSSFCellStyle.BORDER_DOUBLE);
    style2.setBottomBorderColor(HSSFColor.ORANGE.index);
    style2.setRightBorderColor(HSSFColor.SKY_BLUE.index);
    cell2.setCellStyle(style2);

    cell1.setCellValue("U &#038; L");
    cell2.setCellValue("B &#038; R");

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>上面程序既改了顔色，也设置了上和左的边框各一个，右和下的边框各一个。
			</p>
<p>
			<img src="./WS000001.JPG" alt="上下左右边框" width="478" >
			</p>
<p>下面再对边框种类进行各种各样的顔色改变来看看效果。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;

public class POISample{
  static HSSFWorkbook workbook;

  public static void main(String[] args){
    workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row[] = new HSSFRow[5];
    for (int i = 0; i &lt; 5 ; i++){
      row[i] = sheet.createRow(i);
    }

    HSSFCell cell[][] = new HSSFCell[5][3];
    for (int i = 0; i &lt; 5; i++){
      for (int j = 0; j &lt; 3 ; j++){
        cell[i][j] = row[i].createCell((short)j);
      }
    }

    setStyle(cell[0][0], "DASH_DOT",
                          HSSFCellStyle.BORDER_DASH_DOT);
    setStyle(cell[0][1], "DASH_DOT_DOT",
                          HSSFCellStyle.BORDER_DASH_DOT_DOT);
    setStyle(cell[0][2], "DASHED",
                          HSSFCellStyle.BORDER_DASHED);

    setStyle(cell[1][0], "DOTTED",
                          HSSFCellStyle.BORDER_DOTTED);
    setStyle(cell[1][1], "DOUBLE",
                          HSSFCellStyle.BORDER_DOUBLE);
    setStyle(cell[1][2], "HAIR",
                          HSSFCellStyle.BORDER_HAIR);

    setStyle(cell[2][0], "MEDIUM",
                          HSSFCellStyle.BORDER_MEDIUM);
    setStyle(cell[2][1], "MEDIUM_DASH_DOT",
                          HSSFCellStyle.BORDER_MEDIUM_DASH_DOT);
    setStyle(cell[2][2], "MEDIUM_DASH_DOT_DOT",
                          HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT);

    setStyle(cell[3][0], "MEDIUM_DASHED",
                          HSSFCellStyle.BORDER_MEDIUM_DASHED);
    setStyle(cell[3][1], "NONE",
                          HSSFCellStyle.BORDER_NONE);
    setStyle(cell[3][2], "SLANTED_DASH_DOT",
                          HSSFCellStyle.BORDER_SLANTED_DASH_DOT);

    setStyle(cell[4][0], "THICK", HSSFCellStyle.BORDER_THICK);
    setStyle(cell[4][1], "THIN", HSSFCellStyle.BORDER_THIN);

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }

  public static void setStyle(HSSFCell cell,
                          String bn, short border){
    HSSFCellStyle style = workbook.createCellStyle();
    style.setBorderBottom(border);
    style.setBottomBorderColor(HSSFColor.ORANGE.index);
    cell.setCellStyle(style);

    cell.setCellValue(bn);
  }
}
</pre>
<p>运行结果如下：
			</p>
<p>
			<img src="./WS000002.JPG" alt="边框种类改变" width="478" >
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200912/setborder.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>POI调色板操作</title>
		<link>http://justdoblogger.com/blog/200912/hssfpalette.html</link>
		<comments>http://justdoblogger.com/blog/200912/hssfpalette.html#comments</comments>
		<pubDate>Sat, 05 Dec 2009 12:55:58 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[getCustomPalette]]></category>
		<category><![CDATA[HSSFCell]]></category>
		<category><![CDATA[HSSFPalette]]></category>
		<category><![CDATA[HSSFWorkBook]]></category>
		<category><![CDATA[POI调色板]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200912/poi%e8%b0%83%e8%89%b2%e6%9d%bf%e6%93%8d%e4%bd%9c.html</guid>
		<description><![CDATA[上一节介绍了如何设定POI里已经准备好的顔色，但有时你想要的顔色不在这个范围内，怎么办呢？这一节就来介绍如何使用调色板的RGB的值来设定你喜欢的顔色。]]></description>
			<content:encoded><![CDATA[<p>上一节介绍了如何设定POI里已经准备好的顔色，但有时你想要的顔色不在这个范围内，怎么办呢？这一节就来介绍如何使用调色板的RGB的值来设定你喜欢的顔色。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<p>要创建一个新的颜色，在调色板里如果有这个对应值那当然没问题。那有没有可能你想要的顔色在调色板里也没有呢？关于这个解决办法还不知道。总之，先从有对应值的来做做看吧。
			</p>
<p>首先取出现在正在使用的调色板。调色板是由「HSSFPalette」类定义的。其定义如下：
			</p>
<div class="classwaku">
<ul class="classdirectory">
<li class="top">java.lang.Object</li>
<li class="row1">org.apache.poi.hssf.usermodel.HSSFPalette</li>
<li class="detail">public class HSSFPalette extends java.lang.Object</li>
</ul>
</div>
<p>构造方法虽然有一个，但仍然是protected的，所以也不能直接使用，而要用「HSSFWorkbook」类的「getCustomPalette」方法来取得调色板对象。
			</p>
<pre class="methodt">
getCustomPalette
public HSSFPalette getCustomPalette()
</pre>
<pre class="methodc">
--
</pre>
<p>非常遗憾，该方法也是没有任何说明，原因不明。先按下面的方法使用吧。
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFPalette palette = workbook.getCustomPalette();
</pre>
<p>调色板取得后，就可以使用「HSSFPalette」类的「setColorAtIndex」方法设定自己想要的顔色了。
			</p>
<pre class="methodt">
setColorAtIndex
public void setColorAtIndex(short index,
              byte red, byte green, byte blue)
</pre>
<pre class="methodc">
Sets the color at the given offset 

Parameters:
  index - the palette index, between 0x8 to
          0x40 inclusive
  red - the RGB red component, between 0
          and 255 inclusive
  green - the RGB green component, between 0
          and 255 inclusive
  blue - the RGB blue component, between 0
          and 255 inclusive
</pre>
<p>第一个参数设定你想要顔色的主色调的index号，如上一节一样，使用「HSSFColor」类的子类。
			</p>
<pre class="fixbig">
HSSFColor.RED.index
</pre>
<p>剩下的三个参数，通过设定RGB值来调节你想要的顔色。每一个都可以设定0～255的值。
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex(HSSFColor.RED.index,
                 (byte)100, (byte)0, (byte)0);
</pre>
<h2>示例程序</h2>
<p>自己做做看吧，首先要确定你想要顔色的主色调。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row = sheet.createRow(1);
    HSSFCell cell = row.createCell((short)1);

    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.RED.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cell.setCellStyle(style);

    cell.setCellValue("RED");

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>上面程序对一个单元格设定了红色「HSSFColor.RED」的主色调，运行结果如下：
			</p>
<p>
			<img src="./WS000008.JPG" alt="调色板示例" width="478">
			</p>
<p>下面就对这个顔色通过RGB值来做一些改动吧。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.usermodel.HSSFPalette;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFPalette palette = workbook.getCustomPalette();
    palette.setColorAtIndex(HSSFColor.RED.index,
                    (byte)128, (byte)0, (byte)0);

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row = sheet.createRow(1);
    HSSFCell cell = row.createCell((short)1);

    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.RED.index);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cell.setCellStyle(style);

    cell.setCellValue("RED");

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>上面程序使用调色板对红色「HSSFColor.RED」进行了一些改动，之后用前面一个例子的方法同样设定红色，但得到的结果却是不一样的。运行结果如下：
			</p>
<p>
			<img src="./WS000000.JPG" alt="调色板示例" width="478">
			</p>
<p>因为调色板在一个workbook里是共有的，所以如果用调色板改变了某一种顔色，下次使用时，相同的顔色就全部改变了。</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200912/hssfpalette.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>POI单元格顔色设定</title>
		<link>http://justdoblogger.com/blog/200911/setfillforegroundcolor.html</link>
		<comments>http://justdoblogger.com/blog/200911/setfillforegroundcolor.html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 14:46:57 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[示例程序]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[HSSFCell]]></category>
		<category><![CDATA[HSSFCellStyle]]></category>
		<category><![CDATA[HSSFWorkBook]]></category>
		<category><![CDATA[POI单元格顔色设定]]></category>
		<category><![CDATA[setFillBackgroundColor]]></category>
		<category><![CDATA[setFillForegroundColor]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200911/poi%e5%8d%95%e5%85%83%e6%a0%bc%e9%a1%94%e8%89%b2%e8%ae%be%e5%ae%9a.html</guid>
		<description><![CDATA[先从单元格顔色设定开始介绍。单元格的顔色有前景色和背景色。]]></description>
			<content:encoded><![CDATA[<p>先从单元格顔色设定开始介绍。单元格的顔色有前景色和背景色。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<p>前景色的设定使用「HSSFCellStyle」类的「setFillForegroundColor」方法。
			</p>
<pre class="methodt">
setFillForegroundColor
public void setFillForegroundColor(short bg)
</pre>
<pre class="methodc">
set the foreground fill color 

Parameters:
  bg - color
</pre>
<p>背景色的设定则使用「HSSFCellStyle」类的「setFillBackgroundColor」方法。
			</p>
<pre class="methodt">
setFillBackgroundColor
public void setFillBackgroundColor(short bg)
</pre>
<pre class="methodc">
set the background fill color. 

Parameters:
  bg - color
</pre>
<p>两个方法都是通过参数来设定具体什么顔色。该参数类型为short型，在「HSSFColor」类里，准备了各种各样顔色的定义值。
			</p>
<h2>HSSFColor类</h2>
<p>HSSFColor类定义如下：
			</p>
<div class="classwaku">
<ul class="classdirectory">
<li class="top">java.lang.Object</li>
<li class="row1">org.apache.poi.hssf.util.HSSFColor</li>
<li class="detail">public class HSSFColor extends java.lang.Object</li>
</ul>
</div>
<p>而各种顔色又是作为HSSFColor类的子类，定义一览表如下：
			</p>
<table class="pro">
<tr>
<td>HSSFColor.AQUA</td>
<td>HSSFColor.BLACK</td>
</tr>
<tr>
<td>HSSFColor.BLUE</td>
<td>HSSFColor.BLUE_GREY</td>
</tr>
<tr>
<td>HSSFColor.BRIGHT_GREEN</td>
<td>HSSFColor.BROWN</td>
</tr>
<tr>
<td>HSSFColor.CORAL</td>
<td>HSSFColor.CORNFLOWER_BLUE</td>
</tr>
<tr>
<td>HSSFColor.DARK_BLUE</td>
<td>HSSFColor.DARK_GREEN</td>
</tr>
<tr>
<td>HSSFColor.DARK_RED</td>
<td>HSSFColor.DARK_TEAL</td>
</tr>
<tr>
<td>HSSFColor.DARK_YELLOW</td>
<td>HSSFColor.GOLD</td>
</tr>
<tr>
<td>HSSFColor.GREEN</td>
<td>HSSFColor.GREY_25_PERCENT</td>
</tr>
<tr>
<td>HSSFColor.GREY_40_PERCENT</td>
<td>HSSFColor.GREY_50_PERCENT</td>
</tr>
<tr>
<td>HSSFColor.GREY_80_PERCENT</td>
<td>HSSFColor.INDIGO</td>
</tr>
<tr>
<td>HSSFColor.LAVENDER</td>
<td>HSSFColor.LEMON_CHIFFON</td>
</tr>
<tr>
<td>HSSFColor.LIGHT_BLUE</td>
<td>HSSFColor.LIGHT_CORNFLOWER_BLUE</td>
</tr>
<tr>
<td>HSSFColor.LIGHT_GREEN</td>
<td>HSSFColor.LIGHT_ORANGE</td>
</tr>
<tr>
<td>HSSFColor.LIGHT_TURQUOISE</td>
<td>HSSFColor.LIGHT_YELLOW</td>
</tr>
<tr>
<td>HSSFColor.LIME</td>
<td>HSSFColor.MAROON</td>
</tr>
<tr>
<td>HSSFColor.OLIVE_GREEN</td>
<td>HSSFColor.ORANGE</td>
</tr>
<tr>
<td>HSSFColor.ORCHID</td>
<td>HSSFColor.PALE_BLUE</td>
</tr>
<tr>
<td>HSSFColor.PINK</td>
<td>HSSFColor.PLUM</td>
</tr>
<tr>
<td>HSSFColor.RED</td>
<td>HSSFColor.ROSE</td>
</tr>
<tr>
<td>HSSFColor.ROYAL_BLUE</td>
<td>HSSFColor.SEA_GREEN</td>
</tr>
<tr>
<td>HSSFColor.SKY_BLUE</td>
<td>HSSFColor.TAN</td>
</tr>
<tr>
<td>HSSFColor.TEAL</td>
<td>HSSFColor.TURQUOISE</td>
</tr>
<tr>
<td>HSSFColor.VIOLET</td>
<td>HSSFColor.WHITE</td>
</tr>
<tr>
<td>HSSFColor.YELLOW</td>
<td></td>
</tr>
</table>
<p>设定顔色时，用这些子类的静态常量「index」作为参数，使用方法如下：
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(HSSFColor.LIME.index);
style.setFillBackgroundColor(HSSFColor.GREEN.index);
</pre>
<p>如果这些顔色还不够你用的话，那么下一节再介绍怎么设定自己想要的顔色。
			</p>
<h2>填充模式</h2>
<p>指定填充模式的话，使用「HSSFCellStyle」类的「setFillPattern」方法。
			</p>
<pre class="methodt">
setFillPattern
public void setFillPattern(short fp)
</pre>
<pre class="methodc">
setting to one fills the cell with the foreground color
... No idea about other values 

Parameters:
  fp - fill pattern (set to 1 to fill w/foreground color)
</pre>
<p>指定的填充模式，在「HSSFCellStyle」类里也有定义，类型为static short型，如下所示：
			</p>
<table class="pro">
<tr>
<th>值</th>
<th>说明</th>
</tr>
<tr>
<td>NO_FILL</td>
<td>No background</td>
</tr>
<tr>
<td>SOLID_FOREGROUND</td>
<td>Solidly filled</td>
</tr>
<tr>
<td>FINE_DOTS</td>
<td>Small fine dots</td>
</tr>
<tr>
<td>ALT_BARS</td>
<td>Wide dots</td>
</tr>
<tr>
<td>SPARSE_DOTS</td>
<td>Sparse dots</td>
</tr>
<tr>
<td>THICK_HORZ_BANDS</td>
<td>Thick horizontal bands</td>
</tr>
<tr>
<td>THICK_VERT_BANDS</td>
<td>Thick vertical bands</td>
</tr>
<tr>
<td>THICK_BACKWARD_DIAG</td>
<td>Thick backward facing diagonals</td>
</tr>
<tr>
<td>THICK_FORWARD_DIAG</td>
<td>Thick forward facing diagonals</td>
</tr>
<tr>
<td>BIG_SPOTS</td>
<td>Large spots</td>
</tr>
<tr>
<td>BRICKS</td>
<td>Brick-like layout</td>
</tr>
<tr>
<td>THIN_HORZ_BANDS</td>
<td>Thin horizontal bands</td>
</tr>
<tr>
<td>THIN_VERT_BANDS</td>
<td>Thin vertical bands</td>
</tr>
<tr>
<td>THIN_BACKWARD_DIAG</td>
<td>Thin backward diagonal</td>
</tr>
<tr>
<td>THIN_FORWARD_DIAG</td>
<td>Thin forward diagonal</td>
</tr>
<tr>
<td>SQUARES</td>
<td>Squares</td>
</tr>
<tr>
<td>DIAMONDS</td>
<td>Diamonds</td>
</tr>
</table>
<p>实际的使用方法如下：
			</p>
<pre class="fixmidcode">
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFCellStyle style = workbook.createCellStyle();
style.setFillForegroundColor(HSSFColor.LIME.index);
style.setFillBackgroundColor(HSSFColor.GREEN.index);

style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
</pre>
<h2>示例程序</h2>
<p>这就实际动手做做看吧，首先看一下定义的顔色到底是什么顔色，全部拉上来看看。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;

public class POISample{
  static HSSFWorkbook workbook;

  public static void main(String[] args){
    workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row[] = new HSSFRow[12];
    for (int i = 0; i < 12 ; i++){
      row[i] = sheet.createRow(i);
    }

    HSSFCell cell[][] = new HSSFCell[12][4];
    for (int i = 0; i < 12; i++){
      for (int j = 0; j < 4 ; j++){
        cell[i][j] = row[i].createCell((short)j);
      }
    }

    setStyle(cell[0][0], "AQUA", HSSFColor.AQUA.index);
    setStyle(cell[0][1], "BLACK", HSSFColor.BLACK.index);
    setStyle(cell[0][2], "BLUE", HSSFColor.BLUE.index);
    setStyle(cell[0][3], "BLUE_GREY", HSSFColor.BLUE_GREY.index);
    setStyle(cell[1][0], "BRIGHT_GREEN",
                              HSSFColor.BRIGHT_GREEN.index);
    setStyle(cell[1][1], "BROWN", HSSFColor.BROWN.index);
    setStyle(cell[1][2], "CORAL", HSSFColor.CORAL.index);
    setStyle(cell[1][3], "CORNFLOWER_BLUE",
                              HSSFColor.CORNFLOWER_BLUE.index);
    setStyle(cell[2][0], "DARK_BLUE", HSSFColor.DARK_BLUE.index);
    setStyle(cell[2][1], "DARK_GREEN", HSSFColor.DARK_GREEN.index);
    setStyle(cell[2][2], "DARK_RED", HSSFColor.DARK_RED.index);
    setStyle(cell[2][3], "DARK_TEAL", HSSFColor.DARK_TEAL.index);
    setStyle(cell[3][0], "DARK_YELLOW",
                              HSSFColor.DARK_YELLOW.index);
    setStyle(cell[3][1], "GOLD", HSSFColor.GOLD.index);
    setStyle(cell[3][2], "GREEN", HSSFColor.GREEN.index);
    setStyle(cell[3][3], "GREY_25_PERCENT",
                              HSSFColor.GREY_25_PERCENT.index);
    setStyle(cell[4][0], "GREY_40_PERCENT",
                              HSSFColor.GREY_40_PERCENT.index);
    setStyle(cell[4][1], "GREY_50_PERCENT",
                              HSSFColor.GREY_50_PERCENT.index);
    setStyle(cell[4][2], "GREY_80_PERCENT",
                              HSSFColor.GREY_80_PERCENT.index);
    setStyle(cell[4][3], "INDIGO", HSSFColor.INDIGO.index);
    setStyle(cell[5][0], "LAVENDER", HSSFColor.LAVENDER.index);
    setStyle(cell[5][1], "LEMON_CHIFFON",
                              HSSFColor.LEMON_CHIFFON.index);
    setStyle(cell[5][2], "LIGHT_BLUE",
                              HSSFColor.LIGHT_BLUE.index);
    setStyle(cell[5][3], "LIGHT_CORNFLOWER_BLUE",
                          HSSFColor.LIGHT_CORNFLOWER_BLUE.index);
    setStyle(cell[6][0], "LIGHT_GREEN",
                              HSSFColor.LIGHT_GREEN.index);
    setStyle(cell[6][1], "LIGHT_ORANGE",
                              HSSFColor.LIGHT_ORANGE.index);
    setStyle(cell[6][2], "LIGHT_TURQUOISE",
                              HSSFColor.LIGHT_TURQUOISE.index);
    setStyle(cell[6][3], "LIGHT_YELLOW",
                              HSSFColor.LIGHT_YELLOW.index);
    setStyle(cell[7][0], "LIME", HSSFColor.LIME.index);
    setStyle(cell[7][1], "MAROON", HSSFColor.MAROON.index);
    setStyle(cell[7][2], "OLIVE_GREEN",
                              HSSFColor.OLIVE_GREEN.index);
    setStyle(cell[7][3], "ORANGE", HSSFColor.ORANGE.index);
    setStyle(cell[8][0], "ORCHID", HSSFColor.ORCHID.index);
    setStyle(cell[8][1], "PALE_BLUE", HSSFColor.PALE_BLUE.index);
    setStyle(cell[8][2], "PINK", HSSFColor.PINK.index);
    setStyle(cell[8][3], "PLUM", HSSFColor.PLUM.index);
    setStyle(cell[9][0], "RED", HSSFColor.RED.index);
    setStyle(cell[9][1], "ROSE", HSSFColor.ROSE.index);
    setStyle(cell[9][2], "ROYAL_BLUE",
                              HSSFColor.ROYAL_BLUE.index);
    setStyle(cell[9][3], "SEA_GREEN", HSSFColor.SEA_GREEN.index);
    setStyle(cell[10][0], "SKY_BLUE", HSSFColor.SKY_BLUE.index);
    setStyle(cell[10][1], "TAN", HSSFColor.TAN.index);
    setStyle(cell[10][2], "TEAL", HSSFColor.TEAL.index);
    setStyle(cell[10][3], "TURQUOISE",
                              HSSFColor.TURQUOISE.index);
    setStyle(cell[11][0], "VIOLET", HSSFColor.VIOLET.index);
    setStyle(cell[11][1], "WHITE", HSSFColor.WHITE.index);
    setStyle(cell[11][2], "YELLOW", HSSFColor.YELLOW.index);

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }

  public static void setStyle(HSSFCell cell, String col, short fg){
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(fg);
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cell.setCellStyle(style);

    cell.setCellValue(col);
  }
}
</pre>
<p>上面程序只指定了「ForegroundColor」，填充模式是「SOLID_FOREGROUND」，因此顔色应该是全部充满整个单元格的。运行结果如下：
			</p>
<p>
			<img src="./WS000006.JPG" alt="顔色指定" width="401" >
			</p>
<p>下面再对填充模式进行各种修改来看看。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;

public class POISample{
  static HSSFWorkbook workbook;

  public static void main(String[] args){
    workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row[] = new HSSFRow[5];
    for (int i = 0; i < 5 ; i++){
      row[i] = sheet.createRow(i);
    }

    HSSFCell cell[][] = new HSSFCell[5][4];
    for (int i = 0; i < 5; i++){
      for (int j = 0; j < 4 ; j++){
        cell[i][j] = row[i].createCell((short)j);
      }
    }

    setStyle(cell[0][0], "NO_FILL", HSSFCellStyle.NO_FILL);
    setStyle(cell[0][1], "SOLID_FOREGROUND",
                              HSSFCellStyle.SOLID_FOREGROUND);
    setStyle(cell[0][2], "FINE_DOTS", HSSFCellStyle.FINE_DOTS);
    setStyle(cell[0][3], "ALT_BARS", HSSFCellStyle.ALT_BARS);

    setStyle(cell[1][0], "SPARSE_DOTS", HSSFCellStyle.SPARSE_DOTS);
    setStyle(cell[1][1], "THICK_HORZ_BANDS",
                              HSSFCellStyle.THICK_HORZ_BANDS);
    setStyle(cell[1][2], "THICK_VERT_BANDS",
                              HSSFCellStyle.THICK_VERT_BANDS);
    setStyle(cell[1][3], "THICK_BACKWARD_DIAG",
                              HSSFCellStyle.THICK_BACKWARD_DIAG);

    setStyle(cell[2][0], "THICK_FORWARD_DIAG",
                              HSSFCellStyle.THICK_FORWARD_DIAG);
    setStyle(cell[2][1], "BIG_SPOTS", HSSFCellStyle.BIG_SPOTS);
    setStyle(cell[2][2], "BRICKS", HSSFCellStyle.BRICKS);
    setStyle(cell[2][3], "THIN_HORZ_BANDS",
                              HSSFCellStyle.THIN_HORZ_BANDS);

    setStyle(cell[3][0], "THIN_VERT_BANDS",
                              HSSFCellStyle.THIN_VERT_BANDS);
    setStyle(cell[3][1], "THIN_BACKWARD_DIAG",
                              HSSFCellStyle.THIN_BACKWARD_DIAG);
    setStyle(cell[3][2], "THIN_FORWARD_DIAG",
                              HSSFCellStyle.THIN_FORWARD_DIAG);
    setStyle(cell[3][3], "SQUARES", HSSFCellStyle.SQUARES);

    setStyle(cell[4][0], "DIAMONDS", HSSFCellStyle.DIAMONDS);

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }

  public static void setStyle(HSSFCell cell, String fps,
                              short fp){
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.WHITE.index);
    style.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);
    style.setFillPattern(fp);
    cell.setCellStyle(style);

    cell.setCellValue(fps);
  }
}
</pre>
<p>上面固定了「ForegroundColor」和「BackgroundColor」，而填充模式则做了各种尝试。运行结果如下：
			</p>
<p>
			<img src="./WS000007.JPG" alt="填充模式指定" width="399">
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200911/setfillforegroundcolor.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HSSFCellStyle类定义</title>
		<link>http://justdoblogger.com/blog/200911/hssfcellstyle.html</link>
		<comments>http://justdoblogger.com/blog/200911/hssfcellstyle.html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 13:54:38 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[getCell]]></category>
		<category><![CDATA[getCellStyle]]></category>
		<category><![CDATA[HSSFCell]]></category>
		<category><![CDATA[HSSFCellStyle]]></category>
		<category><![CDATA[HSSFWorkBook]]></category>
		<category><![CDATA[setCellStyle]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200911/hssfcellstyle%e7%b1%bb%e5%ae%9a%e4%b9%89.html</guid>
		<description><![CDATA[这一节开始介绍如何通过POI来进行单元格格式的设定。设定格式使用「HSSFCellStyle」类，关于它的类定义如下：]]></description>
			<content:encoded><![CDATA[<p>这一节开始介绍如何通过POI来进行单元格格式的设定。设定格式使用「HSSFCellStyle」类，关于它的类定义如下：
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="classwaku">
<ul class="classdirectory">
<li class="top">java.lang.Object</li>
<li class="row1">org.apache.poi.hssf.usermodel.HSSFCellStyle</li>
<li class="detail">public class HSSFCellStyle extends java.lang.Object</li>
</ul>
</div>
<p>
			它有一个构造方法。
			</p>
<table class="const">
<tr>
<th>构造方法</th>
</tr>
<tr>
<td><span class="title">protected HSSFCellStyle(short index, ExtendedFormatRecord rec)</span><br />Creates new HSSFCellStyle why would you want to do this??</td>
</tr>
</table>
<p>虽然有构造方法，但却是protected的，所以不能直接使用，要通过一个工作簿workbook来生成格式对象。
			</p>
<p>在POI里，格式好像是以workbook为单位来管理的，所以要先作成一个格式对象，保存在workbook里，然后再对已生成好的单元格进行设定。
			</p>
<h2>在单元格里指定格式</h2>
<p>要作成一个格式对象，可以使用「HSSFWorkbook」类的「createCellStyle」方法。
			</p>
<pre class="methodt">
createCellStyle
public HSSFCellStyle createCellStyle()
</pre>
<pre class="methodc">
create a new Cell style and add it to the workbook's style table 

Returns:
  the new Cell Style object
</pre>
<p>另外，要取出现有的格式对象的话，使用「HSSFWorkbook」类的「getCellStyleAt」方法，这个方法有参数，是被保存格式的INDEX号。
			</p>
<pre class="methodt">
getCellStyleAt
public HSSFCellStyle getCellStyleAt(short idx)
</pre>
<pre class="methodc">
get the cell style object at the given index 

Parameters:
  idx - index within the set of styles
Returns:
  HSSFCellStyle object at the index
</pre>
<p>还有，对于某一个单元格，也可以取出它的格式对象。这时要使用「HSSFCell」类的「getCellStyle」方法。
			</p>
<pre class="methodt">
getCellStyle
public HSSFCellStyle getCellStyle()
</pre>
<pre class="methodc">
get the style for the cell. This is a reference to a cell style
contained in the workbook object.
</pre>
<p>这样的话，不管是新创建的或者是从现有的单元格里取出来的格式对象，都可以用来对某一个单元格进行格式的设定。设定方法使用「HSSFCell」类的「setCellStyle」方法。
			</p>
<pre class="methodt">
setCellStyle
public void setCellStyle(HSSFCellStyle style)
</pre>
<pre class="methodc">
set the style for the cell. The style should be an HSSFCellStyle
created/retreived from the HSSFWorkbook. 

Parameters:
  style - reference contained in the workbook
</pre>
<h2>示例程序</h2>
<p>关于格式的详细设定方法，下几节再讲，先做个示例程序来看看。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();
    HSSFRow row = sheet.createRow(1);

    HSSFCell cell = row.createCell((short)0);
    cell.setCellValue("sample");

    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillBackgroundColor(HSSFColor.WHITE.index);
    style.setFillForegroundColor(HSSFColor.LIGHT_ORANGE.index);
    style.setFillPattern(HSSFCellStyle.THICK_HORZ_BANDS);

    cell.setCellStyle(style);

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>按上面程序，在某一个单元格里设定了顔色。运行结果如下：
			</p>
<p>
			<img src="./WS000005.JPG" alt="格式设定" width="399" height="356">
			</p>
<p>好了，从下一节开始详细介绍单元格格式的设定。
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200911/hssfcellstyle.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>POI单元格读取写入函数式</title>
		<link>http://justdoblogger.com/blog/200911/setcellformula.html</link>
		<comments>http://justdoblogger.com/blog/200911/setcellformula.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 14:08:05 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[createCell]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[Excel文件]]></category>
		<category><![CDATA[读取函数式]]></category>
		<category><![CDATA[getCell]]></category>
		<category><![CDATA[getCellFormula]]></category>
		<category><![CDATA[POI]]></category>
		<category><![CDATA[setCellFormula]]></category>
		<category><![CDATA[写入函数式]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200911/poi%e5%8d%95%e5%85%83%e6%a0%bc%e8%af%bb%e5%8f%96%e5%86%99%e5%85%a5%e5%87%bd%e6%95%b0%e5%bc%8f.html</guid>
		<description><![CDATA[单元格里可以写入函数，自动进行计算操作，这也是Excel功能强大的一方面。前面也提到过，使用POI，往单元格里写入函数，使用「setCellFormula」方法，要获取单元格的函数则使用「getCellFormula」方法。
]]></description>
			<content:encoded><![CDATA[<p>单元格里可以写入函数，自动进行计算操作，这也是Excel功能强大的一方面。前面也提到过，使用POI，往单元格里写入函数，使用「setCellFormula」方法，要获取单元格的函数则使用「getCellFormula」方法。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<p>两个方法，在DOC文档里都没有详细说明，原因不明。总之，先动手做做看。首先来看看如何从单元格取出函数式。
			</p>
<p>
			<img src="./WS000003.JPG" alt="函数式取得" width="401" height="352">
			</p>
<p>上图中，在单元格「C:2」里的函数式是「=A2*B2」，「C:3」里的函数式是「=SUM(A3:B3)」。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class POISample{
  public static void main(String[] args){
    FileInputStream in = null;
    HSSFWorkbook workbook = null;

    try{
      in = new FileInputStream("sample.xls");
      POIFSFileSystem fs = new POIFSFileSystem(in);
      workbook = new HSSFWorkbook(fs);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try{
        in.close();
      }catch (IOException e){
        System.out.println(e.toString());
      }
    }

    HSSFSheet sheet = workbook.getSheetAt(0);

    HSSFRow row1 = sheet.getRow(1);

    HSSFCell cell1 = row1.getCell((short)2);
    System.out.println("C:2的函数式 " + cell1.getCellFormula());

    HSSFRow row2 = sheet.getRow(2);

    HSSFCell cell2 = row2.getCell((short)2);
    System.out.println("C:3的函数式 " + cell2.getCellFormula());
  }
}
</pre>
<p>实行结果如下：
			</p>
<pre class="fixmid">
C:2的函数式 A2*B2
C:3的函数式 SUM(A3:B3)
</pre>
<p>如上所示，函数式被正常取出，只是函数式前的「=」被省略了。
			</p>
<p>下面再来看看如何向单元格写入函数式。还是利用之前的Excel文件，「C:2」单元格里写入「A2+B2」，「C:3」单元格里写入「AVERAGE(A3,B3)」这样的函数式。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class POISample{
  public static void main(String[] args){
    FileInputStream in = null;
    HSSFWorkbook workbook = null;

    try{
      in = new FileInputStream("sample.xls");
      POIFSFileSystem fs = new POIFSFileSystem(in);
      workbook = new HSSFWorkbook(fs);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try{
        in.close();
      }catch (IOException e){
        System.out.println(e.toString());
      }
    }

    HSSFSheet sheet = workbook.getSheetAt(0);

    HSSFRow row1 = sheet.getRow(1);
    HSSFCell cell1 = row1.createCell((short)2);
    cell1.setCellFormula("A2+B2");

    HSSFRow row2 = sheet.getRow(2);
    HSSFCell cell2 = row2.createCell((short)2);
    cell2.setCellFormula("AVERAGE(A3,B3)");

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample3.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>
			实行结果如下：
			</p>
<p>
			<img src="./WS000004.JPG" alt="写入函数式" width="402" height="357">
			</p>
<p>到底什么样的函数式可以用，什么样的不能用，这一点还不是很明白，但至少一部分是可以用的。
			</p>
<p>最后要注意的就是，对于使用getCell方法获取的单元格，函数式是不能被写入的。因此对于已经存在的单元格，在写入函数式时，只能先通过createCell方法创建单元格，再写入函数式。
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200911/setcellformula.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POI如何获取单元格内值的类型</title>
		<link>http://justdoblogger.com/blog/200911/getcelltype.html</link>
		<comments>http://justdoblogger.com/blog/200911/getcelltype.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 13:37:48 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[Excel文件]]></category>
		<category><![CDATA[getcelltype]]></category>
		<category><![CDATA[HSSF]]></category>
		<category><![CDATA[HSSFWorkBook]]></category>
		<category><![CDATA[POI]]></category>
		<category><![CDATA[Sheet]]></category>
		<category><![CDATA[单元格内值的类型]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200911/poi%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%8d%95%e5%85%83%e6%a0%bc%e5%86%85%e5%80%bc%e7%9a%84%e7%b1%bb%e5%9e%8b.html</guid>
		<description><![CDATA[在获取单元格值的时候，不同类型，使用的方法也不一样，所以获取之前，必须要知道类型。这一节就来介绍如何知道单元格里的值是何类型。
]]></description>
			<content:encoded><![CDATA[
<p>在获取单元格值的时候，不同类型，使用的方法也不一样，所以获取之前，必须要知道类型。这一节就来介绍如何知道单元格里的值是何类型。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<p>要获取单元格值的类型，使用「HSSFCell」类的「getCellType」方法。
			</p>
<pre class="methodt">
getCellType
public int getCellType()
</pre>
<pre class="methodc">
get the cells type (numeric, formula or string)
</pre>
<p>下面就是类型和定义值的一览表。
			</p>
<table class="pro">
<tr>
<th style="width:100px;">Cell type</th>
<th style="width:200px;">定义值</th>
<th style="width:100px;">值(int)</th>
</tr>
<tr>
<td>Blank</td>
<td>CELL_TYPE_BLANK</td>
<td>3</td>
</tr>
<tr>
<td>Boolean</td>
<td>CELL_TYPE_BOOLEAN</td>
<td>4</td>
</tr>
<tr>
<td>Error</td>
<td>CELL_TYPE_ERROR</td>
<td>5</td>
</tr>
<tr>
<td>Formula</td>
<td>CELL_TYPE_FORMULA</td>
<td>2</td>
</tr>
<tr>
<td>Numeric</td>
<td>CELL_TYPE_NUMERIC</td>
<td>0</td>
</tr>
<tr>
<td>String</td>
<td>CELL_TYPE_STRING</td>
<td>1</td>
</tr>
</table>
<h2>示例程序</h2>
<p>下面来实际动手做做看。按下图准备一个Excel文件。
			</p>
<p>
			<img src="./WS000002.JPG" alt="单元格类型" width="403" height="354">
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class POISample{
  public static void main(String[] args){
    FileInputStream in = null;
    HSSFWorkbook workbook = null;

    try{
      in = new FileInputStream("sample.xls");
      POIFSFileSystem fs = new POIFSFileSystem(in);
      workbook = new HSSFWorkbook(fs);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try{
        in.close();
      }catch (IOException e){
        System.out.println(e.toString());
      }
    }

    HSSFSheet sheet = workbook.getSheetAt(0);
    HSSFRow row = sheet.getRow(1);

    HSSFCell cell = row.getCell((short)0);
    System.out.println("A:2=" + getType(cell.getCellType()));

    cell = row.getCell((short)1);
    System.out.println("B:2=" + getType(cell.getCellType()));

    cell = row.getCell((short)2);
    System.out.println("C:2=" + getType(cell.getCellType()));

    cell = row.getCell((short)3);
    System.out.println("D:2=" + getType(cell.getCellType()));

    cell = row.getCell((short)4);
    System.out.println("E:2=" + getType(cell.getCellType()));
  }

  public static String getType(int type){
    if (type == HSSFCell.CELL_TYPE_BLANK){
      return "CELL_TYPE_BLANK";
    }else if (type == HSSFCell.CELL_TYPE_BOOLEAN){
      return "CELL_TYPE_BOOLEAN";
    }else if (type == HSSFCell.CELL_TYPE_ERROR){
      return "CELL_TYPE_ERROR";
    }else if (type == HSSFCell.CELL_TYPE_FORMULA){
      return "CELL_TYPE_FORMULA";
    }else if (type == HSSFCell.CELL_TYPE_NUMERIC){
      return "CELL_TYPE_NUMERIC";
    }else if (type == HSSFCell.CELL_TYPE_STRING){
      return "CELL_TYPE_STRING";
    }else{
      return "Not defined";
    }
  }
}
</pre>
<p>
			实行结果如下：
			</p>
<pre class="fixmid">
A:2=CELL_TYPE_NUMERIC
B:2=CELL_TYPE_STRING
C:2=CELL_TYPE_BOOLEAN
D:2=CELL_TYPE_NUMERIC
E:2=CELL_TYPE_ERROR
</pre>
<p>有一点要注意的是，数值型和日期型都是「CELL_TYPE_NUMERIC」。
			</p>
<h2>日期型检查</h2>
<p>到底是数值型还是日期型，可以通过「org.apache.poi.hssf.usermodel.HSSFDateUtil」类的「isCellDateFormatted」方法来检证。
			</p>
<pre class="methodt">
isCellDateFormatted
public static boolean isCellDateFormatted(HSSFCell cell)
</pre>
<pre class="methodc">
Check if a cell contains a date Since dates are
stored internally in Excel as double values we
infer it is a date if it is formatted as such.
</pre>
<p>因为这个方法是静态的，可以直接调用如下所示。
			</p>
<pre class="fixmidcode">
if (HSSFDateUtil.isCellDateFormatted(cell)){
    /* 日期型 */
}
</pre>
<p>现在就把之前的示例程序稍微改动一下，再运行看看。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;

public class POISample{
  public static void main(String[] args){
    FileInputStream in = null;
    HSSFWorkbook workbook = null;

    try{
      in = new FileInputStream("sample.xls");
      POIFSFileSystem fs = new POIFSFileSystem(in);
      workbook = new HSSFWorkbook(fs);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try{
        in.close();
      }catch (IOException e){
        System.out.println(e.toString());
      }
    }

    HSSFSheet sheet = workbook.getSheetAt(0);
    HSSFRow row = sheet.getRow(1);

    HSSFCell cell = row.getCell((short)0);
    System.out.println("A:2=" + getType(cell));

    cell = row.getCell((short)1);
    System.out.println("B:2=" + getType(cell));

    cell = row.getCell((short)2);
    System.out.println("C:2=" + getType(cell));

    cell = row.getCell((short)3);
    System.out.println("D:2=" + getType(cell));

    cell = row.getCell((short)4);
    System.out.println("E:2=" + getType(cell));
  }

  public static String getType(HSSFCell cell){
    int type = cell.getCellType();

    if (type == HSSFCell.CELL_TYPE_BLANK){
      return "CELL_TYPE_BLANK";
    }else if (type == HSSFCell.CELL_TYPE_BOOLEAN){
      return "CELL_TYPE_BOOLEAN";
    }else if (type == HSSFCell.CELL_TYPE_ERROR){
      return "CELL_TYPE_ERROR";
    }else if (type == HSSFCell.CELL_TYPE_FORMULA){
      return "CELL_TYPE_FORMULA";
    }else if (type == HSSFCell.CELL_TYPE_NUMERIC){
      if (HSSFDateUtil.isCellDateFormatted(cell)){
        return "CELL_TYPE_DATE";
      }else{
        return "CELL_TYPE_NUMERIC";
      }
    }else if (type == HSSFCell.CELL_TYPE_STRING){
      return "CELL_TYPE_STRING";
    }else{
      return "Not defined";
    }
  }
}
</pre>
<p>
			实行结果如下：
			</p>
<pre class="fixmid">
A:2=CELL_TYPE_NUMERIC
B:2=CELL_TYPE_STRING
C:2=CELL_TYPE_BOOLEAN
D:2=CELL_TYPE_DATE
E:2=CELL_TYPE_ERROR
</pre>
<p>这一次，日期型也可以被检查出来了。
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200911/getcelltype.html/feed</wfw:commentRss>
		<slash:comments>166</slash:comments>
		</item>
		<item>
		<title>POI向单元格写入中文</title>
		<link>http://justdoblogger.com/blog/200911/setcellvalue-chinese.html</link>
		<comments>http://justdoblogger.com/blog/200911/setcellvalue-chinese.html#comments</comments>
		<pubDate>Tue, 03 Nov 2009 13:28:08 +0000</pubDate>
		<dc:creator>braveheart_txl</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Excel操作]]></category>
		<category><![CDATA[Excel文件]]></category>
		<category><![CDATA[HSSF]]></category>
		<category><![CDATA[POI]]></category>
		<category><![CDATA[POI向单元格写入中文]]></category>
		<category><![CDATA[setcellvalue]]></category>
		<category><![CDATA[setEncoding]]></category>
		<category><![CDATA[Sheet]]></category>

		<guid isPermaLink="false">http://justdoblogger.com/blog/200911/poi%e5%90%91%e5%8d%95%e5%85%83%e6%a0%bc%e5%86%99%e5%85%a5%e4%b8%ad%e6%96%87.html</guid>
		<description><![CDATA[如果你现在下载最新版的POI开发包，你会发现，用POI向单元格里写入字符串时，如果是中文文字或者日文文字的话，已经不需要指定Unicode了，直接就可以显示汉字。之前版本存在的「HSSFCell」类的「setEncoding」方法已经被删除了。下面是被删除的方法说明。
]]></description>
			<content:encoded><![CDATA[<p>如果你现在下载最新版的POI开发包，你会发现，用POI向单元格里写入字符串时，如果是中文文字或者日文文字的话，已经不需要指定Unicode了，直接就可以显示汉字。之前版本存在的「HSSFCell」类的「setEncoding」方法已经被删除了。下面是被删除的方法说明。
			</p>
<div class="separator" style="clear: both; text-align: center;">
</div>
<pre class="methodt">
setEncoding
public void setEncoding(short encoding)
</pre>
<pre class="methodc">
set the encoding to either 8 or 16 bit. (US/UK use 8-bit,
rest of the western world use 16bit) 

Parameters:
  encoding - either ENCODING_COMPRESSED_UNICODE (0)
    or ENCODING_UTF_16 (1)
</pre>
<h2>示例程序</h2>
<p>
			用下面程序来做做看。
			</p>
<pre class="fixsmallcode">
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

public class POISample{
  public static void main(String[] args){
    HSSFWorkbook workbook = new HSSFWorkbook();

    HSSFSheet sheet = workbook.createSheet();

    HSSFRow row1 = sheet.createRow(1);

    HSSFCell cell1 = row1.createCell((short)0);
    //cell1.setEncoding(HSSFCell.ENCODING_UTF_16);
    cell1.setCellValue("使用中文");

    HSSFCell cell2 = row1.createCell((short)1);
    //cell2.setEncoding(HSSFCell.ENCODING_COMPRESSED_UNICODE);
    cell2.setCellValue("日本語を使う");

    FileOutputStream out = null;
    try{
      out = new FileOutputStream("sample.xls");
      workbook.write(out);
    }catch(IOException e){
      System.out.println(e.toString());
    }finally{
      try {
        out.close();
      }catch(IOException e){
        System.out.println(e.toString());
      }
    }
  }
}
</pre>
<p>
			运行结果如下：
			</p>
<p>
			<img src="./WS000001.JPG" alt="POI写入中文" width="399" height="356">
			</p>
]]></content:encoded>
			<wfw:commentRss>http://justdoblogger.com/blog/200911/setcellvalue-chinese.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

