﻿<?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>博客园-tonyqus.cn</title><link>http://www.cnblogs.com/tonyqus/</link><description>专心学习业务NPOI - 一个能帮助你直接读写office文件流的库</description><language>zh-cn</language><lastBuildDate>Mon, 06 Jul 2009 01:53:15 GMT</lastBuildDate><pubDate>Mon, 06 Jul 2009 01:53:15 GMT</pubDate><ttl>60</ttl><item><title>NPOI 1.2教程 - 2.5 打印相关设置</title><link>http://www.cnblogs.com/tonyqus/archive/2009/05/10/1453589.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Sun, 10 May 2009 04:06:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/05/10/1453589.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1453589.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/05/10/1453589.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1453589.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1453589.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>
<p>NPOI官方网站：<a href="http://npoi.codeplex.com/"><font color="#a91718">http://npoi.codeplex.com/</font></a></p>
<p>&nbsp;</p>
<p>打印设置主要包括方向设置、缩放、纸张设置、页边距等。NPOI 1.2支持大部分打印属性，能够让你轻松满足客户的打印需要。</p>
<p>&nbsp;</p>
<p>首先是方向设置，Excel支持两种页面方向，即纵向和横向。</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="132" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_thumb.png" width="445" border="0" /></a> </p>
<p>在NPOI中如何设置呢？你可以通过HSSFSheet.PrintSetup.Landscape来设置，Landscape是布尔类型的，在英语中是横向的意思。如果Landscape等于true，则表示页面方向为横向；否则为纵向。</p>
<p>&nbsp;</p>
<p>接着是缩放设置，</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_6.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="81" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_thumb_2.png" width="400" border="0" /></a> </p>
<p>&nbsp;</p>
<p>这里的缩放比例对应于HSSFSheet.PrintSetup.Scale，而页宽和页高分别对应于HSSFSheet.PrintSetup.FitWidth和HSSFSheet.PrintSetup.FitHeight。要注意的是，这里的PrintSetup.Scale应该被设置为0-100之间的值，而不是小数。</p>
<p>&nbsp;</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="35" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_thumb_3.png" width="404" border="0" /></a> </p>
<p>接下来就是纸张设置了，对应于HSSFSheet.PrintSetup.PaperSize，但这里的PaperSize并不是随便设置的，而是由一些固定的值决定的，具体的值与对应的纸张如下表所示：</p>
<table cellspacing="0" cellpadding="0" border="0">
    <tr>
            <td width="84">值</td>
            <td width="262">纸张</td>
        </tr>
        <tr>
            <td>1</td>
            <td>US Letter 8 1/2 x 11 in</td>
        </tr>
        <tr>
            <td>2</td>
            <td>US Letter Small 8 1/2 x 11 in</td>
        </tr>
        <tr>
            <td>3</td>
            <td>US Tabloid 11 x 17 in</td>
        </tr>
        <tr>
            <td>4</td>
            <td>US Ledger 17 x 11 in</td>
        </tr>
        <tr>
            <td>5</td>
            <td>US Legal 8 1/2 x 14 in</td>
        </tr>
        <tr>
            <td>6</td>
            <td>US Statement 5 1/2 x 8 1/2 in</td>
        </tr>
        <tr>
            <td>7</td>
            <td>US Executive 7 1/4 x 10 1/2 in</td>
        </tr>
        <tr>
            <td>8</td>
            <td>A3 297 x 420 mm</td>
        </tr>
        <tr>
            <td>9</td>
            <td>A4 210 x 297 mm</td>
        </tr>
        <tr>
            <td>10</td>
            <td>A4 Small 210 x 297 mm</td>
        </tr>
        <tr>
            <td>11</td>
            <td>A5 148 x 210 mm</td>
        </tr>
        <tr>
            <td>12</td>
            <td>B4 (JIS) 250 x 354</td>
        </tr>
        <tr>
            <td>13</td>
            <td>B5 (JIS) 182 x 257 mm</td>
        </tr>
        <tr>
            <td>14</td>
            <td>Folio 8 1/2 x 13 in</td>
        </tr>
        <tr>
            <td>15</td>
            <td>Quarto 215 x 275 mm</td>
        </tr>
        <tr>
            <td>16</td>
            <td>10 x 14 in</td>
        </tr>
        <tr>
            <td>17</td>
            <td>11 x 17 in</td>
        </tr>
        <tr>
            <td>18</td>
            <td>US Note 8 1/2 x 11 in</td>
        </tr>
        <tr>
            <td>19</td>
            <td>US Envelope #9 3 7/8 x 8 7/8</td>
        </tr>
        <tr>
            <td>20</td>
            <td>US Envelope #10 4 1/8 x 9 1/2</td>
        </tr>
        <tr>
            <td>21</td>
            <td>US Envelope #11 4 1/2 x 10 3/8</td>
        </tr>
        <tr>
            <td>22</td>
            <td>US Envelope #12 4 \276 x 11</td>
        </tr>
        <tr>
            <td>23</td>
            <td>US Envelope #14 5 x 11 1/2</td>
        </tr>
        <tr>
            <td>24</td>
            <td>C size sheet</td>
        </tr>
        <tr>
            <td>25</td>
            <td>D size sheet</td>
        </tr>
        <tr>
            <td>26</td>
            <td>E size sheet</td>
        </tr>
        <tr>
            <td>27</td>
            <td>Envelope DL 110 x 220mm</td>
        </tr>
        <tr>
            <td>28</td>
            <td>Envelope C5 162 x 229 mm</td>
        </tr>
        <tr>
            <td>29</td>
            <td>Envelope C3 324 x 458 mm</td>
        </tr>
        <tr>
            <td>30</td>
            <td>Envelope C4 229 x 324 mm</td>
        </tr>
        <tr>
            <td>31</td>
            <td>Envelope C6 114 x 162 mm</td>
        </tr>
        <tr>
            <td>32</td>
            <td>Envelope C65 114 x 229 mm</td>
        </tr>
        <tr>
            <td>33</td>
            <td>Envelope B4 250 x 353 mm</td>
        </tr>
        <tr>
            <td>34</td>
            <td>Envelope B5 176 x 250 mm</td>
        </tr>
        <tr>
            <td>35</td>
            <td>Envelope B6 176 x 125 mm</td>
        </tr>
        <tr>
            <td>36</td>
            <td>Envelope 110 x 230 mm</td>
        </tr>
        <tr>
            <td>37</td>
            <td>US Envelope Monarch 3.875 x 7.5 in</td>
        </tr>
        <tr>
            <td>38</td>
            <td>6 3/4 US Envelope 3 5/8 x 6 1/2 in</td>
        </tr>
        <tr>
            <td>39</td>
            <td>US Std Fanfold 14 7/8 x 11 in</td>
        </tr>
        <tr>
            <td>40</td>
            <td>German Std Fanfold 8 1/2 x 12 in</td>
        </tr>
        <tr>
            <td>41</td>
            <td>German Legal Fanfold 8 1/2 x 13 in</td>
        </tr>
        <tr>
            <td>42</td>
            <td>B4 (ISO) 250 x 353 mm</td>
        </tr>
        <tr>
            <td>43</td>
            <td>Japanese Postcard 100 x 148 mm</td>
        </tr>
        <tr>
            <td>44</td>
            <td>9 x 11 in</td>
        </tr>
        <tr>
            <td>45</td>
            <td>10 x 11 in</td>
        </tr>
        <tr>
            <td>46</td>
            <td>15 x 11 in</td>
        </tr>
        <tr>
            <td>47</td>
            <td>Envelope Invite 220 x 220 mm</td>
        </tr>
        <tr>
            <td>48</td>
            <td>RESERVED--DO NOT USE</td>
        </tr>
        <tr>
            <td>49</td>
            <td>RESERVED--DO NOT USE</td>
        </tr>
        <tr>
            <td>50</td>
            <td>US Letter Extra 9 \275 x 12 in</td>
        </tr>
        <tr>
            <td>51</td>
            <td>US Legal Extra 9 \275 x 15 in</td>
        </tr>
        <tr>
            <td>52</td>
            <td>US Tabloid Extra 11.69 x 18 in</td>
        </tr>
        <tr>
            <td>53</td>
            <td>A4 Extra 9.27 x 12.69 in</td>
        </tr>
        <tr>
            <td>54</td>
            <td>Letter Transverse 8 \275 x 11 in</td>
        </tr>
        <tr>
            <td>55</td>
            <td>A4 Transverse 210 x 297 mm</td>
        </tr>
        <tr>
            <td>56</td>
            <td>Letter Extra Transverse 9\275 x 12 in</td>
        </tr>
        <tr>
            <td>57</td>
            <td>SuperA/SuperA/A4 227 x 356 mm</td>
        </tr>
        <tr>
            <td>58</td>
            <td>SuperB/SuperB/A3 305 x 487 mm</td>
        </tr>
        <tr>
            <td>59</td>
            <td>US Letter Plus 8.5 x 12.69 in</td>
        </tr>
        <tr>
            <td>60</td>
            <td>A4 Plus 210 x 330 mm</td>
        </tr>
        <tr>
            <td>61</td>
            <td>A5 Transverse 148 x 210 mm</td>
        </tr>
        <tr>
            <td>62</td>
            <td>B5 (JIS) Transverse 182 x 257 mm</td>
        </tr>
        <tr>
            <td>63</td>
            <td>A3 Extra 322 x 445 mm</td>
        </tr>
        <tr>
            <td>64</td>
            <td>A5 Extra 174 x 235 mm</td>
        </tr>
        <tr>
            <td>65</td>
            <td>B5 (ISO) Extra 201 x 276 mm</td>
        </tr>
        <tr>
            <td>66</td>
            <td>A2 420 x 594 mm</td>
        </tr>
        <tr>
            <td>67</td>
            <td>A3 Transverse 297 x 420 mm</td>
        </tr>
        <tr>
            <td>68</td>
            <td>A3 Extra Transverse 322 x 445 mm</td>
        </tr>
        <tr>
            <td>69</td>
            <td>Japanese Double Postcard 200 x 148 mm</td>
        </tr>
        <tr>
            <td>70</td>
            <td>A6 105 x 148 mm</td>
        </tr>
        <tr>
            <td>71</td>
            <td>Japanese Envelope Kaku #2</td>
        </tr>
        <tr>
            <td>72</td>
            <td>Japanese Envelope Kaku #3</td>
        </tr>
        <tr>
            <td>73</td>
            <td>Japanese Envelope Chou #3</td>
        </tr>
        <tr>
            <td>74</td>
            <td>Japanese Envelope Chou #4</td>
        </tr>
        <tr>
            <td>75</td>
            <td>Letter Rotated 11 x 8 1/2 11 in</td>
        </tr>
        <tr>
            <td>76</td>
            <td>A3 Rotated 420 x 297 mm</td>
        </tr>
        <tr>
            <td>77</td>
            <td>A4 Rotated 297 x 210 mm</td>
        </tr>
        <tr>
            <td>78</td>
            <td>A5 Rotated 210 x 148 mm</td>
        </tr>
        <tr>
            <td>79</td>
            <td>B4 (JIS) Rotated 364 x 257 mm</td>
        </tr>
        <tr>
            <td>80</td>
            <td>B5 (JIS) Rotated 257 x 182 mm</td>
        </tr>
        <tr>
            <td>81</td>
            <td>Japanese Postcard Rotated 148 x 100 mm</td>
        </tr>
        <tr>
            <td>82</td>
            <td>Double Japanese Postcard Rotated 148 x 200 mm</td>
        </tr>
        <tr>
            <td>83</td>
            <td>A6 Rotated 148 x 105 mm</td>
        </tr>
        <tr>
            <td>84</td>
            <td>Japanese Envelope Kaku #2 Rotated</td>
        </tr>
        <tr>
            <td>85</td>
            <td>Japanese Envelope Kaku #3 Rotated</td>
        </tr>
        <tr>
            <td>86</td>
            <td>Japanese Envelope Chou #3 Rotated</td>
        </tr>
        <tr>
            <td>87</td>
            <td>Japanese Envelope Chou #4 Rotated</td>
        </tr>
        <tr>
            <td>88</td>
            <td>B6 (JIS) 128 x 182 mm</td>
        </tr>
        <tr>
            <td>89</td>
            <td>B6 (JIS) Rotated 182 x 128 mm</td>
        </tr>
        <tr>
            <td>90</td>
            <td>12 x 11 in</td>
        </tr>
        <tr>
            <td>91</td>
            <td>Japanese Envelope You #4</td>
        </tr>
        <tr>
            <td>92</td>
            <td>Japanese Envelope You #4 Rotated</td>
        </tr>
        <tr>
            <td>93</td>
            <td>PRC 16K 146 x 215 mm</td>
        </tr>
        <tr>
            <td>94</td>
            <td>PRC 32K 97 x 151 mm</td>
        </tr>
        <tr>
            <td>95</td>
            <td>PRC 32K(Big) 97 x 151 mm</td>
        </tr>
        <tr>
            <td>96</td>
            <td>PRC Envelope #1 102 x 165 mm</td>
        </tr>
        <tr>
            <td>97</td>
            <td>PRC Envelope #2 102 x 176 mm</td>
        </tr>
        <tr>
            <td>98</td>
            <td>PRC Envelope #3 125 x 176 mm</td>
        </tr>
        <tr>
            <td>99</td>
            <td>PRC Envelope #4 110 x 208 mm</td>
        </tr>
        <tr>
            <td>100</td>
            <td>PRC Envelope #5 110 x 220 mm</td>
        </tr>
        <tr>
            <td>101</td>
            <td>PRC Envelope #6 120 x 230 mm</td>
        </tr>
        <tr>
            <td>102</td>
            <td>PRC Envelope #7 160 x 230 mm</td>
        </tr>
        <tr>
            <td>103</td>
            <td>PRC Envelope #8 120 x 309 mm</td>
        </tr>
        <tr>
            <td>104</td>
            <td>PRC Envelope #9 229 x 324 mm</td>
        </tr>
        <tr>
            <td>105</td>
            <td>PRC Envelope #10 324 x 458 mm</td>
        </tr>
        <tr>
            <td>106</td>
            <td>PRC 16K Rotated</td>
        </tr>
        <tr>
            <td>107</td>
            <td>PRC 32K Rotated</td>
        </tr>
        <tr>
            <td>108</td>
            <td>PRC 32K(Big) Rotated</td>
        </tr>
        <tr>
            <td>109</td>
            <td>PRC Envelope #1 Rotated 165 x 102 mm</td>
        </tr>
        <tr>
            <td>110</td>
            <td>PRC Envelope #2 Rotated 176 x 102 mm</td>
        </tr>
        <tr>
            <td>111</td>
            <td>PRC Envelope #3 Rotated 176 x 125 mm</td>
        </tr>
        <tr>
            <td>112</td>
            <td>PRC Envelope #4 Rotated 208 x 110 mm</td>
        </tr>
        <tr>
            <td>113</td>
            <td>PRC Envelope #5 Rotated 220 x 110 mm</td>
        </tr>
        <tr>
            <td>114</td>
            <td>PRC Envelope #6 Rotated 230 x 120 mm</td>
        </tr>
        <tr>
            <td>115</td>
            <td>PRC Envelope #7 Rotated 230 x 160 mm</td>
        </tr>
        <tr>
            <td>116</td>
            <td>PRC Envelope #8 Rotated 309 x 120 mm</td>
        </tr>
        <tr>
            <td>117</td>
            <td>PRC Envelope #9 Rotated 324 x 229 mm</td>
        </tr>
        <tr>
            <td>118</td>
            <td>PRC Envelope #10 Rotated 458 x 324 mm</td>
        </tr>
    </table>
<p>（此表摘自《Excel Binary File Format (.xls) Structure Specification.pdf》）</p>
<p>HSSFSheet下面定义了一些xxxx_PAPERSIZE的常量，但都是非常常用的纸张大小，如果满足不了你的需要，可以根据上表自己给PaperSize属性赋值。所以，如果你要设置纸张大小可以用这样的代码：</p>
<p>HSSFSheet.PrintSetup.PaperSize=HSSFSheet.A4_PAPERSIZE;</p>
<p>或</p>
<p>HSSFSheet.PrintSetup.PaperSize=9; (A4 210*297mm)</p>
<p>&nbsp;</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_10.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="30" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_thumb_4.png" width="146" border="0" /></a> </p>
<p>再下来就是打印的起始页码，它对应于HSSFSheet.PrintSetup.PageStart和HSSFSheet.PrintSetup.UsePage，如果UsePage=false，那么就相当于&#8220;自动&#8221;，这时PageStart不起作用；如果UsePage=true，PageStart才会起作用。所以在设置PageStart之前，必须先把UsePage设置为true。</p>
<p>&nbsp;</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_14.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="403" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.5.1_D5BE/image_thumb_5.png" width="562" border="0" /></a> </p>
<p>&#8220;打印&#8221;栏中的&#8220;网格线&#8221;设置对应于HSSFSheet.IsPrintGridlines，请注意，这里不是HSSFSheet.PrintSetup下面，所以别搞混了。这里之所以不隶属于PrintSetup是由底层存储该信息的record决定的，底层是把IsGridsPrinted放在GridsetRecord里面的，而不是PrintSetupRecord里面的，尽管界面上是放在一起的。另外还有一个HSSFSheet.IsGridsPrinted属性，这个属性对应于底层的gridset Record，但这个record是保留的，从微软的文档显示没有任何意义，所以这个属性请不要去设置。</p>
<p>&#8220;单色打印&#8221;则对应于HSSFSheet.PrintSetup.NoColors，这是布尔类型的，值为true时，表示单色打印。</p>
<p>&#8220;草稿品质&#8221;对应于HSSFSheet.PrintSetup.IsDraft，也是布尔类型的，值为true时，表示用草稿品质打印。</p>
<p>这里的打印顺序是由HSSFSheet.PrintSetup.LeftToRight决定的，它是布尔类型的，当为true时，则表示&#8220;先行后列&#8221;；如果是false，则表示&#8220;先列后行&#8221;。</p>
<p>&nbsp;</p>
<p>在NPOI 1.2中，&#8220;行号列标&#8221;、&#8220;批注&#8221;和&#8220;错误单元格打印为&#8221;、&#8220;页边距&#8221;暂不支持，将在以后的版本中支持。</p>
<p>&nbsp;</p>
<p>有关打印的范例可以参考 <a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank"><font color="#a91718">NPOI 1.2正式版</font></a> 中的 SetPrintSettingsInXls 项目。</p>
 <img src ="http://www.cnblogs.com/tonyqus/aggbug/1453589.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47995/" target="_blank">Google Voice 上手</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>博客园上海俱乐部活动通知（2009-4-25） </title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/15/1436144.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Wed, 15 Apr 2009 00:10:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/15/1436144.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1436144.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/15/1436144.html#Feedback</comments><slash:comments>26</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1436144.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1436144.html</trackback:ping><description><![CDATA[<p><strong>活动介绍</strong> <br />活动时间：2009年4月25日13:30-17:30 </p>
<p>活动地点：浦东南路3500号（近华丰路）<a href="http://www.ddmap.com/map/21/point-298117-%BA%BA%CD%A5-.htm" target="_blank">汉庭快捷酒店世博村店</a>一楼会议室 </p>
<p>提供的服务：茶水、无线上网（免费）</p>
<p>费用：35元/人（到场签到时付费） </p>
<p>人数：50人</p>
<p>&nbsp;</p>
<p><strong>活动日程安排</strong> <br />13:30-14:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 签到，领取小礼品和意见反馈表 <br />14:00-15:15&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 集中化WCF服务管理和部署（<a href="http://teddyma.cnblogs.com/" target="_blank">Teddy Ma</a>） <br />15:15-15:45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Q&amp;A <br />15:45-16:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 茶歇 <br />16:00-17:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 博客园近期话题线下互动 <br />17:00-17:30&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 抽奖、自由交流、合影 <br /></p>
<p><strong></strong></p>
<p><strong></strong>&nbsp;</p>
<p><strong>报名方法：</strong></p>
<p>请<strong>发邮件</strong>到<a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_gmailicon_2.jpg"><img title="r_gmailicon" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="21" alt="r_gmailicon" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_gmailicon_thumb.jpg" width="161" border="0" /></a> ，写上你的真实姓名和网名，方便到场时签到。由于场地方面的限制，人数将控制在50人左右，前50封报名邮件我们将发邀请邮件予以确认，望那些没有报名成功的兄弟能够谅解，也希望在以后的活动中能够看到您的身影。 </p>
<p>注：回复不作为报名凭证</p>
<p><strong></strong></p>
<p><strong></strong>&nbsp;</p>
<p><strong>联系方式：</strong></p>
<p>联系人：瞿杰（Tony Qu）</p>
<p>Email：<a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_gmailicon_2.jpg"><img title="r_gmailicon" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="21" alt="r_gmailicon" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_gmailicon_thumb.jpg" width="161" border="0" /></a></p>
<p>MSN: <a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_msnicon_2.jpg"><img title="r_msnicon" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="21" alt="r_msnicon" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/r_msnicon_thumb.jpg" width="156" border="0" /></a> </p>
<p>&nbsp;</p>
<p><strong>交通指南：</strong></p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/image_4.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="363" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/2009425_8935/image_thumb_1.png" width="312" border="0" /></a> </p>
<p>直达公交: <a href="http://www.ddmap.com/map/21/bus-key-576%C7%F8%BC%E4.htm" target="_blank">576区间路</a> <a href="http://www.ddmap.com/map/21/bus-key-955.htm" target="_blank">955路</a> <a href="http://www.ddmap.com/map/21/bus-key-%D6%DC%B3%C2%CF%DF.htm" target="_blank">周陈线</a> <a href="http://www.ddmap.com/map/21/bus-key-86.htm" target="_blank">86路</a> <a href="http://www.ddmap.com/map/21/bus-key-785.htm" target="_blank">785路</a> <a href="http://www.ddmap.com/map/21/bus-key-%B4%F3%C7%C5%D2%BB%CF%DF.htm" target="_blank">大桥一线</a> <a href="http://www.ddmap.com/mstmap50007/g_sch_bus.jsp?buskeyname=978&amp;mapno=21&amp;schtype=1">978</a>&nbsp;<a href="http://www.ddmap.com/mstmap50007/g_sch_bus.jsp?buskeyname=610&amp;mapno=21&amp;schtype=1">610</a></p>
<p>路线一（2, 4, 6号线沿线）：坐地铁2号线、4号线或6号线到世纪大道站，从1号口出来在东方路张杨路站台坐978或610至华丰路站下，车站旁就是汉庭酒店</p>
<p>路线二（8号线沿线）：坐地铁8号线到耀华路站下车，到浦东南路上的车站换乘978或82，到华丰路站下车，马路对面就是汉庭世博店</p>
<p>路线三（曲阳、外滩）：乘坐576，到华丰路站下来就是</p>
<p>&nbsp;</p>
<p><strong>赞助：</strong></p>
<p>本次活动由<a href="http://www.hjenglish.com/" target="_blank">沪江网</a>和<a href="http://www.turingbook.com/" target="_blank">图灵教育</a>共同赞助（排名不分先后）</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1436144.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47994/" target="_blank">Google号召社区力量为互联网加速</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 显示/隐藏Excel网格线</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/14/1434100.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Mon, 13 Apr 2009 23:54:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/14/1434100.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1434100.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/14/1434100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1434100.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1434100.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>
<p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>
<p>&nbsp;</p>
<p>有些时候，我们需要网格线，而有些时候我们不需要，这取决于实际的业务需求。前两天inmegin兄就问我，怎么把网格给去掉，因为他们要把Excel文档当Word使，也许是因为Excel排版方便吧。</p>
<p>Excel中的网格线设置是以表（Sheet）为单位进行管理的，这也就意味着你可以让一个表显示网格线，而另一个表不显示，这是不冲突的。</p>
<p>&nbsp;</p>
<p>在Excel 2007中，我们通常用&#8220;工作表选项&#8221;面板来设置这个属性:</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2Excel_11FA6/image_2.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="107" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2Excel_11FA6/image_thumb.png" width="122" border="0" /></a> </p>
<p>&nbsp;</p>
<p>在面板中，你会发现有2个多选框，一个是查看，一个是打印，也就是说Excel是把查看和打印网格线作为两个设置来处理的，存储的Record也是不同的。</p>
<p>在NPOI中，如果要让网格线在查看时显示/隐藏，你可以HSSFSheet.DisplayGridlines属性，默认值为true（这也是为什么默认情况下我们能够看到网格线）。下面的代码就是让网格线在查看时不可见的：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFWorkbook hssfworkbook = <span style="color: #0000ff">new</span> HSSFWorkbook();
HSSFSheet s1 = hssfworkbook.CreateSheet(<span style="color: #006080">"Sheet1"</span>);
s1.DisplayGridlines = <span style="color: #0000ff">false</span>;</pre></div>
<p>如果要在打印时显示/隐藏网格线，你可以用HSSFSheet.IsGridlinesPrinted属性，默认值为false（这就是默认情况下打印看不到网格线的原因）。代码和上面差不多：</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">s1.IsGridsPrinted = <span style="color: #0000ff">true</span>;</pre></div>
<p>上面的代码将在打印时显示网格线，打印的效果如下所示。</p>
<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2Excel_11FA6/image_4.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="115" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2Excel_11FA6/image_thumb_1.png" width="91" border="0" /></a> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>在此也提醒大家，如果这个Excel最终客户有打印意向，可别忘了把IsGridPrinted属性也设置上。</p>
<p>&nbsp;</p>
<p>相关范例可以参考NPOI 1.2正式版中的DisplayGridlinesInXls项目。</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1434100.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47989/" target="_blank">Twitter无处不在 魔兽世界Twitter发送器插件发布</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 组合行、列</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/13/1434453.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Mon, 13 Apr 2009 00:46:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/13/1434453.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1434453.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/13/1434453.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1434453.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1434453.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>Excel 2007中有一个面板是专门用于设置组合功能的，叫做&#8220;分级显示&#8221;面板，如下所示：</p>  <p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.8_7979/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="105" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.8_7979/image_thumb.png" width="244" border="0" /></a> </p>  <p>可能我们在过去生成Excel文件的时候根本不会用这个功能，也没办法用，因为cvs法和html法没办法控制这些东西。这里简单的介绍一下什么叫做组合：</p>  <p>组合分为行组合和列组合，所谓行组合，就是让n行组合成一个集合，能够进行展开和合拢操作，在Excel中显示如下：</p>  <p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.8_7979/image_8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="176" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.8_7979/image_thumb_3.png" width="376" border="0" /></a> </p>  <p>图中左侧就是用于控制行组合折叠的图标，图中上部就是用于控制列组合的，是不是有点像TreeView中的折叠节点？很多时候由于数据太多，为了让用户对于大量数据一目了然，我们可以使用行列组合来解决显示大纲，这和Visual Studio 里面的region的概念是类似的。</p>  <p>细心的朋友可能已经注意到了，我们其实可以对一行做多次组合操作，这就是分级显示的概念，图中就把行2-3分为2个组合，第2行到第4行为一个组合，第2行到第5行一个组合，所以是分两级。</p>  <p>在NPOI中，要实现分组其实并不难，你只需要调用HSSFSheet.GroupRow和HSSFSheet.GroupColumn这两个方法就可以了。</p>  <p>&#160;</p>  <p>首先我们来看HSSFSheet.GroupRow，GroupRow有2个参数，分别是fromRow和toRow，表示起始行号和结束行号，这些行号都是从0开始算起的。</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFWorkbook hssfworkbook = <span style="color: #0000ff">new</span> HSSFWorkbook();
HSSFSheet s = hssfworkbook.CreateSheet(<span style="color: #006080">&quot;Sheet1&quot;</span>);
s.GroupRow(1, 3);</pre>
</div>

<p>上面的代码把第2行到第4行做了组合。</p>

<p>要组合列，其实代码很相似，如下所示：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">s.GroupColumn(1,3)</pre>
</div>

<p></p>

<p>上面的代码把B至D列做了组合。</p>

<p>&#160;</p>

<p>正如上图中Excel的&#8220;分级显示&#8221;面板所示，有&#8220;组合&#8221;，也一定有&#8220;取消组合&#8221;，NPOI中你可以用HSSFSheet.UngroupRow和HSSFSheet.UngroupColumn，参数和GroupXXX是一样的，如果要取消第2到第4行的组合，就可以用下面的代码：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">s.UngroupColumn(1,3)</pre>
</div>

<p>&#160;</p>

<p>相关范例请见<a href="http://npoi.codeplex.com/" target="_blank">NPOI 1.2正式版</a>中的GroupRowAndColumnInXls项目。</p> <img src ="http://www.cnblogs.com/tonyqus/aggbug/1434453.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47988/" target="_blank">Firefox 3.5匆忙推出漏洞多 Mozilla本月将更新</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程（目录）</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434209.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Sun, 12 Apr 2009 09:19:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434209.html</guid><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com">http://npoi.codeplex.com</a></p>  <p>很多人可能对NPOI还很陌生，别担心，通过本教程你将对NPOI有进一步的认识和理解。</p>  <p>目录</p>  <p>1. 认识NPOI</p>  <p>1.1 什么是NPOI</p>  <p>1.2 版权说明</p>  <p>1.3 相关资源</p>  <p>1.4 团队介绍</p>  <p>1.5 未来展望</p>  <p>1.6 各Assembly的作用</p>  <p>&#160;</p>  <p>2. 使用NPOI生成xls文件 </p>  <p>2.1 创建基本内容</p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/22/1419293.html">2.1.1 创建Workbook和Sheet</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/23/1419364.html">2.1.2 创建DocumentSummaryInformation和SummaryInformation</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/23/1419988.html">2.1.3 创建单元格</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/25/1421287.html">2.1.5 创建批注</a></p>  <p>2.1.6 创建页眉和页脚</p>  <p>&#160;</p>  <p>2.2 单元格操作</p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/27/1422734.html">2.2.1 设置格式</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/30/1425376.html">2.2.2 合并单元格</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/03/31/1426732.html">2.2.3 对齐相关设置</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/04/1429376.html" target="_blank">2.2.4 使用边框</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/04/1429499.html" target="_blank">2.2.5 字体设置</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/08/1432096.html" target="_blank">2.2.6 背景和纹理</a></p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434106.html" target="_blank">2.2.7 设置宽度和高度</a></p>  <p>&#160;</p>  <p>2.3 使用Excel公式</p>  <p>2.3.1 基本计算</p>  <p>2.3.2 SUM函数</p>  <p>2.3.3 日期函数</p>  <p>2.3.4 字符串相关函数</p>  <p>2.3.5 IF函数</p>  <p>2.3.6 </p>  <p>2.3.7 CountIf函数</p>  <p>2.3.8 随机数函数</p>  <p>&#160;</p>  <p>2.4 创建图形</p>  <p>2.4.1 画线</p>  <p>2.4.2 画多边形</p>  <p>2.4.3 画圆形</p>  <p>2.4.4 画Grid</p>  <p>2.4.5 插入图片</p>  <p>&#160;</p>  <p>2.5 打印设置</p>  <p>2.5.1 设置打印方向</p>  <p>2.5.2 设置页数</p>  <p>2.5.3 设置纸张类型</p>  <p>2.5.4 设置缩放比例</p>  <p>2.5.5 设置Margin</p>  <p>2.5.6 </p>  <p>&#160;</p>  <p>2.6 高级功能</p>  <p>2.6.1 调整表单显示比例</p>  <p>2.6.2 设置密码</p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/13/1434453.html" target="_blank">2.6.3 组合行、列</a></p>  <p>2.6.4 锁定列</p>  <p><a href="http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434100.html" target="_blank">2.6.5 显示/隐藏网格线</a></p>  <p>2.6.6 设置初始视图的行、列</p>  <p>&#160;</p>  <p>3. 项目实践</p>  <p>3.1 使用模板</p>  <p>3.2 生成九九乘法表</p>  <p>3.3 生成一张工资单</p>  <p>3.4 从xls文件中抽取文本</p>  <p>3.5 批量生成xls文件</p> <img src ="http://www.cnblogs.com/tonyqus/aggbug/1434209.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47987/" target="_blank">预测：Twitter最可能收购的十家公司</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 2.2.7 设置单元格的宽度和高度</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434106.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Sun, 12 Apr 2009 09:11:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434106.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1434106.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/12/1434106.html#Feedback</comments><slash:comments>8</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1434106.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1434106.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>在Excel中，单元格的宽度其实就是列的宽度，因为Excel假设这一列的单元格的宽度肯定一致。所以要设置单元格的宽度，我们就得从列的宽度下手，HSSFSheet有个方法叫SetColumnWidth，共有两个参数：一个是列的索引（从0开始），一个是宽度。</p>  <p>现在假设你要设置B列的宽度，就可以用下面的代码：</p>  <p></p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFWorkbook hssfworkbook = <span style="color: #0000ff">new</span> HSSFWorkbook();
HSSFSheet sheet1 = hssfworkbook.CreateSheet(<span style="color: #006080">&quot;Sheet1&quot;</span>);
sheet1.SetColumnWidth(1, 100 * 256);</pre>
</div>

<p>这里你会发现一个有趣的现象，SetColumnWidth的第二个参数要乘以256，这是怎么回事呢？其实，这个参数的单位是1/256个字符宽度，也就是说，这里是把B列的宽度设置为了100个字符。</p>

<p>刚才说的是如何设置，那如何去读取一个列的宽度呢？直接用GetColumnWidth方法，这个方法只有一个参数，那就是列的索引号。如下所示：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">int</span> col1width = sheet1.GetColumnWidth(1);</pre>
</div>

<p>&#160;</p>

<p>说完宽度，我们来说高度，在Excel中，每一行的高度也是要求一致的，所以设置单元格的高度，其实就是设置行的高度，所以相关的属性也应该在HSSFRow上，它就是HSSFRow.Height和HeightInPoints，这两个属性的区别在于HeightInPoints的单位是点，而Height的单位是1/20个点，所以Height的值永远是HeightInPoints的20倍。</p>

<p>要设置第一行的高度，可以用如下代码：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">sheet1.CreateRow(0).Height = 200*20;</pre>
</div>

<p></p>

<p>或者</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">sheet1.CreateRow(0).HeightInPoints = 200;</pre>
</div>

<p>如果要获得某一行的行高，可以直接拿HSSFRow.Height属性的返回值。</p>

<p>&#160;</p>

<p>你可能觉得一行一行设置行高或者一列一列设置列宽很麻烦，那你可以考虑使用HSSFSheet.DefaultColumnWidth、HSSFSheet.DefaultRowHeight和HSSFSheet.DefaultRowHeightInPoints属性。</p>

<p>一旦设置了这些属性，如果某一行或者某一列没有设置宽度，就会使用默认宽度或高度。代码如下：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">sheet1.DefaultColumnWidth=100*256;
sheet1.DefaultRowHeight=30*20;</pre>
</div>

<p>&#160;</p>

<p>相关范例请见<a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank">NPOI 1.2正式版</a>中的SetWidthAndHeightInXls项目</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1434106.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47987/" target="_blank">预测：Twitter最可能收购的十家公司</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 2.2.6设置单元格的背景和图案</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/09/1432096.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Thu, 09 Apr 2009 08:28:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/09/1432096.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1432096.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/09/1432096.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1432096.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1432096.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>本节我们将用NPOI来为单元格添加背景和图案。</p>  <p>&#160;</p>  <p>在之前的教程中，我们已经提到HSSFCellStyle有两个背景颜色属性，一个叫FillBackgroundColor，另一个叫FillForegroundColor，但其实这指的都是背景颜色，那为什么还有ForegroundColor呢？为了能够帮助大家理解，我们举一个实际的例子，下面这个图案是Excel的一个单元格：</p>  <p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="20" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb.png" width="66" border="0" /></a> </p>  <p>线是白色的，背景是红色的。这里的线其实就是下面的Excel界面中的图案：</p>  <p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="217" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_1.png" width="289" border="0" /></a> </p>  <p>&#160;</p>  <p>至于线的颜色则是图案颜色，即白色。</p>  <p>所以以上单元格如果要用NPOI来设置就可以用以下代码完成：</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #008000">//fill background</span>
HSSFCellStyle style8 = hssfworkbook.CreateCellStyle();
style8.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.WHITE.index;
style8.FillPattern = HSSFCellStyle.SQUARES;
style8.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.RED.index;
sheet1.CreateRow(7).CreateCell(0).CellStyle = style8;</pre>
</div>

<p>现在是不是清楚一些了，这里的FillPattern就图案样式，所有的枚举值都是HSSFCellStyle的常量；FillForegroundColor就是图案的颜色，而FillBackgroundColor则是背景的颜色，即红色。</p>

<p>下面罗列一下图案样式及其对应的值：</p>

<table cellspacing="0" cellpadding="2" width="600" border="1"><tbody>
    <tr>
      <td valign="top" width="116">图案样式</td>

      <td valign="top" width="484">常量</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_46.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="28" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_22.png" width="29" border="0" /></a> </td>

      <td valign="top" width="484">HSSFCellStyle.NO_FILL</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_6.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_2.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.ALT_BARS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_3.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.FINE_DOTS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_10.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_4.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.SPARSE_DOTS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_12.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_5.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.LESS_DOTS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_14.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_6.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.LEAST_DOTS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_18.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_8.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.BRICKS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_20.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_9.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.BIG_SPOTS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_22.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_10.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THICK_FORWARD_DIAG</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_24.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_11.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THICK_BACKWARD_DIAG</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_26.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_12.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THICK_VERT_BANDS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_28.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_13.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THICK_HORZ_BANDS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_30.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_14.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THIN_HORZ_BANDS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_32.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_15.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THIN_VERT_BANDS</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_34.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_16.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THIN_BACKWARD_DIAG</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_36.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_17.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.THIN_FORWARD_DIAG</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_44.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="28" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_21.png" width="29" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.SQUARES</td>
    </tr>

    <tr>
      <td valign="top" width="116"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_42.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="27" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.2_1120F/image_thumb_20.png" width="28" border="0" /></a></td>

      <td valign="top" width="484">HSSFCellStyle.DIAMONDS</td>
    </tr>
  </tbody></table>

<p>通过这张表，你将很容易找到自己需要的样式，不用再去一个一个猜测了。</p>

<p>&#160;</p>

<p>相关范例请参考<a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank">NPOI 1.2正式版</a>中的ColorfullMatrixTable和FillBackgroundInXls。</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1432096.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47986/" target="_blank">网易澄清:与暴雪合资公司仅提供技术支持</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 2.2.5 设置单元格字体</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/08/1429499.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Wed, 08 Apr 2009 00:11:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/08/1429499.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1429499.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/08/1429499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1429499.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1429499.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>本节我们将继续使用NPOI来设置单元格格式，这一节我们主要讲如何设置“字体”。</p>  <p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.5_B3BF/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="441" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.5_B3BF/image_thumb.png" width="640" border="0" /></a> </p>  <p>&#160;</p>  <p>在设置字体之前，我们首先要做的就是创建字体对象，这和创建数字格式很相似。</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFFont font = hssfworkbook.CreateFont();</pre>
</div>

<p>这句话会在Excel文件内部创建相应的FontRecord，所以你不用客户因为自己机器上的Excel没有相应的字体设置而导致设置丢失。</p>

<p>字体在设置完成后，我们就可以把它赋给单元格样式，代码如下：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFCellStyle style1 = hssfworkbook.CreateCellStyle();
style1.SetFont(font);
cell1.CellStyle=style1;</pre>
</div>

<p>这里的cell1是HSSFCell的一个实例。</p>

<p>&#160;</p>

<p>好了，下面我们就开始对字体进行设置。</p>

<p><u></u></p>

<p><u>字体名称</u></p>

<p>这里的字体名称是通过HSSFFont.FontName进行设置的，至于具体的名称，只要是常用字体都可以，比如说Arial, Verdana等，当然也可以是中文字体名，如宋体、黑体等。不过设置字体名称有个前提，那就是假设打开这个xls文件的客户机上有这种字体，如果没有，Excel将使用默认字体。</p>

<p>下面就是设置字体名称为“宋体”的代码：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">font.FontName = <span style="color: #006080">&quot;宋体&quot;</span>;</pre>
</div>

<p><u></u></p>

<p><u>字号</u></p>

<p>与字号有关的属性有两个，一个是FontHeight，一个是FontHeightInPoints。区别在于，FontHeight的值是FontHeightInPoints的20倍，通常我们在Excel界面中看到的字号，比如说12，对应的是FontHeightInPoints的值，而FontHeight要产生12号字体的大小，值应该是240。所以通常建议你用FontHeightInPoint属性。</p>

<p>如果要设置字号为12，代码就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">font.FontHeightInPoints = 12;</pre>
</div>

<p>&#160;</p>

<p><u>字体颜色</u></p>

<p>这里可能会与CellStyle上的ForegroundColor和BackgroundColor产生混淆，其实所有的字体颜色都是在HSSFFont的实例上设置的，CellStyle的ForegroundColor和BackgroundColor分别指背景填充色和填充图案的颜色，和文本颜色无关。</p>

<p>要设置字体颜色，我们可以用HSSFFont.Color属性，颜色可以通过HSSFColor获得，代码如下所示：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">font.Color = HSSFColor.RED.index;</pre>
</div>

<p>这行代码把文本设置为红色。</p>

<p>&#160;</p>

<p><u>下划线</u></p>

<p>通常我们所说的下划线都是单线条的，其实Excel支持好几种下划线，如下所示：</p>

<table cellspacing="0" cellpadding="2" width="600" border="1"><tbody>
    <tr>
      <td valign="top" width="300">类型</td>

      <td valign="top" width="300">对应的值</td>
    </tr>

    <tr>
      <td valign="top" width="300">单下划线</td>

      <td valign="top" width="300">HSSFFont.U_SINGLE</td>
    </tr>

    <tr>
      <td valign="top" width="300">双下划线</td>

      <td valign="top" width="300">HSSFFont.U_DOUBLE</td>
    </tr>

    <tr>
      <td valign="top" width="300">会计用单下划线</td>

      <td valign="top" width="300">HSSFFont.U_SINGLE_ACCOUNTING</td>
    </tr>

    <tr>
      <td valign="top" width="300">会计用双下划线</td>

      <td valign="top" width="300">HSSFFont.U_DOUBLE_ACCOUNTING</td>
    </tr>

    <tr>
      <td valign="top" width="300">无下划线</td>

      <td valign="top" width="300">HSSFFont.U_NONE</td>
    </tr>
  </tbody></table>

<p>当你要设置下划线时，可以用HSSFFont.Underline属性，这是一个byte类型的值，例如</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">font.Underline=HSSFFont.U_SINGLE</pre>
</div>

<p>这行代码就是设置单下划线的代码。</p>

<p><u></u></p>

<p><u>上标下标</u></p>

<p>设置这东西可以用HSSFFont.TypeOffset属性，值有以下几种：</p>

<table cellspacing="0" cellpadding="2" width="600" border="1"><tbody>
    <tr>
      <td valign="top" width="300">TypeOffset的值</td>

      <td valign="top" width="300">说明</td>
    </tr>

    <tr>
      <td valign="top" width="300">HSSFFont.SS_SUPER</td>

      <td valign="top" width="300">上标</td>
    </tr>

    <tr>
      <td valign="top" width="300">HSSFFont.SS_SUB</td>

      <td valign="top" width="300">下标</td>
    </tr>

    <tr>
      <td valign="top" width="300">HSSFFont.SS_NONE</td>

      <td valign="top" width="300">普通，默认值</td>
    </tr>
  </tbody></table>

<p>所以如果你要上标的话，可以用下面的代码：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">font.TypeOffset=HSSFFont.SS_SUPER;</pre>
</div>

<p><u></u></p>

<p><u>删除线</u></p>

<p>设置这东西可以用HSSFFont.IsStrikeout属性，当为true时，表示有删除线；为false则表示没有删除线。</p>

<p>&#160;</p>

<p>相关范例请参考<a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank">NPOI 1.2正式版</a>中的ApplyFontInXls的项目。</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1429499.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47985/" target="_blank">杰克逊悼念仪式或成史上最大规模Web活动</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 2.2.4 设置单元格边框</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/06/1429376.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Mon, 06 Apr 2009 03:38:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/06/1429376.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1429376.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/06/1429376.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1429376.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1429376.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>很多表格中都要使用边框，本节将为你重点讲解NPOI中边框的设置和使用。</p>  <p>边框和其他单元格设置一样也是在HSSFCellStyle上操作的，HSSFCellStyle有2种和边框相关的属性，分别是:</p>  <table cellspacing="0" cellpadding="2" width="855" border="1"><tbody>     <tr>       <td valign="top" width="190">边框相关属性</td>        <td valign="top" width="136">说明</td>        <td valign="top" width="527">范例</td>     </tr>      <tr>       <td valign="top" width="190">Border+方向</td>        <td valign="top" width="136">边框类型</td>        <td valign="top" width="527">BorderTop, BorderBottom,BorderLeft, BorderRight</td>     </tr>      <tr>       <td valign="top" width="190">方向+BorderColor</td>        <td valign="top" width="136">边框颜色</td>        <td valign="top" width="527">TopBorderColor,BottomBorderColor, LeftBorderColor, RightBorderColor</td>     </tr>   </tbody></table>  <p>&#160;</p>  <p>其中边框类型分为以下几种：</p>  <table cellspacing="0" cellpadding="2" width="598" border="1"><tbody>     <tr>       <td valign="top" width="116">边框范例图</td>        <td valign="top" width="480">对应的静态值</td>     </tr>      <tr>       <td valign="top" width="118"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_2.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb.png" width="49" border="0" /></a></td>        <td valign="top" width="479">HSSFCellStyle.BORDER_DOTTED</td>     </tr>      <tr>       <td valign="top" width="119"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_1.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_HAIR</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_28.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="15" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_13.png" width="47" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_DASH_DOT_DOT</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_6.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_2.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_DASH_DOT</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_3.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_DASHED</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_4.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_THIN</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_12.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_5.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_14.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_6.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_SLANTED_DASH_DOT</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_16.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_7.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_MEDIUM_DASH_DOT</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_18.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="14" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_8.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_MEDIUM_DASHED</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_22.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="13" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_10.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_MEDIUM</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_24.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="13" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_11.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_THICK</td>     </tr>      <tr>       <td valign="top" width="120"><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_26.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="13" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_12.png" width="49" border="0" /></a> </td>        <td valign="top" width="478">HSSFCellStyle.BORDER_DOUBLE</td>     </tr>   </tbody></table>  <p>至于颜色那就很多了，全部在HSSFColor下面，如HSSFColor.GREEN, HSSFColor.RED，都是静态实例，可以直接引用。</p>  <p>下面我们假设我们要把一个单元格的四周边框都设置上，可以用下面的代码：</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFSheet sheet = hssfworkbook.CreateSheet(<span style="color: #006080">&quot;new sheet&quot;</span>);

<span style="color: #008000">// Create a row and put some cells in it. Rows are 0 based.</span>
HSSFRow row = sheet.CreateRow(1);
<span style="color: #008000">// Create a cell and put a value in it.</span>
HSSFCell cell = row.CreateCell(1);
<span style="color: #008000">// Style the cell with borders all around.</span>
HSSFCellStyle style = hssfworkbook.CreateCellStyle();
style.BorderBottom= HSSFCellStyle.BORDER_THIN;
style.BorderLeft= HSSFCellStyle.BORDER_THIN;
style.BorderRight= HSSFCellStyle.BORDER_THIN;
style.BorderTop = HSSFCellStyle.BORDER_THIN ;
cell.CellStyle= style;</pre>
</div>

<p>这段代码使用了最普通的细边框，使得这个单元格看上去像块空心砖头。</p>

<p><a href="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_34.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="86" alt="image" src="http://images.cnblogs.com/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_52A9/image_thumb_16.png" width="182" border="0" /></a> </p>

<p>注意：这里我们没有设置边框的颜色，但这不会影响最终的效果，因为Excel会用默认的黑色给边框上色。</p>

<p>&#160;</p>

<p>如果要设置颜色的话，也很简单，如下：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.BottomBorderColor= HSSFColor.GREEN.index;</pre>
</div>

<p>以上代码将底部边框设置为绿色，要注意，不是直接把HSSFColor.GREEN赋给XXXXBorderColor属性，而是把index的值赋给它。</p>

<p>&#160;</p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p>相关范例请参考<a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank">NPOI 1.2正式版</a>中的SetBorderStyleInXls项目。</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1429376.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47984/" target="_blank">《商业周刊》:Mozilla的志愿者开发模式被复制</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item><item><title>NPOI 1.2教程 - 2.2.3 单元格对齐相关设置</title><link>http://www.cnblogs.com/tonyqus/archive/2009/04/01/1426732.html</link><dc:creator>Tony  Qu</dc:creator><author>Tony  Qu</author><pubDate>Wed, 01 Apr 2009 01:10:00 GMT</pubDate><guid>http://www.cnblogs.com/tonyqus/archive/2009/04/01/1426732.html</guid><wfw:comment>http://www.cnblogs.com/tonyqus/comments/1426732.html</wfw:comment><comments>http://www.cnblogs.com/tonyqus/archive/2009/04/01/1426732.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/tonyqus/comments/commentRss/1426732.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/tonyqus/services/trackbacks/1426732.html</trackback:ping><description><![CDATA[<p>作者：Tony Qu</p>  <p>NPOI官方网站：<a href="http://npoi.codeplex.com/">http://npoi.codeplex.com/</a></p>  <p>&#160;</p>  <p>本节将围绕“对齐”选项卡中的设置展开，虽然实际上你会发现该选项卡中的很多设置和对齐没有什么关系。合并单元格已经在<a href="http://www.cnblogs.com/tonyqus/archive/2009/03/30/1425376.html" target="_blank">2.2.2节</a>讲过了，这里就不提了。</p>  <p><a href="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="348" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_thumb_1.png" width="633" border="0" /></a> </p>  <p>首先我们用代码创建必要的单元格，代码如下：</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFWorkbook hssfworkbook = <span style="color: #0000ff">new</span> HSSFWorkbook();
HSSFSheet sheet1 = hssfworkbook.CreateSheet(<span style="color: #006080">&quot;Sheet1&quot;</span>);
HSSFRow row = sheet1.CreateRow(0);
row.CreateCell(0).SetCellValue(<span style="color: #006080">&quot;Test&quot;</span>);</pre>
</div>

<p>这里我们假设在A0单元格中加入了文本Test。</p>

<p>&#160;</p>

<p>请注意接下来我们要做的所有操作都是在CellStyle的基础上完成的，所以我们创建一个HSSFCellStyle：</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">HSSFCellStyle style=hssfworkbook.CreateCellStyle();</pre>
</div>

<p>&#160;</p>

<p><u>水平对齐</u></p>

<p>这里用的是HSSFCellStyle.Alignment，默认值自然是常规，即HSSFCellStyle.ALIGN_GENERAL。</p>

<p>如果是左侧对齐就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_LEFT;</pre>
</div>

<p>如果是居中对齐就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_CENTER;</pre>
</div>

<p>如果是右侧对齐就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_RIGHT;</pre>
</div>

<p>如果是跨列举中就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_CENTER_SELECTION;</pre>
</div>

<p>如果是两端对齐就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_JUSTIFY;</pre>
</div>

<p>如果是填充就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Alignment = HSSFCellStyle.ALIGN_FILL;</pre>
</div>

<p>&#160;</p>

<p>注意：以上选项仅当有足够的宽度时才能产生效果，不设置宽度恐怕看不出区别。</p>

<p>&#160;</p>

<p><u>垂直对齐</u></p>

<p>这里用的是HSSFCellStyle.VerticalAlignment，默认值为居中，即HSSFCellStyle.VERTICAL_CENTER</p>

<p>如果是靠上就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.VerticalAlignment=HSSFCellStyle.VERTICAL_TOP</pre>
</div>

<p>如果是居中就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.VerticalAlignment=HSSFCellStyle.VERTICAL_CENTER</pre>
</div>

<p>如果是靠下就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.VerticalAlignment=HSSFCellStyle.VERTICAL_BOTTOM</pre>
</div>

<p>如果是两端对齐就是</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.VerticalAlignment=HSSFCellStyle.VERTICAL_JUSTIFY</pre>
</div>

<p>注意：以上选项仅当有足够的高度时才能产生效果，不设置高度恐怕看不出区别。</p>

<p>&#160;</p>

<p><u>自动换行</u></p>

<p><u></u></p>

<p>自动换行翻译成英文其实就是Wrap的意思，所以这里我们应该用WrapText属性，这是一个布尔属性</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.WrapText = <span style="color: #0000ff">true</span>;</pre>
</div>

<p>效果如下所示：</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_10.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_thumb_4.png" width="118" border="0" /></a> </p>

<p>&#160;</p>

<p><u>文本缩进</u></p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_12.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="54" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_thumb_5.png" width="95" border="0" /></a> </p>

<p>这是一个不太引人注意的选项，所以这里给张图出来，让大家知道是什么，缩进说白了就是文本前面的空白，我们同样可以用属性来设置，这个属性叫做Indention。</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Indention = 3;</pre>
</div>

<p>&#160;</p>

<p><u>文本旋转</u></p>

<p>文本方向大家一定在Excel中设置过，上图中就是调整界面，主要参数是度数，那么我们如何在NPOI中设置呢？</p>

<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
  <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">style.Rotation=(<span style="color: #0000ff">short</span>)90;</pre>
</div>

<p>以上代码是把单元格A1中的文本逆时针旋转90度，等同于下图中的设置：</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="180" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/tonyqus/WindowsLiveWriter/NPOI1.22.2.3_1375D/image_thumb_3.png" width="129" border="0" /></a>&#160;&#160;&#160; </p>

<p>&#160;</p>

<p>请注意，这里的Rotation取值是从-90到90，而不是0-180度。</p>

<p>&#160;</p>

<p>最后别忘了把样式变量style赋给HSSFCellStyle.CellStyle，否则就前功尽弃了，呵呵！</p>

<p>&#160;</p>

<p>以上的一些功能，比如文本旋转和自动换行，使用传统的cvs和html法恐怕是无法实现的。随着学习的不断深入，你将越来越意识到使用NPOI生成Excel其实如此简单。</p>

<p>相关范例请参考<a href="http://npoi.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21991" target="_blank">NPOI 1.2正式版</a>中的SetAlignmentInXls和RotateTextInXls。</p><img src ="http://www.cnblogs.com/tonyqus/aggbug/1426732.html?type=1" width = "1" height = "1" /><br/><br/>--------------------------<br/>新闻：<a href="http://news.cnblogs.com/n/47977/" target="_blank">Mono 的Virtual PC 虚拟机</a><br/>网站导航: <a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://dotnet.cnblogs.com" target="_blank">.NET频道</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://zzk.cnblogs.com" target="_blank">找找看</a>]]></description></item></channel></rss>