{"id":45,"date":"2019-07-22T14:36:37","date_gmt":"2019-07-22T06:36:37","guid":{"rendered":"http:\/\/www.zkjia.com\/?p=45"},"modified":"2019-07-22T14:42:04","modified_gmt":"2019-07-22T06:42:04","slug":"npoishiyongshouce-yigec-laicaozuoexcel-yu-word-dezujian","status":"publish","type":"post","link":"http:\/\/www.zkjia.com\/?p=45","title":{"rendered":"NPOI\u4f7f\u7528\u624b\u518c \u3010\u4e00\u4e2aC# \u6765\u64cd\u4f5cExcel \u4e0e Word \u7684\u7ec4\u4ef6\u3011"},"content":{"rendered":"\n<p>\u76ee\u5f55<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/08\/1541606.html\" target=\"_blank\" rel=\"noreferrer noopener\">1.\u8ba4\u8bc6<\/a>NPOI<\/p>\n\n\n\n<p>2.&nbsp;\u4f7f\u7528NPOI\u751f\u6210xls\u6587\u4ef6<\/p>\n\n\n\n<p>2.1&nbsp;\u521b\u5efa\u57fa\u672c\u5185\u5bb9<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/22\/1419293.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.1.1\u521b\u5efa<\/a>Workbook\u548cSheet<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/23\/1419364.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.1.2\u521b\u5efa<\/a>DocumentSummaryInformation\u548cSummaryInformation<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/23\/1419988.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.1.3\u521b\u5efa\u5355\u5143\u683c<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/25\/1421287.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.1.5\u521b\u5efa\u6279\u6ce8<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/08\/1541604.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.1.6\u521b\u5efa\u9875\u7709\u548c\u9875\u811a<\/a><\/p>\n\n\n\n<p>2.2&nbsp;\u5355\u5143\u683c\u64cd\u4f5c<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/27\/1422734.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.1\u8bbe\u7f6e\u683c\u5f0f<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/30\/1425376.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.2\u5408\u5e76\u5355\u5143\u683c<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/31\/1426732.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.3\u5bf9\u9f50\u76f8\u5173\u8bbe\u7f6e<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/04\/1429376.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.4\u4f7f\u7528\u8fb9\u6846<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/04\/1429499.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.5\u5b57\u4f53\u8bbe\u7f6e<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/08\/1432096.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.6\u80cc\u666f\u548c\u7eb9\u7406<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/12\/1434106.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.7\u8bbe\u7f6e\u5bbd\u5ea6\u548c\u9ad8\u5ea6<\/a><\/p>\n\n\n\n<p>2.3&nbsp;\u4f7f\u7528Excel\u516c\u5f0f<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/10\/1564407.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.1\u57fa\u672c\u8ba1\u7b97<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/10\/1564412.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.2 SUM\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565644.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.3\u65e5\u671f\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565899.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.4\u5b57\u7b26\u4e32\u76f8\u5173\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/15\/1566667.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.5 IF\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/16\/1567379.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.6 CountIf\u548c<\/a>SumIf\u51fd\u6570<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575317.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.7 Lookup\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575327.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.8\u968f\u673a\u6570\u51fd\u6570<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/12\/1582085.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.9\u901a\u8fc7<\/a>NPOI\u83b7\u5f97\u516c\u5f0f\u7684\u8fd4\u56de\u503c<\/p>\n\n\n\n<p>2.4&nbsp;\u521b\u5efa\u56fe\u5f62<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565645.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.1\u753b\u7ebf<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565901.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.2\u753b\u77e9\u5f62<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575309.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.3\u753b\u5706\u5f62<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/25\/1589570.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.4\u753b<\/a>Grid<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/28\/1576044.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.5\u63d2\u5165\u56fe\u7247<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/05\/10\/1453589.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.5\u6253\u5370\u76f8\u5173\u8bbe\u7f6e<\/a><\/p>\n\n\n\n<p>&nbsp;&nbsp;<br>2.6&nbsp;\u9ad8\u7ea7\u529f\u80fd<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/28\/1576063.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.1\u8c03\u6574\u8868\u5355\u663e\u793a\u6bd4\u4f8b<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/18\/1568917.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.2\u8bbe\u7f6e\u5bc6\u7801<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/13\/1434453.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.3\u7ec4\u5408\u884c\u3001\u5217<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/18\/1568918.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.4\u9501\u5b9a\u5217<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/12\/1434100.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.5\u663e\u793a<\/a>\/\u9690\u85cf\u7f51\u683c\u7ebf<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/11\/15\/1603516.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.6\u8bbe\u7f6e\u521d\u59cb\u89c6\u56fe\u7684\u884c\u3001\u5217<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/22\/1572170.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.7\u6570\u636e\u6709\u6548\u6027<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/24\/1572980.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.8\u751f\u6210\u4e0b\u62c9\u5f0f\u83dc\u5355<\/a><\/p>\n\n\n\n<p>3.&nbsp;\u9879\u76ee\u5b9e\u8df5<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/10\/1543242.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.1\u57fa\u4e8e<\/a>.xls\u6a21\u677f\u751f\u6210Excel\u6587\u4ef6<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/29\/1576070.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.2\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/13\/1582832.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.3\u751f\u6210\u4e00\u5f20\u5de5\u8d44\u5355<\/a><\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/18\/1585536.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.4\u4ece<\/a>xls\u6587\u4ef6\u4e2d\u62bd\u53d6\u6587\u672c<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/25\/1589606.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.5\u5de7\u5999\u4f7f\u7528<\/a>ExcelChart<\/p>\n\n\n\n<p><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/12\/24\/1631075.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.6\u5bfc\u5165<\/a>Excel\u6587\u4ef6<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/08\/1541606.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 1&nbsp;\u8ba4\u8bc6NPOI<\/strong><\/p>\n\n\n\n<p>\u672c\u7ae0\u5c06\u4ecb\u7ecdNPOI\u7684\u4e00\u4e9b\u57fa\u672c\u4fe1\u606f\uff0c\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u90e8\u5206<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4ec0\u4e48\u662fNPOI<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u7248\u6743\u8bf4\u660e<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u76f8\u5173\u8d44\u6e90<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u56e2\u961f\u4ecb\u7ecd<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u672a\u6765\u5c55\u671b<\/p>\n\n\n\n<p>\u00b7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5404Assembly\u7684\u4f5c\u7528<\/p>\n\n\n\n<p>1.1&nbsp;\u4ec0\u4e48\u662fNPOI<\/p>\n\n\n\n<p>NPOI\uff0c\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662fPOI\u7684.NET\u7248\u672c\u3002\u90a3POI\u53c8\u662f\u4ec0\u4e48\u5462\uff1fPOI\u662f\u4e00\u5957\u7528Java\u5199\u6210\u7684\u5e93\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u5728\u6ca1\u6709\u5b89\u88c5\u5fae\u8f6fOffice\u7684\u60c5\u51b5\u4e0b\u8bfb\u5199Office 97-2003\u7684\u6587\u4ef6\uff0c\u652f\u6301\u7684\u6587\u4ef6\u683c\u5f0f\u5305\u62ecxls, doc, ppt\u7b49\u3002\u5728\u672c\u6587\u53d1\u5e03\u65f6\uff0cPOI\u7684\u6700\u65b0\u7248\u672c\u662f3.5 beta 6\u3002<\/p>\n\n\n\n<p>NPOI 1.x\u662f\u57fa\u4e8ePOI 3.x\u7248\u672c\u5f00\u53d1\u7684\uff0c\u4e0epoi 3.2\u5bf9\u5e94\u7684\u7248\u672c\u662fNPOI 1.2\uff0c\u76ee\u524d\u6700\u65b0\u53d1\u5e03\u7684\u7248\u672c\u662f1.2.1\uff0c\u5728\u8be5\u7248\u672c\u4e2d\u4ec5\u652f\u6301\u8bfb\u5199Excel\u6587\u4ef6\u548cDrawing\u683c\u5f0f\uff0c\u5176\u4ed6\u6587\u4ef6\u683c\u5f0f\u5c06\u5728\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u5f97\u5230\u652f\u6301\u3002<\/p>\n\n\n\n<p>1.2&nbsp;\u7248\u6743\u8bf4\u660e<\/p>\n\n\n\n<p>NPOI\u91c7\u7528\u7684\u662fApache 2.0\u8bb8\u53ef\u8bc1\uff08poi\u4e5f\u662f\u91c7\u7528\u8fd9\u4e2a\u8bb8\u53ef\u8bc1\uff09\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u88ab\u7528\u4e8e\u4efb\u4f55\u5546\u4e1a\u6216\u975e\u5546\u4e1a\u9879\u76ee\uff0c\u4f60\u4e0d\u7528\u62c5\u5fc3\u56e0\u4e3a\u4f7f\u7528\u5b83\u800c\u5fc5\u987b\u5f00\u653e\u4f60\u81ea\u5df1\u7684\u6e90\u4ee3\u7801\uff0c\u6240\u4ee5\u5b83\u5bf9\u4e8e\u5f88\u591a\u4ece\u4e8b\u4e1a\u52a1\u7cfb\u7edf\u5f00\u53d1\u7684\u516c\u53f8\u6765\u8bf4\u7edd\u5bf9\u662f\u5f88\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\u4f5c\u4e3a\u4e00\u4e2a\u5f00\u6e90\u8bb8\u53ef\u8bc1\uff0c\u80af\u5b9a\u4e5f\u662f\u6709\u4e00\u4e9b\u4e49\u52a1\u7684\uff0c\u4f8b\u5982\u5982\u679c\u4f60\u5728\u7cfb\u7edf\u4e2d\u4f7f\u7528NPOI\uff0c\u4f60\u5fc5\u987b\u4fdd\u7559NPOI\u4e2d\u7684\u6240\u6709\u58f0\u660e\u4fe1\u606f\u3002\u5bf9\u4e8e\u6e90\u4ee3\u7801\u7684\u4efb\u4f55\u4fee\u6539\uff0c\u5fc5\u987b\u505a\u51fa\u660e\u786e\u7684\u6807\u8bc6\u3002<\/p>\n\n\n\n<p>\u5b8c\u6574\u7684apache 2.0\u8bb8\u53ef\u8bc1\u8bf7\u89c1<a href=\"http:\/\/www.phpx.com\/man\/Apache-2\/license.html\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.phpx.com\/man\/Apache-2\/license.html<\/a><\/p>\n\n\n\n<p>1.3&nbsp;\u76f8\u5173\u8d44\u6e90<\/p>\n\n\n\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>POIFS Browser 1.2<\/p>\n\n\n\n<p>\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=24305\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=24305<\/a><\/p>\n\n\n\n<p>QQ\u4ea4\u6d41\u7fa4:&nbsp; 78142590<\/p>\n\n\n\n<p>1.4&nbsp;\u56e2\u961f\u4ecb\u7ecd<\/p>\n\n\n\n<p>Tony Qu\u6765\u81ea\u4e8e\u4e2d\u56fd\u4e0a\u6d77\uff0c\u662f\u8fd9\u4e2a\u9879\u76ee\u7684\u53d1\u8d77\u4eba\u548c\u5f00\u53d1\u4eba\u5458\uff0c\u65f6\u533a\u662fGMT+8\uff0c2008\u5e749\u6708\u5f00\u59cb\u4e86NPOI\u7684\u5f00\u53d1\uff0c\u8d1f\u8d23NPOI\u6240\u6709\u5e95\u5c42\u5e93\u7684\u5f00\u53d1\u3001\u6d4b\u8bd5\u548cbug\u4fee\u590d\u3002<\/p>\n\n\n\n<p>\u4e2a\u4ebablog\u5730\u5740\u4e3a<a href=\"http:\/\/tonyqus.cnblogs.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/tonyqus.cnblogs.com\/<\/a><\/p>\n\n\n\n<p>H\u00fcseyinT\u00fcfek\u00e7ilerli\u6765\u81ea\u4e8e\u571f\u8033\u5176\u7684\u4f0a\u65af\u5766\u5e03\u5c14\uff0c\u4e5f\u662f\u8fd9\u4e2a\u9879\u76ee\u7684\u5f00\u53d1\u4eba\u5458\uff0c\u65f6\u533a\u662fGMT+2\uff0c2008\u5e7411\u6708\u53c2\u4e0e\u4e86NPOI\u7684\u5f00\u53d1\uff0c\u4e3b\u8981\u8d1f\u8d23POIFS Browser 1.0\u7684\u5f00\u53d1\u5de5\u4f5c\u3002<\/p>\n\n\n\n<p>\u4e2a\u4ebablog\u5730\u5740\u4e3a<a href=\"http:\/\/huseyint.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/huseyint.com\/<\/a><\/p>\n\n\n\n<p>aTao.Xiang\uff0c\u6765\u81ea\u4e2d\u56fd\uff0c2009\u5e748\u6708\u5f00\u59cb\u53c2\u4e0e\u8be5\u9879\u76ee\uff0c\u4e3b\u8981\u53c2\u4e0e\u4e86NPOI 1.2\u4e2d\u6587\u7248\u7684\u64b0\u5199\u5de5\u4f5c\u548c\u63a8\u5e7f\u5de5\u4f5c<\/p>\n\n\n\n<p>\u4e2a\u4ebablog\u5730\u5740\u4e3a<a href=\"http:\/\/www.cnblogs.com\/atao\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.cnblogs.com\/atao\/<\/a><\/p>\n\n\n\n<p>1.5&nbsp;\u56de\u987e\u4e0e\u5c55\u671b<\/p>\n\n\n\n<p>\u76ee\u524dPOI\u7248\u672c\u4e2d\u7684HWPF\uff08\u7528\u4e8eWord\u7684\u8bfb\u5199\u5e93\uff09\u8fd8\u4e0d\u662f\u5f88\u7a33\u5b9a\uff0c\u5e76\u975e\u6b63\u5f0f\u53d1\u5e03\u7248\u672c\uff0c\u4e14\u8d1f\u8d23HWPF\u7684\u5173\u952e\u5f00\u53d1\u4eba\u5458\u5df2\u7ecf\u79bb\u5f00\uff0c\u6240\u4ee5NPOI\u53ef\u80fd\u8003\u8651\u81ea\u5df1\u91cd\u65b0\u5f00\u53d1HWPF\u3002\u53e6\u5916\uff0c\u76ee\u524d\u5fae\u8f6f\u6b63\u5728\u5f00\u53d1Open XML Format SDK\uff0cNPOI\u53ef\u80fd\u4f1a\u653e\u5f03\u5bf9ooxml\u7684\u652f\u6301\uff0c\u5f53\u7136\u8fd9\u53d6\u51b3\u4e8e\u7528\u6237\u7684\u9700\u6c42\u548cOpen XML Format SDK\u7684\u7a33\u5b9a\u6027\u548c\u901f\u5ea6\u3002\u4ece\u76ee\u524d\u800c\u8a00\uff0cNPOI\u6709\u51e0\u5927\u4f18\u52bf<\/p>\n\n\n\n<p>\u7b2c\u4e00\uff0c\u5b8c\u5168\u57fa\u4e8e.NET 2.0\uff0c\u800c\u975e.NET 3.0\/3.5\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\uff0c\u8bfb\u5199\u901f\u5ea6\u5feb\uff08\u6709\u4e2a\u56fd\u5916\u7684\u5144\u5f1f\u56de\u590d\u8bf4\uff0c\u4ed6\u539f\u6765\u7528ExcelPackage\u751f\u6210\u7528\u4e864-5\u4e2a\u5c0f\u65f6\uff0c\u73b0\u5728\u53ea\u9700\u89814-5\u5206\u949f\uff09<\/p>\n\n\n\n<p>\u7b2c\u4e09\uff0c\u7a33\u5b9a\u6027\u597d\uff08\u76f8\u5bf9\u4e8e\u7528Office OIA\u800c\u8a00\uff0c\u6bd5\u7adf\u90a3\u4e1c\u897f\u662f\u57fa\u4e8eAutomation\u505a\u7684\uff0c\u5728Server\u4e0a\u8dd1\u4e2aAutomation\u7684\u4e1c\u897f\uff0c\u60f3\u60f3\u90fd\u89c9\u5f97\u53ef\u6015\uff09\uff0c\u8dd1\u8fc7\u4e86\u5c06\u8fd11000\u4e2a\u6d4b\u8bd5\u7528\u4f8b\uff08\u6765\u81ea\u4e8ePOI\u7684testcase\u76ee\u5f55\uff09<\/p>\n\n\n\n<p>\u7b2c\u56db\uff0cAPI\u7b80\u5355\u6613\u7528\uff0c\u5f53\u7136\u8fd9\u5f97\u611f\u8c22POI\u7684\u8bbe\u8ba1\u5e08\u4eec<\/p>\n\n\n\n<p>\u7b2c\u4e94\uff0c\u5b8c\u7f8e\u652f\u6301Excel 2003\u683c\u5f0f\uff08\u636e\u8bf4myxls\u65e0\u6cd5\u6b63\u786e\u8bfb\u53d6xls\u6a21\u677f\uff0c\u4f46NPOI\u53ef\u4ee5\uff09\uff0c\u4ee5\u540e\u4e5f\u8bb8\u662f\u6240\u6709Office 2003\u683c\u5f0f<\/p>\n\n\n\n<p>\u5e0c\u671bNPOI\u628a\u8fd9\u4e9b\u4f18\u52bf\u7ee7\u7eed\u53d1\u626c\u4e0b\u53bb\uff0c\u8fd9\u6837NPOI\u624d\u4f1a\u66f4\u6709\u7ade\u4e89\u529b\u3002<\/p>\n\n\n\n<p>1.6 NPOI 1.2\u4e2d\u5404Assembly\u7684\u4f5c\u7528<\/p>\n\n\n\n<p>NPOI\u76ee\u524d\u6709\u597d\u51e0\u4e2aassembly\uff0c\u6bcf\u4e2a\u7684\u4f5c\u7528\u5404\u6709\u4e0d\u540c\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6309\u9700\u52a0\u8f7d\u76f8\u5e94\u7684assembly\u3002\u5728\u8fd9\u91cc\u5927\u6982\u7f57\u5217\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<p>NPOI.Util&nbsp;&nbsp;\u57fa\u7840\u8f85\u52a9\u5e93<br>NPOI.POIFS&nbsp;&nbsp; OLE2\u683c\u5f0f\u8bfb\u5199\u5e93<br>NPOI.DDF&nbsp;&nbsp; Microsoft Drawing\u683c\u5f0f\u8bfb\u5199\u5e93<br>NPOI.SS&nbsp;&nbsp; Excel\u516c\u5f0f\u8ba1\u7b97\u5e93<br>NPOI.HPSF&nbsp;&nbsp; OLE2\u7684Summary Information\u548cDocument Summary Information\u5c5e\u6027\u8bfb\u5199\u5e93<br>NPOI.HSSF&nbsp;&nbsp; Excel BIFF\u683c\u5f0f\u8bfb\u5199\u5e93<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/23\/1419293.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.1.1&nbsp;\u521b\u5efaWorkbook\u548cSheet<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u521b\u5efaWorkbook\u8bf4\u767d\u4e86\u5c31\u662f\u521b\u5efa\u4e00\u4e2aExcel\u6587\u4ef6\uff0c\u5f53\u7136\u5728NPOI\u4e2d\u66f4\u51c6\u786e\u7684\u8868\u793a\u662f\u5728\u5185\u5b58\u4e2d\u521b\u5efa\u4e00\u4e2aWorkbook\u5bf9\u8c61\u6d41\u3002<\/p>\n\n\n\n<p>\u672c\u8282\u4f5c\u4e3a\u7b2c2\u7ae0\u7684\u5f00\u7bc7\u7ae0\u8282\uff0c\u5c06\u505a\u8f83\u4e3a\u8be6\u7ec6\u7684\u8bb2\u89e3\uff0c\u4ee5\u5e2e\u52a9NPOI\u7684\u5b66\u4e60\u8005\u66f4\u597d\u7684\u7406\u89e3NPOI\u7684\u7ec4\u6210\u548c\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>NPOI.HSSF\u662f\u4e13\u95e8\u8d1f\u8d23Excel BIFF\u683c\u5f0f\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u4f9b\u5f00\u53d1\u8005\u4f7f\u7528\u7684\u5bf9\u8c61\u4e3b\u8981\u4f4d\u4e8eNPOI.HSSF.UserModel\u548cNPOI.HSSF.Util\u547d\u540d\u7a7a\u95f4\u4e0b\uff0c\u4e0b\u9762\u6211\u4eec\u8981\u8bb2\u5230\u7684Workbook\u7684\u521b\u5efa\u7528\u7684\u5c31\u662fNPOI.HSSF.UserModel.HSSFWorkbook\u7c7b\uff0c\u8fd9\u4e2a\u7c7b\u8d1f\u8d23\u521b\u5efa.xls\u6587\u6863\u3002<\/p>\n\n\n\n<p>\u5728\u5f00\u59cb\u521b\u5efaWorkbook\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u8981\u5728\u9879\u76ee\u4e2d\u5f15\u7528\u4e00\u4e9b\u5fc5\u8981\u7684NPOI assembly\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>NPOI.dll<\/p>\n\n\n\n<p>NPOI.POIFS.dll<\/p>\n\n\n\n<p>NPOI.HSSF.dll<\/p>\n\n\n\n<p>NPOI.Util.dll<\/p>\n\n\n\n<p>\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684xls\u6587\u4ef6\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u53ea\u8981\u6211\u4eec\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u7684HSSFWorkbook\u5b9e\u4f8b\u5c31\u884c\u4e86\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>using&nbsp;NPOI.HSSF.UserModel;<\/p>\n\n\n\n<p>&#8230;<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u554a\uff0c\u6ca1\u6709\u4efb\u4f55\u53c2\u6570\u6216\u8bbe\u7f6e\uff0c\u4f46\u8fd9\u4e48\u521b\u5efa\u6709\u4e00\u4e9b\u9650\u5236\uff0c\u8fd9\u6837\u521b\u5efa\u51fa\u6765\u7684Workbook\u5728Excel\u4e2d\u6253\u5f00\u662f\u4f1a\u62a5\u9519\u7684\uff0c\u56e0\u4e3aExcel\u89c4\u5b9a\u4e00\u4e2aWorkbook\u5fc5\u987b\u81f3\u5c11\u5e261\u4e2aSheet\uff0c\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u5728Excel\u754c\u9762\u4e2d\uff0c\u65b0\u5efa\u4e00\u4e2aWorkbook\u9ed8\u8ba4\u90fd\u4f1a\u65b0\u5efa3\u4e2aSheet\u3002\u6240\u4ee5\u5fc5\u987b\u52a0\u5165\u4e0b\u9762\u7684\u521b\u5efaSheet\u7684\u4ee3\u7801\u624d\u80fd\u4fdd\u8bc1\u751f\u6210\u7684\u6587\u4ef6\u6b63\u5e38\uff1a<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.CreateSheet(&#8220;newsheet&#8221;);<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u521b\u5efa\u6807\u51c6\u7684Excel\u6587\u4ef6\uff0c\u5373\u62e5\u67093\u4e2aSheet\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>hssfworkbook.CreateSheet(&#8220;Sheet2&#8221;);<\/p>\n\n\n\n<p>hssfworkbook.CreateSheet(&#8220;Sheet3&#8221;);<\/p>\n\n\n\n<p>\u6700\u540e\u5c31\u662f\u628a\u8fd9\u4e2aHSSFWorkbook\u5b9e\u4f8b\u5199\u5165\u6587\u4ef6\u4e86\uff0c\u4ee3\u7801\u4e5f\u5f88\u7b80\u5355\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>FileStreamfile =new&nbsp;FileStream(@&#8221;test.xls&#8221;, FileMode.Create);<\/p>\n\n\n\n<p>hssfworkbook.Write(file);<\/p>\n\n\n\n<p>file.Close();<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5047\u8bbe\u6587\u4ef6\u540d\u662ftest.xls\uff0c\uff0c\u5728\u521b\u5efa\u5b8cFileStream\u4e4b\u540e\uff0c\u76f4\u63a5\u8c03\u7528HSSFWorkbook\u7c7b\u7684Write\u65b9\u6cd5\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u4f60\u53ef\u4ee5\u6253\u5f00test.xls\u6587\u4ef6\u786e\u8ba4\u4e00\u4e0b\uff0c\u662f\u4e0d\u662f\u67093\u4e2a\u7a7a\u7684Sheet\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684CreateEmptyExcelFile\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/24\/1419364.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.1.2&nbsp;\u521b\u5efaDocumentSummaryInformation\u548cSummaryInformation<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u6628\u5929\u6536\u5230\u4e86\u4e0d\u5c11\u56de\u590d\uff0c\u6709msn\u4e0a\u7684\uff0c\u4e5f\u6709blog\u4e0a\u7684\uff0c\u6211\u4ee3\u8868NPOI Team\u5411\u6240\u6709\u652f\u6301\u548c\u5173\u6ce8NPOI\u7684\u5144\u5f1f\u8868\u793a\u611f\u8c22\uff0c\u8ba9\u6211\u4eec\u5171\u540c\u5b8c\u5584NPOI\u3002<\/p>\n\n\n\n<p>\u524d\u4e00\u8282\u4e2d\u6211\u4eec\u8bb2\u89e3\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Workbook\uff0c\u4f46\u5728\u6b64\u8fc7\u7a0b\u4e2d\u5927\u5bb6\u4e5f\u8bb8\u4f1a\u53d1\u73b0\u4e00\u4e2a\u7ec6\u8282\uff0c\u8fd9\u4e9b\u6587\u4ef6\u6ca1\u6709\u5305\u62ecDocummentSummaryInformation\u548cSummaryInformation\u5934\u3002\u5982\u679c\u4f60\u8fd8\u4e0d\u662f\u5f88\u6e05\u695a\u6211\u5728\u8bf4\u4ec0\u4e48\uff0c\u53ef\u4ee5\u770bPOIFS Browser\u6253\u5f00test.xls\u6587\u4ef6\u540e\u7684\u622a\u56fe\uff1a<\/p>\n\n\n\n<p>\u4f60\u4f1a\u53d1\u73b0\u53ea\u6709Workbook\u76ee\u5f55\uff0c\u5176\u4ed6\u4ec0\u4e48\u90fd\u6ca1\u6709\uff0c\u4f46\u4e8b\u5b9e\u4e0a\u4e00\u4e2a\u6b63\u5e38\u7684xls\u6587\u4ef6\uff0c\u6bd4\u5982\u8bf4Excel\u751f\u6210\u7684xls\u6587\u4ef6\u662f\u7c7b\u4f3c\u4e0b\u9762\u7684\u7ed3\u6784\uff1a<\/p>\n\n\n\n<p>\u662f\u4e0d\u662f\u591a\u51fa\u6765DocumentSummaryInformation\u548cSummaryInformation\u4e24\u4e2a\u5934\uff1f\u5f88\u591a\u4eba\u53ef\u80fd\u5bf9DocumentSummaryInformation\u548cSummaryInformation\u5f88\u964c\u751f\uff0c\u53ef\u80fd\u7b2c\u4e00\u6b21\u542c\u8bf4\u8fd9\u73a9\u610f\uff0c\u6ca1\u4e8b\uff0c\u8fd9\u5f88\u6b63\u5e38\uff0c\u56e0\u4e3a\u666e\u901a\u7528\u6237\u5f88\u5c11\u4f1a\u53bb\u4f7f\u7528\u8fd9\u4e9b\u4e1c\u897f\uff0c\u4f46\u5b83\u4eec\u5176\u5b9e\u6bd4\u60f3\u8c61\u4e2d\u6709\u7528\u3002<\/p>\n\n\n\n<p>\u8bf7\u770b\u4e0a\u56fe\u4e2d\u7684\u4fe1\u606f\uff0c\u5982\u4f5c\u8005\u3001\u6807\u9898\u3001\u6807\u8bb0\u3001\u5907\u6ce8\u3001\u4e3b\u9898\u7b49\u4fe1\u606f\uff0c\u5176\u5b9e\u8fd9\u4e9b\u4fe1\u606f\u90fd\u662f\u5b58\u50a8\u5728DocummentSummaryInformation\u548cSummaryInformation\u91cc\u9762\u7684\uff0c\u8fd9\u4e48\u4e00\u8bf4\u6211\u60f3\u5927\u5bb6\u5e94\u8be5\u660e\u767d\u4e86\u5427\uff0c\u8fd9\u4e9b\u4fe1\u606f\u662f\u4e3a\u4e86\u5feb\u901f\u63d0\u53d6\u6587\u4ef6\u4fe1\u606f\u51c6\u5907\u3002\u5728Windows XP\u4e2d\uff0c\u4e5f\u6709\u5bf9\u5e94\u7684\u67e5\u770b\u548c\u4fee\u6539\u754c\u9762\uff0c\u53ea\u662f\u6ca1\u6709Vista\u8fd9\u4e48\u65b9\u4fbf\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>\u8fd9\u6050\u6015\u4e5f\u662f\u5f88\u591a\u4eba\u5bf9\u4e8e\u8fd9\u4e9b\u4fe1\u606f\u6f20\u4e0d\u5173\u5fc3\u7684\u539f\u56e0\u5427\uff0c\u56e0\u4e3a\u6ca1\u6709\u4eba\u613f\u610f\u901a\u8fc7\u53f3\u51fb\u6587\u4ef6-&gt;\u5c5e\u6027\u8fd9\u6837\u590d\u6742\u7684\u64cd\u4f5c\u53bb\u67e5\u770b\u4e00\u4e9b\u6458\u8981\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>\u63d0\u793a<\/strong><\/p>\n\n\n\n<p>DocummentSummaryInformation\u548cSummaryInformation\u5e76\u4e0d\u662fOffice\u6587\u4ef6\u7684\u4e13\u5229\uff0c\u53ea\u8981\u662fOLE2\u683c\u5f0f\uff0c\u90fd\u53ef\u4ee5\u62e5\u6709\u8fd9\u4e24\u4e2a\u5934\u4fe1\u606f\uff0c\u4e3b\u8981\u76ee\u7684\u5c31\u662f\u4e3a\u4e86\u5728\u6ca1\u6709\u5b8c\u6574\u8bfb\u53d6\u6587\u4ef6\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u83b7\u5f97\u6587\u4ef6\u7684\u6458\u8981\u4fe1\u606f\uff0c\u540c\u65f6\u4e5f\u53ef\u7528\u4f5c\u684c\u9762\u641c\u7d20\u7684\u4f9d\u636e\u3002\u8981\u4e86\u89e3DocummentSummaryInformation\u7684\u5168\u90e8\u5c5e\u6027\u8bf7\u89c1<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa380374%28VS.85%29.aspx\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/msdn.microsoft.com\/en-us\/library\/aa380374(VS.85).aspx<\/a>\uff1b\u8981\u4e86\u89e3SummaryInformation\u7684\u5168\u90e8\u5c5e\u6027\u8bf7\u89c1<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa369794%28VS.85%29.aspx\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/msdn.microsoft.com\/en-us\/library\/aa369794(VS.85).aspx<\/a>\u3002<\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u8bf4\u5230\u8fd9\u91cc\uff0c\u6211\u60f3\u5927\u5bb6\u5bf9\u4e8e\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u521b\u5efa\u7684\u5185\u5bb9\u6709\u4e86\u521d\u6b65\u7684\u8ba4\u8bc6\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u9a6c\u4e0a\u52a8\u624b\u521b\u5efa\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5f15\u7528\u4ee5\u4e0b\u8fd9\u4e9b\u547d\u540d\u7a7a\u95f4\uff1a<\/p>\n\n\n\n<p>using&nbsp;NPOI.HSSF.UserModel;<\/p>\n\n\n\n<p>using&nbsp;NPOI.HPSF;<\/p>\n\n\n\n<p>using&nbsp;NPOI.POIFS.FileSystem;<\/p>\n\n\n\n<p>\u5176\u4e2d\u4e0eDocummentSummaryInformation\u548cSummaryInformation\u5bc6\u5207\u76f8\u5173\u7684\u662fHPSF\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u521b\u5efaWorkbook<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>\u7136\u540e\u521b\u5efaDocumentSummaryInformation<\/p>\n\n\n\n<p>DocumentSummaryInformationdsi = PropertySetFactory.CreateDocumentSummaryInformation();<\/p>\n\n\n\n<p>dsi.Company =&#8221;NPOI Team&#8221;;<\/p>\n\n\n\n<p>\u518d\u521b\u5efaSummaryInformation<\/p>\n\n\n\n<p>SummaryInformationsi = PropertySetFactory.CreateSummaryInformation();<\/p>\n\n\n\n<p>si.Subject =&#8221;NPOI SDK Example&#8221;;<\/p>\n\n\n\n<p>\u56e0\u4e3a\u662f\u8303\u4f8b\uff0c\u8fd9\u91cc\u4ec5\u5404\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u5c5e\u6027\uff0c\u5176\u4ed6\u90fd\u6ca1\u6709\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u628a\u521b\u5efa\u597d\u7684\u5bf9\u8c61\u8d4b\u7ed9Workbook\uff0c\u8fd9\u6837\u624d\u80fd\u4fdd\u8bc1\u8fd9\u4e9b\u4fe1\u606f\u88ab\u5199\u5165\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>hssfworkbook.DocumentSummaryInformation= dsi;<\/p>\n\n\n\n<p>hssfworkbook.SummaryInformation= si;<\/p>\n\n\n\n<p>\u6700\u540e\u548c2.1.1\u8282\u4e00\u6837\uff0c\u6211\u4eec\u628aWorkbook\u901a\u8fc7FileStream\u5199\u5165\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684CreatePOIFSFileWithProperties<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/25\/1419988.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.1.3&nbsp;\u521b\u5efa\u5355\u5143\u683c<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u7528\u8fc7Excel\u7684\u4eba\u90fd\u77e5\u9053\uff0c\u5355\u5143\u683c\u662fExcel\u6700\u6709\u610f\u4e49\u7684\u4e1c\u897f\uff0c\u6211\u4eec\u505a\u4efb\u4f55\u64cd\u4f5c\u6050\u6015\u90fd\u8981\u548c\u5355\u5143\u683c\u6253\u4ea4\u9053\u3002\u5728Excel\u4e2d\u6211\u4eec\u8981\u6dfb\u52a0\u4e00\u4e2a\u5355\u5143\u683c\u53ea\u9700\u8981\u70b9\u51fb\u4efb\u4f55\u4e00\u4e2a\u5355\u5143\u683c\uff0c\u7136\u540e\u8f93\u5165\u5185\u5bb9\u5c31\u662f\u4e86\uff0c\u4f46\u662fExcel\u5e95\u5c42\u5176\u5b9e\u6ca1\u6709\u8fd9\u4e48\u7b80\u5355\uff0c\u4e0d\u540c\u7684\u5355\u5143\u683c\u662f\u6709\u4e0d\u540c\u7684\u7c7b\u578b\u7684\uff0c\u6bd4\u5982\u8bf4\u6570\u503c\u5355\u5143\u683c\u662f\u7528NumberRecord\u8868\u793a\uff0c\u6587\u672c\u5355\u5143\u683c\u662f\u7528LabelSSTRecord\u8868\u793a\uff0c\u7a7a\u5355\u5143\u683c\u662f\u7528BlankRecord\u8868\u793a\u3002\u8fd9\u4e5f\u5c31\u610f\u5473\u7740\uff0c\u5728\u8bbe\u7f6e\u5355\u5143\u683c\u65f6\uff0c\u4f60\u5fc5\u987b\u544a\u8bc9NPOI\u4f60\u9700\u8981\u521b\u5efa\u54ea\u79cd\u7c7b\u578b\u7684\u5355\u5143\u683c\u3002<\/p>\n\n\n\n<p>\u8981\u521b\u5efa\u5355\u5143\u683c\u9996\u5148\u8981\u521b\u5efa\u5355\u5143\u683c\u6240\u5728\u7684\u884c\uff0c\u6bd4\u5982\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u521b\u5efa\u4e86\u7b2c0\u884c\uff1a<\/p>\n\n\n\n<p>HSSFSheetsheet1 = hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>HSSFRowrow1=sheet1.CreateRow(0);<\/p>\n\n\n\n<p>\u884c\u5efa\u597d\u4e86\uff0c\u5c31\u53ef\u4ee5\u5efa\u5355\u5143\u683c\u4e86\uff0c\u6bd4\u5982\u521b\u5efaA1\u4f4d\u7f6e\u7684\u5355\u5143\u683c\uff1a<\/p>\n\n\n\n<p>row1.CreateCell(0).SetCellValue(1);<\/p>\n\n\n\n<p>\u8fd9\u91cc\u8981\u8bf4\u660e\u4e00\u4e0b\uff0cSetCellValue\u6709\u597d\u51e0\u79cd\u91cd\u8f7d\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u5355\u5143\u683c\u4e3abool\u3001double\u3001DateTime\u3001string\u548cHSSFRichTextString\u7c7b\u578b\u3002\u5176\u4e2d\u5bf9\u4e8estring\u7c7b\u578b\u7684\u91cd\u8f7d\u8c03\u7528\u7684\u5c31\u662fHSSFRichTextString\u7c7b\u578b\u7684\u91cd\u8f7d\uff0c\u6240\u4ee5\u662f\u4e00\u6837\u7684\uff0cHSSFRichTextString\u53ef\u7528\u4e8e\u6709\u5b57\u4f53\u6216\u8005Unicode\u7684\u6587\u672c\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u6bcf\u4e00\u884c\u8981\u58f0\u660e\u4e00\u4e2aHSSFRow\u5f88\u9ebb\u70e6\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellValue(&#8220;This is a Sample&#8221;);<\/p>\n\n\n\n<p>\u8fd9\u4e48\u7528\u6709\u4e2a\u524d\u63d0\uff0c\u90a3\u5c31\u662f\u7b2c0\u884c\u8fd8\u6ca1\u521b\u5efa\u8fc7\uff0c\u5426\u5219\u5f97\u8fd9\u4e48\u7528\uff1a<\/p>\n\n\n\n<p>sheet1.GetRow(0).CreateCell(0).SetCellValue(&#8220;This is a Sample&#8221;);<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u7684\u884c\u5728Excel\u91cc\u662f\u4ece1\u5f00\u59cb\u7684\uff0c\u4f46\u662fNPOI\u5185\u90e8\u662f\u4ece0\u5f00\u59cb\u7684\uff1b\u5217\u5728Excel\u91cc\u9762\u662f\u7528\u5b57\u6bcd\u8868\u793a\u7684\uff0c\u800cNPOI\u4e2d\u4e5f\u662f\u7528\u4ece0\u5f00\u59cb\u7684\u6570\u5b57\u8868\u793a\u7684\uff0c\u6240\u4ee5\u8981\u6ce8\u610f\u8f6c\u6362\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u8981\u83b7\u5f97\u67d0\u4e00\u4e2a\u5df2\u7ecf\u521b\u5efa\u7684\u5355\u5143\u683c\u5bf9\u8c61\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>sheet1.GetRow(row_index).GetCell(column_index);<\/p>\n\n\n\n<p>\u672c\u8282\u4ec5\u8bb2\u89e3\u6700\u57fa\u672c\u7684\u5355\u5143\u683c\u521b\u5efa\uff0c\u6709\u5173\u5355\u5143\u683c\u683c\u5f0f\u8bbe\u7f6e\u3001\u6837\u5f0f\u7b49\u9ad8\u7ea7\u8bdd\u9898\u8bf7\u89c1\uff1a2.2\u8282\u5355\u5143\u683c\u76f8\u5173\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684SetCellValuesInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/26\/1421287.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.1.4&nbsp;\u521b\u5efa\u6279\u6ce8<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5f88\u591a\u4eba\u4e0d\u600e\u4e48\u7528Excel\u4e2d\u7684\u6279\u6ce8\uff0c\u6240\u4ee5\u6211\u7279\u5730\u622a\u4e86\u5f20\u56fe\uff0c\u8ba9\u5927\u5bb6\u77e5\u9053\u672c\u8282\u6211\u4eec\u8981\u521b\u5efa\u7684\u5230\u5e95\u662f\u4ec0\u4e48\u4e1c\u897f\u3002<\/p>\n\n\n\n<p>\u5728\u8fc7\u53bb\uff0c\u6211\u4eec\u6050\u6015\u6ca1\u6709\u529e\u6cd5\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff0c\u56e0\u4e3a\u65e0\u8bba\u662fcvs\u6cd5\u3001html\u6cd5\u3001oledb\u6cd5\u90fd\u6ca1\u6709\u63d0\u4f9b\u8fd9\u6837\u7684\u63a5\u53e3\uff0c\u5f53\u7136Office PIA\u6cd5\u53ef\u4ee5\u505a\u5230\uff0c\u4f46\u662f\u6027\u80fd\u5b9e\u5728\u592a\u5dee\uff0c\u800c\u4e14\u7a33\u5b9a\u6027\u4e0d\u597d\uff0c\u7ecf\u5e38\u83ab\u540d\u5176\u5999crash\uff08\u8fd9\u662f\u67d0\u67d0\u5144\u5f1f\u7ed9\u6211\u7684\u53cd\u9988\uff0c\u6211\u5f15\u7528\u4e86\u4e0b\uff0c\u5475\u5475\uff09\u3002\u5728\u4ee5\u540e\u7684\u6559\u7a0b\u4e2d\uff0c\u4f60\u5c06\u770b\u5230\u66f4\u591a\u5728\u8fc7\u53bb\u65e0\u6cd5\u901a\u8fc7\u4f20\u7edf\u65b9\u6cd5\u5b9e\u73b0\u7684\u4e1c\u897f\uff0c\u597d\u620f\u624d\u521a\u521a\u5f00\u59cb\u3002<\/p>\n\n\n\n<p>\u6279\u6ce8\u4e3b\u8981\u6709\u4e09\u4e2a\u5c5e\u6027\u9700\u8981\u8bbe\u7f6e\uff0c\u4e00\u4e2a\u662f\u6279\u6ce8\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\u3001\u4e00\u4e2a\u662f\u6279\u6ce8\u7684\u6587\u672c\u3001\u8fd8\u6709\u4e00\u4e2a\u662f\u6279\u6ce8\u7684\u4f5c\u8005\u3002<\/p>\n\n\n\n<p>\u6279\u6ce8\u7684\u4f4d\u7f6e\u548c\u5927\u5c0f\uff0c\u5728Excel\u4e2d\u662f\u4e0e\u5355\u5143\u683c\u5bc6\u5207\u76f8\u5173\u7684\uff0cNPOI\u4e2d\u901a\u8fc7HSSFClientAnchor\u7684\u5b9e\u4f8b\u6765\u8868\u793a\uff0c\u5b83\u7684\u6784\u9020\u51fd\u6570\u6bd4\u8f83\u590d\u6742\uff0c\u67098\u4e2a\u53c2\u6570\uff0c\u5b83\u4eec\u5206\u522b\u662f<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u53c2\u6570<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td>dx1<\/td><td>\u7b2c1\u4e2a\u5355\u5143\u683c\u4e2dx\u8f74\u7684\u504f\u79fb\u91cf<\/td><\/tr><tr><td>dy1<\/td><td>\u7b2c1\u4e2a\u5355\u5143\u683c\u4e2dy\u8f74\u7684\u504f\u79fb\u91cf<\/td><\/tr><tr><td>dx2<\/td><td>\u7b2c2\u4e2a\u5355\u5143\u683c\u4e2dx\u8f74\u7684\u504f\u79fb\u91cf<\/td><\/tr><tr><td>dy2<\/td><td>\u7b2c2\u4e2a\u5355\u5143\u683c\u4e2dy\u8f74\u7684\u504f\u79fb\u91cf<\/td><\/tr><tr><td>col1<\/td><td>\u7b2c1\u4e2a\u5355\u5143\u683c\u7684\u5217\u53f7<\/td><\/tr><tr><td>row1<\/td><td>\u7b2c1\u4e2a\u5355\u5143\u683c\u7684\u884c\u53f7<\/td><\/tr><tr><td>col2<\/td><td>\u7b2c2\u4e2a\u5355\u5143\u683c\u7684\u5217\u53f7<\/td><\/tr><tr><td>row2<\/td><td>\u7b2c2\u4e2a\u5355\u5143\u683c\u7684\u884c\u53f7<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u6253\u7b97\u8ba9\u6ce8\u91ca\u663e\u793a\u5728B3\u548cE5\u4e4b\u95f4\uff0c\u5c31\u5e94\u8be5\u8fd9\u4e48\u5199\uff1a<\/p>\n\n\n\n<p>HSSFPatriarchpatr = sheet.CreateDrawingPatriarch();<\/p>\n\n\n\n<p>HSSFCommentcomment1 = patr.CreateComment(new&nbsp;HSSFClientAnchor(0, 0, 0, 0, 1, 2 , 4, 4));<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u8bbe\u7f6e\u8fd9\u4e2a\u6279\u6ce8\u7684\u5185\u5bb9\u548c\u4f5c\u8005\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u7b80\u5355\uff1a<\/p>\n\n\n\n<p>comment1.String=newHSSFRichTextString(&#8220;Hello World&#8221;);<\/p>\n\n\n\n<p>comment1.Author=&#8221;NPOI Team&#8221;;<\/p>\n\n\n\n<p>\u6700\u540e\u4e00\u6b65\u5c31\u662f\u628a\u6279\u6ce8\u8d4b\u7ed9\u67d0\u4e2a\u5355\u5143\u683c\uff1a<\/p>\n\n\n\n<p>HSSFCell cell= sheet.CreateRow(1).CreateCell(1);<\/p>\n\n\n\n<p>cell.CellComment= comment1;<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u6279\u6ce8\uff0c\u4f60\u6709\u4e24\u79cd\u9009\u62e9\uff0c\u4e00\u79cd\u662f\u9690\u85cf\uff08\u9ed8\u8ba4\uff09\uff0c\u4e00\u79cd\u662f\u663e\u793a\uff08\u5373\u8868\u5355\u4e00\u6253\u5f00\u5c31\u663e\u793a\u8be5\u6279\u6ce8\uff09\uff0c\u53ef\u4ee5\u901a\u8fc7comment1.Visible\u5c5e\u6027\u6765\u63a7\u5236\u3002<\/p>\n\n\n\n<p>\u770b\u4e86\u4e0a\u9762\u8fd9\u5f20\u56fe\u5927\u5bb6\u5c31\u5e94\u8be5\u660e\u767d\u4e86\uff0c\u8fd9\u91cc\u67092\u4e2a\u6279\u6ce8\uff0c\u4e0b\u9762\u90a3\u4e2a\u662f\u663e\u793a\u7684\uff0c\u4e0a\u9762\u90a3\u4e2a\u662f\u9690\u85cf\u7684\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684SetCellCommentInXls\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/08\/1541604.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.1.6&nbsp;\u521b\u5efa\u9875\u7709\u548c\u9875\u811a<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5f88\u591a\u4eba\u5e76\u4e0d\u77e5\u9053Excel\u7684\u9875\u7709\u548c\u9875\u811a\u529f\u80fd\uff0c\u56e0\u4e3a\u5728\u754c\u9762\u4e0a\u662f\u663e\u793a\u4e0d\u4e86\u9875\u7709\u548c\u9875\u811a\u7684\uff0c\u5fc5\u987b\u5728\u6253\u5370\u9875\u9762\u4e2d\u624d\u80fd\u770b\u5230\uff0c\u8fd9\u4e5f\u76f4\u63a5\u5bfc\u81f4\u4e86\u5176\u8bbe\u7f6e\u754c\u9762\u4e5f\u663e\u5f97\u66f4\u9690\u79d8\uff0c\u4f60\u5fc5\u987b\u8fdb\u5165\u9875\u9762\u8bbe\u7f6e&nbsp;\u2013&gt;\u9875\u7709\u548c\u9875\u811a\u624d\u80fd\u8bbe\u7f6e\u3002\u4ee5\u4e0b\u662fOffice 2007\u4e2d\u7684\u8bbe\u7f6e\u754c\u9762\u3002<\/p>\n\n\n\n<p>\u5f53\u4f60\u6309\u201c\u81ea\u5b9a\u4e49\u9875\u7709\u201d\u6216\u201c\u81ea\u5b9a\u4e49\u9875\u811a\u201d\u65f6\uff0c\u4f60\u4f1a\u770b\u5230\u4ee5\u4e0b\u754c\u9762\uff0cExcel\u628a\u9875\u7709\u3001\u9875\u811a\u5206\u6210\u4e86\u5de6\u4e2d\u53f3\u4e09\u90e8\u5206\uff0c\u8fd9\u4e00\u70b9\u7edd\u975e\u5355\u7eaf\u4f53\u73b0\u5728\u754c\u9762\u4e0a\uff0c\u5728\u5e95\u5c42\u7684\u5b58\u50a8\u4e2d\u4e5f\u662f\u5982\u6b64\u3002\u5982\u679c\u4f60\u8bbe\u7f6e\u7684\u662f\u201c\u5de6\u201d\u7684\u5185\u5bb9\uff0c\u5e95\u5c42\u7684\u5b58\u50a8\u5b57\u7b26\u4e32\u5c31\u4f1a\u5728\u5f00\u5934\u52a0\u4e0a&amp;L\uff0c\u5982\u679c\u662f\u201c\u53f3\u201d\u7684\u5185\u5bb9\u5219\u4f1a\u52a0\u4e0a&amp;R\uff0c\u6240\u4ee5HeaderRecord\u4e2d\u7684\u5b57\u7b26\u4e32\u770b\u4e0a\u53bb\u662f\u8fd9\u6837\u7684\uff1a&#8221;&amp;C&amp;LFooter A&amp;R\u201d\uff0c\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u610f\u601d\u662f\u4ec5\u8bbe\u7f6e\u4e86\u201c\u5de6\u201d\u7684\u5185\u5bb9\uff0c\u5185\u5bb9\u662fFooter A\u3002<\/p>\n\n\n\n<p>\u770b\u4e86\u8fd9\u4e9b\u6211\u60f3\u4f60\u5e94\u8be5\u5bf9\u9875\u7709\u548c\u9875\u811a\u6709\u6240\u4e86\u89e3\u4e86\uff0c\u56de\u8fc7\u5934\u6765\u8bf4NPOI\uff0cNPOI\u4e2d\u4e3b\u8981\u662f\u9760HSSFSheet.Header\u548cHSSFSheet.Footer\u6765\u8bbe\u7f6e\u7684\uff0c\u8fd9\u4e24\u4e2a\u5c5e\u6027\u5206\u522b\u662fHSSFHeader\u548cHSSFFooter\u7c7b\u578b\u7684\u3002<\/p>\n\n\n\n<p>\u53c2\u8003\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFSheet s1= hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>s1.CreateRow(0).CreateCell(1).SetCellValue(123);<\/p>\n\n\n\n<p>\/\/set headertext<\/p>\n\n\n\n<p>s1.Header.Center=&#8221;This is a test sheet&#8221;;<\/p>\n\n\n\n<p>\/\/set footertext<\/p>\n\n\n\n<p>s1.Footer.Left=&#8221;Copyright NPOI Team&#8221;;<\/p>\n\n\n\n<p>s1.Footer.Right=&#8221;created by Tony Qu\uff08\u77bf\u6770\uff09&#8221;;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4e2d\u6211\u6dfb\u52a0\u4e86\u9875\u7709\u7684Center\u5185\u5bb9\uff0cFooter\u7684Left\u548cRight\u5185\u5bb9\uff0c\u5728\u6253\u5370\u9884\u89c8\u4e2d\u770b\u5230\u7684\u6548\u679c\u5927\u6982\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n\n\n\n<p>\u9875\u7709<\/p>\n\n\n\n<p>\u9875\u811a<\/p>\n\n\n\n<p>\u81f3\u4e8e\u4e00\u4e9bExcel\u7279\u6b8a\u5b57\u7b26\uff0c\u6bd4\u5982\u8bf4\u9875\u7801\u53ef\u4ee5\u7528&amp;P\uff0c\u5f53\u524d\u65e5\u671f\u53ef\u4ee5\u7528&amp;D\uff0c\u5176\u4ed6\u7684\u4e1c\u897f\u4f60\u5c31\u81ea\u5df1\u7814\u7a76\u5427\u3002<\/p>\n\n\n\n<p>\u672c\u8303\u4f8b\u5b8c\u6574\u4ee3\u7801\u8bf7\u89c1NPOI.Examples\u4e2d\u7684CreateHeaderFooterInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/27\/1422734.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.1&nbsp;\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5728Excel\u4e2d\u6211\u4eec\u7ecf\u5e38\u8981\u8bbe\u7f6e\u683c\u5f0f\uff0c\u6bd4\u5982\u8bf4\u65e5\u671f\u683c\u5f0f\uff08yyyymmdd\uff09\u3001\u5c0f\u6570\u70b9\u683c\u5f0f\uff081.20\uff09\u3001\u8d27\u5e01\u683c\u5f0f\uff08$2000\uff09\u3001\u767e\u5206\u6bd4\u683c\u5f0f\uff0899.99%\uff09\u7b49\u7b49\uff0c\u8fd9\u4e9b\u4e1c\u897f\u5728\u8fc7\u53bb\u6211\u4eec\u6050\u6015\u53ea\u80fd\u5728\u670d\u52a1\u5668\u7aef\u751f\u6210\u597d\uff0c\u4e0d\u4f46\u589e\u52a0\u4e86\u670d\u52a1\u5668\u7aef\u7684\u4ee3\u7801\u91cf\uff0c\u8fd8\u9020\u6210\u4e86\u4e0d\u5fc5\u8981\u7684\u5b57\u7b26\u4e32\u66ff\u6362\u64cd\u4f5c\uff0c\u5982\u4ecaNPOI\u5c06\u8ba9\u670d\u52a1\u5668\u4ece\u8fd9\u79cd\u5b8c\u5168\u6ca1\u6709\u5fc5\u8981\u7684\u64cd\u4f5c\u4e2d\u89e3\u653e\u51fa\u6765\uff0c\u4e00\u5207\u90fd\u5c06\u7531Excel\u5728\u5ba2\u6237\u7aef\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528NPOI\u65f6\u8981\u6ce8\u610f\uff0c\u6240\u6709\u7684\u683c\u5f0f\u90fd\u662f\u901a\u8fc7CellStyle.DataFormat\u8d4b\u7ed9\u5355\u5143\u683c\u7684\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u8d4b\u7ed9\u5355\u5143\u683c\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u4e00&nbsp;\u65e5\u671f\u683c\u5f0f<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u9700\u8981\u663e\u793a\u7684\u65e5\u671f\u7684\u683c\u5f0f\u4e3a2008\u5e745\u67085\u65e5\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u751f\u6210\uff1a<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.CreateSheet(&#8220;newsheet&#8221;);<\/p>\n\n\n\n<p>HSSFCell cell= sheet.CreateRow(0).CreateCell(0);<\/p>\n\n\n\n<p>cell.SetCellValue(newDateTime(2008,5,5));<\/p>\n\n\n\n<p>\/\/set dateformat<\/p>\n\n\n\n<p>HSSFCellStylecellStyle = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>HSSFDataFormatformat = hssfworkbook.CreateDataFormat();<\/p>\n\n\n\n<p>cellStyle.DataFormat= format.GetFormat(&#8220;yyyy\u5e74m\u6708d\u65e5&#8221;);<\/p>\n\n\n\n<p>cell.CellStyle=cellStyle;<\/p>\n\n\n\n<p>\u7531\u4e8e\u8fd9\u91cc\u7684\u201cyyyy\u5e74m\u6708d\u65e5\u201d\u5c5e\u4e8e\u81ea\u5b9a\u4e49\u683c\u5f0f\uff08\u533a\u522b\u4e8eExcel\u5185\u5d4c\u7684\u683c\u5f0f\uff09\uff0c\u6240\u4ee5\u5fc5\u987b\u7528hssfworkbook.CreateDataFormat()\u521b\u5efa\u4e00\u4e2aHSSFDataFormat\u5b9e\u4f8b\uff0c\u7136\u540e\u4f7f\u7528format.GetFormat\u6765\u83b7\u53d6\u76f8\u5e94\u7684\u683c\u5f0f\uff0c\u53ea\u8981\u662fExcel\u652f\u6301\u7684\u683c\u5f0f\u8868\u793a\u65b9\u5f0f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u90fd\u80fd\u591f\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u4e8c\u4fdd\u75592\u4f4d\u5c0f\u6570<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e2a\u5355\u5143\u683c\u7684\u503c\u4e3a1.2\uff0c\u600e\u4e48\u663e\u793a\u62101.20\u5462\uff1f\u5728Excel\u4e2d\u53ef\u4ee5\u7528\u201c0.00\u201d\u6765\u8868\u793a\uff0c\u6240\u4ee5\u4e0b\u9762\u7684\u4ee3\u7801\u5c31\u80fd\u5b8c\u6210\uff1a<\/p>\n\n\n\n<p>\/\/ Create arow and put some cells in it. Rows are 0 based.<\/p>\n\n\n\n<p>HSSFCell cell= sheet.CreateRow(0).CreateCell(0);<\/p>\n\n\n\n<p>\/\/set valuefor the cell<\/p>\n\n\n\n<p>cell.SetCellValue(1.2);<\/p>\n\n\n\n<p>\/\/numberformat with 2 digits after the decimal point &#8211; &#8220;1.20&#8221;<\/p>\n\n\n\n<p>HSSFCellStylecellStyle = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>cellStyle.DataFormat= HSSFDataFormat.GetBuiltinFormat(&#8220;0.00&#8221;);<\/p>\n\n\n\n<p>cell.CellStyle= cellStyle;<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4e0e\u4e0a\u9762\u6709\u6240\u4e0d\u540c\uff0c\u7528\u7684\u662fHSSFDataFormat.GetBuiltinFormat()\u65b9\u6cd5\uff0c\u4e4b\u6240\u4ee5\u7528\u8fd9\u4e2a\uff0c\u662f\u56e0\u4e3a0.00\u662fExcel\u5185\u5d4c\u7684\u683c\u5f0f\uff0c\u5b8c\u6574\u7684Excel\u5185\u5d4c\u683c\u5f0f\u5217\u8868\u5927\u5bb6\u53ef\u4ee5\u770b\u8fd9\u4e2a\u7a97\u53e3\u4e2d\u7684\u81ea\u5b9a\u4e49\u5217\u8868\uff1a<\/p>\n\n\n\n<p>\u8fd9\u91cc\u5c31\u4e0d\u4e00\u4e00\u5217\u51fa\u4e86\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u4e09\u8d27\u5e01\u683c\u5f0f<\/p>\n\n\n\n<p>\u8d27\u5e01\u683c\u5f0f\u5728\u91d1\u878d\u7684\u9879\u76ee\u4e2d\u7ecf\u5e38\u7528\u5230\uff0c\u6bd4\u5982\u8bf4\u4eba\u6c11\u5e01\u7b26\u53f7\u00a5\uff0c\u7f8e\u5143\u7b26\u53f7$\u7b49\uff0c\u8fd9\u91cc\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u8868\u793a\uff1a<\/p>\n\n\n\n<p>HSSFCellcell2 = sheet.CreateRow(1).CreateCell(0);<\/p>\n\n\n\n<p>cell2.SetCellValue(20000);<\/p>\n\n\n\n<p>HSSFCellStylecellStyle2 = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>HSSFDataFormatformat = hssfworkbook.CreateDataFormat();<\/p>\n\n\n\n<p>cellStyle2.DataFormat= format.GetFormat(&#8220;\u00a5#,##0&#8221;);<\/p>\n\n\n\n<p>cell2.CellStyle= cellStyle2;<\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u8fd8\u52a0\u5165\u4e86\u5343\u5206\u4f4d\u5206\u9694\u7b26\uff0c\u6240\u4ee5\u662f#,##\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5199\uff0c\u4f60\u5f97\u53bb\u95ee\u5fae\u8f6f\uff0c\u5475\u5475\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u56db\u767e\u5206\u6bd4<\/p>\n\n\n\n<p>\u767e\u5206\u6bd4\u5728\u62a5\u8868\u4e2d\u4e5f\u5f88\u5e38\u7528\uff0c\u5176\u5b9e\u57fa\u672c\u4e0a\u548c\u4e0a\u9762\u4e00\u6837\uff0c\u53ea\u662f\u683c\u5f0f\u8868\u793a\u662f0.00%\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>cellStyle4.DataFormat= HSSFDataFormat.GetBuiltinFormat(&#8220;0.00%&#8221;);<\/p>\n\n\n\n<p>\u7531\u4e8e\u8fd9\u91cc\u662f\u5185\u5d4c\u683c\u5f0f\uff0c\u6240\u4ee5\u76f4\u63a5\u7528HSSFDataFormat.GetBuiltinFormat\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u4e94\u4e2d\u6587\u5927\u5199<\/p>\n\n\n\n<p>\u5728\u8868\u793a\u91d1\u989d\u65f6\uff0c\u6211\u4eec\u65f6\u5e38\u4f1a\u7528\u5230\uff0c\u6211\u4e5f\u89c1\u8fc7\u4e0d\u5c11\u5144\u5f1f\u5b9e\u73b0\u4e86\u6570\u5b57\u8f6c\u4e2d\u6587\u5927\u5c0f\u5199\u7684\u5de5\u5177\u7c7b\uff0c\u4ee5\u540e\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u8ba9Excel\u53bb\u5904\u7406\u8fd9\u4e00\u5207\uff0c\u4ee3\u7801\u548c\u521a\u624d\u5dee\u4e0d\u591a\uff0c\u4e5f\u662f\u6539\u683c\u5f0f\u7684\u8868\u793a\uff1a<\/p>\n\n\n\n<p>HSSFDataFormatformat = hssfworkbook.CreateDataFormat();<\/p>\n\n\n\n<p>cellStyle6.DataFormat= format.GetFormat(&#8220;[DbNum2][$-804]0&#8221;);<\/p>\n\n\n\n<p>\u7531\u4e8e\u662f\u81ea\u5b9a\u4e49\u683c\u5f0f\uff0c\u6240\u4ee5\u7528\u4e86HSSFDataFormat.GetFormat\uff0c\u76f8\u4fe1\u4f60\u5bf9\u8fd9\u4e24\u79cd\u83b7\u53d6\u683c\u5f0f\u7684\u5f62\u5f0f\u7684\u533a\u522b\u8d8a\u6765\u8d8a\u719f\u6089\u4e86\u3002<\/p>\n\n\n\n<p>\u6848\u4f8b\u516d\u79d1\u5b66\u8ba1\u6570\u6cd5<\/p>\n\n\n\n<p>\u8fd9\u4e1c\u897f\u6570\u5b66\u8bfe\u4e0a\u6211\u4eec\u90fd\u5b66\u8fc7\uff0c\u867d\u7136\u7528\u7684\u4e0d\u591a\uff0c\u4f46\u662f\u65e2\u7136Excel\u652f\u6301\uff0c\u8fd9\u91cc\u4e5f\u63d0\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<p>cellStyle3.DataFormat= HSSFDataFormat.GetBuiltinFormat(&#8220;0.00E+00&#8221;);<\/p>\n\n\n\n<p>\u4e0b\u9762\u5c55\u793a\u4e0b\u4ee5\u4e0a\u8fd9\u4e9b\u4f8b\u5b50\u7684\u663e\u793a\u6548\u679c\uff1a<\/p>\n\n\n\n<p>\u6700\u540e\u603b\u7ed3\u4e00\u4e0bHSSFDataFormat.GetFormat\u548cHSSFDataFormat.GetBuiltinFormat\u7684\u533a\u522b\uff1a<\/p>\n\n\n\n<p>\u5f53\u4f7f\u7528Excel\u5185\u5d4c\u7684\uff08\u6216\u8005\u8bf4\u9884\u5b9a\u4e49\uff09\u7684\u683c\u5f0f\u65f6\uff0c\u76f4\u63a5\u7528HSSFDataFormat.GetBuiltinFormat\u9759\u6001\u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5f53\u4f7f\u7528\u81ea\u5df1\u5b9a\u4e49\u7684\u683c\u5f0f\u65f6\uff0c\u5fc5\u987b\u5148\u8c03\u7528HSSFWorkbook.CreateDataFormat()\uff0c\u56e0\u4e3a\u8fd9\u65f6\u5728\u5e95\u5c42\u4f1a\u5148\u627e\u6709\u6ca1\u6709\u5339\u914d\u7684\u5185\u5d4cFormatRecord\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u4f1a\u65b0\u5efa\u4e00\u4e2aFormatRecord\uff0c\u6240\u4ee5\u5fc5\u987b\u5148\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u7136\u540e\u4f60\u5c31\u53ef\u4ee5\u7528\u83b7\u5f97\u7684HSSFDataFormat\u5b9e\u4f8b\u7684GetFormat\u65b9\u6cd5\u4e86\uff0c\u5f53\u7136\u76f8\u5bf9\u800c\u8a00\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u9ebb\u70e6\uff0c\u6240\u4ee5\u5185\u5d4c\u683c\u5f0f\u8fd8\u662f\u7528HSSFDataFormat.GetBuiltinFormat\u9759\u6001\u65b9\u6cd5\u66f4\u52a0\u76f4\u63a5\u4e00\u4e9b\u3002\u4e0d\u8fc7\u81ea\u5b9a\u4e49\u7684\u683c\u5f0f\u4e5f\u4e0d\u662f\u5929\u9a6c\u884c\u7a7a\u968f\u4fbf\u5b9a\u4e49\uff0c\u8fd8\u662f\u8981\u53c2\u7167Excel\u7684\u683c\u5f0f\u8868\u793a\u6765\u5b9a\u4e49\uff0c\u5177\u4f53\u8bf7\u770b\u76f8\u5173\u7684Excel\u6559\u7a0b\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u81ea\u5b9a\u4e49\u7684FormatRecord\u662f\u5d4c\u5165xls\u6587\u4ef6\u5185\u90e8\u7684\uff0c\u6240\u4ee5\u4e0d\u7528\u62c5\u5fc3\u5bf9\u65b9Excel\u4e2d\u6709\u6ca1\u6709\u5b9a\u4e49\u8fc7\u8fd9\u79cd\u683c\u5f0f\uff0c\u90fd\u662f\u80fd\u591f\u6b63\u5e38\u4f7f\u7528\u7684\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684NumberFormatInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/31\/1425376.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.2&nbsp;\u5355\u5143\u683c\u5408\u5e76<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5408\u5e76\u5355\u5143\u683c\u5728\u5236\u4f5c\u8868\u683c\u65f6\u5f88\u6709\u7528\uff0c\u6bd4\u5982\u8bf4\u8868\u683c\u7684\u6807\u9898\u5c31\u7ecf\u5e38\u662f\u628a\u7b2c\u4e00\u884c\u7684\u5355\u5143\u683c\u5408\u5e76\u5c45\u4e2d\u3002\u90a3\u4e48\u5728NPOI\u4e2d\u5e94\u8be5\u5982\u4f55\u5b9e\u73b0\u5355\u5143\u683c\u7684\u5408\u5e76\u5462\uff1f<\/p>\n\n\n\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\uff0cNPOI\u5f15\u5165\u4e86\u65b0\u7684\u6982\u5ff5\uff0c\u5373Region\uff0c\u56e0\u4e3a\u5408\u5e76\u5355\u5143\u683c\uff0c\u5176\u5b9e\u5c31\u662f\u8bbe\u5b9a\u4e00\u4e2a\u533a\u57df\u3002\u4e0b\u9762\u8bf4\u4e00\u4e0bRegion\u7c7b\u7684\u53c2\u6570\uff0cRegion\u603b\u5171\u67094\u4e2a\u53c2\u6570\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>Region\u7684\u53c2\u6570<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td>FirstRow<\/td><td>\u533a\u57df\u4e2d\u7b2c\u4e00\u4e2a\u5355\u5143\u683c\u7684\u884c\u53f7<\/td><\/tr><tr><td>FirstColumn<\/td><td>\u533a\u57df\u4e2d\u7b2c\u4e00\u4e2a\u5355\u5143\u683c\u7684\u5217\u53f7<\/td><\/tr><tr><td>LastRow<\/td><td>\u533a\u57df\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u5143\u683c\u7684\u884c\u53f7<\/td><\/tr><tr><td>LastColumn<\/td><td>\u533a\u57df\u4e2d\u6700\u540e\u4e00\u4e2a\u5355\u5143\u683c\u7684\u5217\u53f7<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u7531\u4e8e\u5355\u5143\u683c\u7684\u5408\u5e76\u90fd\u662f\u5728\u8868\u7684\u57fa\u7840\u4e0a\u5efa\u7acb\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u5f97\u5148\u5efaSheet\uff1a<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.CreateSheet(&#8220;newsheet&#8221;);<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6839\u636e\u5b9e\u9645\u573a\u666f\u6765\u505a\u4e00\u4e9b\u6f14\u793a\u3002<\/p>\n\n\n\n<p>\u573a\u666f\u4e00\u6807\u9898\u884c\u7684\u5408\u5e76<\/p>\n\n\n\n<p>\u8fd9\u79cd\u573a\u666f\u662f\u6700\u5e38\u89c1\u7684\uff0c\u6bd4\u5982\u8bf4\u6211\u4eec\u8981\u5efa\u7acb\u4e00\u5f20\u9500\u552e\u60c5\u51b5\u8868\uff0c\u82f1\u6587\u53ebSales Report<\/p>\n\n\n\n<p>\u6211\u4eec\u5148\u8bbe\u7f6e\u5c45\u4e2d\u548c\u5b57\u4f53\u6837\u5f0f\uff0c\u8fd9\u91cc\u6211\u4eec\u91c7\u752820\u53f7\u5b57\u4f53\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFRow row =sheet.CreateRow(0);<\/p>\n\n\n\n<p>HSSFCell cell= row.CreateCell(0);<\/p>\n\n\n\n<p>cell.SetCellValue(&#8220;Sales Report&#8221;);<\/p>\n\n\n\n<p>HSSFCellStylestyle = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_CENTER;<\/p>\n\n\n\n<p>HSSFFont font= hssfworkbook.CreateFont();<\/p>\n\n\n\n<p>font.FontHeight= 20*20;<\/p>\n\n\n\n<p>style.SetFont(font);<\/p>\n\n\n\n<p>cell.CellStyle= style;<\/p>\n\n\n\n<p>\u8981\u4ea7\u751f\u56fe\u4e2d\u7684\u6548\u679c\uff0c\u5373\u628aA1:F1\u8fd96\u4e2a\u5355\u5143\u683c\u5408\u5e76\uff0c\u7136\u540e\u6dfb\u52a0\u5408\u5e76\u533a\u57df\uff1a<\/p>\n\n\n\n<p>sheet.AddMergedRegion(new&nbsp;Region(0, 0, 0,5));<\/p>\n\n\n\n<p>\u573a\u666f\u4e8c\u591a\u884c\u5408\u5e76<\/p>\n\n\n\n<p>\u770b\u5b8c\u573a\u666f\u4e00\uff0c\u4f60\u53ef\u4e0d\u8981\u8ba4\u4e3a\u591a\u884c\u5408\u5e76\u5c31\u9700\u8981\u4e00\u884c\u4e00\u884c\u505a\uff0c\u5176\u5b9e\u4e5f\u53ea\u9700\u8981\u4e00\u884c\u4ee3\u7801\uff0c\u6bd4\u5982\u8bf4\u6211\u4eec\u8981\u628aC3:E5\u5408\u5e76\u4e3a\u4e00\u4e2a\u5355\u5143\u683c\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>sheet.AddMergedRegion(new&nbsp;Region(2, 2, 4,4));<\/p>\n\n\n\n<p>\u63d0\u793a\u5373\u4f7f\u4f60\u6ca1\u6709\u7528CreateRow\u548cCreateCell\u521b\u5efa\u8fc7\u884c\u6216\u5355\u5143\u683c\uff0c\u4e5f\u5b8c\u5168\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa\u533a\u57df\u7136\u540e\u628a\u8fd9\u4e00\u533a\u57df\u5408\u5e76\uff0cExcel\u7684\u533a\u57df\u5408\u5e76\u4fe1\u606f\u662f\u5355\u72ec\u5b58\u50a8\u7684\uff0c\u548cRowRecord\u3001ColumnInfoRecord\u4e0d\u5b58\u5728\u76f4\u63a5\u5173\u7cfb\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684MergedCellInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/01\/1426732.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.3&nbsp;\u5355\u5143\u683c\u5bf9\u9f50\u76f8\u5173\u8bbe\u7f6e<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u672c\u8282\u5c06\u56f4\u7ed5\u201c\u5bf9\u9f50\u201d\u9009\u9879\u5361\u4e2d\u7684\u8bbe\u7f6e\u5c55\u5f00\uff0c\u867d\u7136\u5b9e\u9645\u4e0a\u4f60\u4f1a\u53d1\u73b0\u8be5\u9009\u9879\u5361\u4e2d\u7684\u5f88\u591a\u8bbe\u7f6e\u548c\u5bf9\u9f50\u6ca1\u6709\u4ec0\u4e48\u5173\u7cfb\u3002\u5408\u5e76\u5355\u5143\u683c\u5df2\u7ecf\u5728<a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/03\/30\/1425376.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.2.2\u8282<\/a>\u8bb2\u8fc7\u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u63d0\u4e86\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u7528\u4ee3\u7801\u521b\u5efa\u5fc5\u8981\u7684\u5355\u5143\u683c\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =new&nbsp;HSSFWorkbook();<\/p>\n\n\n\n<p>HSSFSheetsheet1 = hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>HSSFRow row =sheet1.CreateRow(0);<\/p>\n\n\n\n<p>row.CreateCell(0).SetCellValue(&#8220;Test&#8221;);<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u4eec\u5047\u8bbe\u5728A0\u5355\u5143\u683c\u4e2d\u52a0\u5165\u4e86\u6587\u672cTest\u3002<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u505a\u7684\u6240\u6709\u64cd\u4f5c\u90fd\u662f\u5728CellStyle\u7684\u57fa\u7840\u4e0a\u5b8c\u6210\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u521b\u5efa\u4e00\u4e2aHSSFCellStyle\uff1a<\/p>\n\n\n\n<p>HSSFCellStylestyle=hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>\u6c34\u5e73\u5bf9\u9f50<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7528\u7684\u662fHSSFCellStyle.Alignment\uff0c\u9ed8\u8ba4\u503c\u81ea\u7136\u662f\u5e38\u89c4\uff0c\u5373HSSFCellStyle.ALIGN_GENERAL\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u5de6\u4fa7\u5bf9\u9f50\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_LEFT;<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u5c45\u4e2d\u5bf9\u9f50\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_CENTER;<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u53f3\u4fa7\u5bf9\u9f50\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_RIGHT;<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u8de8\u5217\u4e3e\u4e2d\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_CENTER_SELECTION;<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u4e24\u7aef\u5bf9\u9f50\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_JUSTIFY;<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u586b\u5145\u5c31\u662f<\/p>\n\n\n\n<p>style.Alignment= HSSFCellStyle.ALIGN_FILL;<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u4ee5\u4e0a\u9009\u9879\u4ec5\u5f53\u6709\u8db3\u591f\u7684\u5bbd\u5ea6\u65f6\u624d\u80fd\u4ea7\u751f\u6548\u679c\uff0c\u4e0d\u8bbe\u7f6e\u5bbd\u5ea6\u6050\u6015\u770b\u4e0d\u51fa\u533a\u522b\u3002<\/p>\n\n\n\n<p>\u5782\u76f4\u5bf9\u9f50<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7528\u7684\u662fHSSFCellStyle.VerticalAlignment\uff0c\u9ed8\u8ba4\u503c\u4e3a\u5c45\u4e2d\uff0c\u5373HSSFCellStyle.VERTICAL_CENTER<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u9760\u4e0a\u5c31\u662f<\/p>\n\n\n\n<p>style.VerticalAlignment=HSSFCellStyle.VERTICAL_TOP<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u5c45\u4e2d\u5c31\u662f<\/p>\n\n\n\n<p>style.VerticalAlignment=HSSFCellStyle.VERTICAL_CENTER<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u9760\u4e0b\u5c31\u662f<\/p>\n\n\n\n<p>style.VerticalAlignment=HSSFCellStyle.VERTICAL_BOTTOM<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u4e24\u7aef\u5bf9\u9f50\u5c31\u662f<\/p>\n\n\n\n<p>style.VerticalAlignment=HSSFCellStyle.VERTICAL_JUSTIFY<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u4ee5\u4e0a\u9009\u9879\u4ec5\u5f53\u6709\u8db3\u591f\u7684\u9ad8\u5ea6\u65f6\u624d\u80fd\u4ea7\u751f\u6548\u679c\uff0c\u4e0d\u8bbe\u7f6e\u9ad8\u5ea6\u6050\u6015\u770b\u4e0d\u51fa\u533a\u522b\u3002<\/p>\n\n\n\n<p>\u81ea\u52a8\u6362\u884c<\/p>\n\n\n\n<p>\u81ea\u52a8\u6362\u884c\u7ffb\u8bd1\u6210\u82f1\u6587\u5176\u5b9e\u5c31\u662fWrap\u7684\u610f\u601d\uff0c\u6240\u4ee5\u8fd9\u91cc\u6211\u4eec\u5e94\u8be5\u7528WrapText\u5c5e\u6027\uff0c\u8fd9\u662f\u4e00\u4e2a\u5e03\u5c14\u5c5e\u6027<\/p>\n\n\n\n<p>style.WrapText=true;<\/p>\n\n\n\n<p>\u6548\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>\u6587\u672c\u7f29\u8fdb<\/p>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u4e0d\u592a\u5f15\u4eba\u6ce8\u610f\u7684\u9009\u9879\uff0c\u6240\u4ee5\u8fd9\u91cc\u7ed9\u5f20\u56fe\u51fa\u6765\uff0c\u8ba9\u5927\u5bb6\u77e5\u9053\u662f\u4ec0\u4e48\uff0c\u7f29\u8fdb\u8bf4\u767d\u4e86\u5c31\u662f\u6587\u672c\u524d\u9762\u7684\u7a7a\u767d\uff0c\u6211\u4eec\u540c\u6837\u53ef\u4ee5\u7528\u5c5e\u6027\u6765\u8bbe\u7f6e\uff0c\u8fd9\u4e2a\u5c5e\u6027\u53eb\u505aIndention\u3002<\/p>\n\n\n\n<p>style.Indention= 3;<\/p>\n\n\n\n<p>\u6587\u672c\u65cb\u8f6c<\/p>\n\n\n\n<p>\u6587\u672c\u65b9\u5411\u5927\u5bb6\u4e00\u5b9a\u5728Excel\u4e2d\u8bbe\u7f6e\u8fc7\uff0c\u4e0a\u56fe\u4e2d\u5c31\u662f\u8c03\u6574\u754c\u9762\uff0c\u4e3b\u8981\u53c2\u6570\u662f\u5ea6\u6570\uff0c\u90a3\u4e48\u6211\u4eec\u5982\u4f55\u5728NPOI\u4e2d\u8bbe\u7f6e\u5462\uff1f<\/p>\n\n\n\n<p>style.Rotation=(short)90;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u662f\u628a\u5355\u5143\u683cA1\u4e2d\u7684\u6587\u672c\u9006\u65f6\u9488\u65cb\u8f6c90\u5ea6\uff0c\u7b49\u540c\u4e8e\u4e0b\u56fe\u4e2d\u7684\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684Rotation\u53d6\u503c\u662f\u4ece-90\u523090\uff0c\u800c\u4e0d\u662f0-180\u5ea6\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u522b\u5fd8\u4e86\u628a\u6837\u5f0f\u53d8\u91cfstyle\u8d4b\u7ed9HSSFCellStyle.CellStyle\uff0c\u5426\u5219\u5c31\u524d\u529f\u5c3d\u5f03\u4e86\uff0c\u5475\u5475\uff01<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u7684\u4e00\u4e9b\u529f\u80fd\uff0c\u6bd4\u5982\u6587\u672c\u65cb\u8f6c\u548c\u81ea\u52a8\u6362\u884c\uff0c\u4f7f\u7528\u4f20\u7edf\u7684cvs\u548chtml\u6cd5\u6050\u6015\u662f\u65e0\u6cd5\u5b9e\u73b0\u7684\u3002\u968f\u7740\u5b66\u4e60\u7684\u4e0d\u65ad\u6df1\u5165\uff0c\u4f60\u5c06\u8d8a\u6765\u8d8a\u610f\u8bc6\u5230\u4f7f\u7528NPOI\u751f\u6210Excel\u5176\u5b9e\u5982\u6b64\u7b80\u5355\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684SetAlignmentInXls\u548cRotateTextInXls\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/06\/1429376.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.4&nbsp;\u8bbe\u7f6e\u5355\u5143\u683c\u8fb9\u6846<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5f88\u591a\u8868\u683c\u4e2d\u90fd\u8981\u4f7f\u7528\u8fb9\u6846\uff0c\u672c\u8282\u5c06\u4e3a\u4f60\u91cd\u70b9\u8bb2\u89e3NPOI\u4e2d\u8fb9\u6846\u7684\u8bbe\u7f6e\u548c\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u8fb9\u6846\u548c\u5176\u4ed6\u5355\u5143\u683c\u8bbe\u7f6e\u4e00\u6837\u4e5f\u662f\u5728HSSFCellStyle\u4e0a\u64cd\u4f5c\u7684\uff0cHSSFCellStyle\u67092\u79cd\u548c\u8fb9\u6846\u76f8\u5173\u7684\u5c5e\u6027\uff0c\u5206\u522b\u662f:<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u8fb9\u6846\u76f8\u5173\u5c5e\u6027<\/td><td>\u8bf4\u660e<\/td><td>\u8303\u4f8b<\/td><\/tr><tr><td>Border+\u65b9\u5411<\/td><td>\u8fb9\u6846\u7c7b\u578b<\/td><td>BorderTop, BorderBottom,BorderLeft, BorderRight<\/td><\/tr><tr><td>\u65b9\u5411+BorderColor<\/td><td>\u8fb9\u6846\u989c\u8272<\/td><td>TopBorderColor,BottomBorderColor, LeftBorderColor, RightBorderColor<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u5176\u4e2d\u8fb9\u6846\u7c7b\u578b\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u8fb9\u6846\u8303\u4f8b\u56fe<\/td><td>\u5bf9\u5e94\u7684\u9759\u6001\u503c<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_DOTTED<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_HAIR<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_DASH_DOT_DOT<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_DASH_DOT<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_DASHED<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_THIN<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_MEDIUM_DASH_DOT_DOT<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_SLANTED_DASH_DOT<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_MEDIUM_DASH_DOT<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_MEDIUM_DASHED<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_MEDIUM<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_THICK<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BORDER_DOUBLE<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u81f3\u4e8e\u989c\u8272\u90a3\u5c31\u5f88\u591a\u4e86\uff0c\u5168\u90e8\u5728HSSFColor\u4e0b\u9762\uff0c\u5982HSSFColor.GREEN,HSSFColor.RED\uff0c\u90fd\u662f\u9759\u6001\u5b9e\u4f8b\uff0c\u53ef\u4ee5\u76f4\u63a5\u5f15\u7528\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u5047\u8bbe\u6211\u4eec\u8981\u628a\u4e00\u4e2a\u5355\u5143\u683c\u7684\u56db\u5468\u8fb9\u6846\u90fd\u8bbe\u7f6e\u4e0a\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.CreateSheet(&#8220;newsheet&#8221;);<\/p>\n\n\n\n<p>\/\/ Create arow and put some cells in it. Rows are 0 based.<\/p>\n\n\n\n<p>HSSFRow row =sheet.CreateRow(1);<\/p>\n\n\n\n<p>\/\/ Create acell and put a value in it.<\/p>\n\n\n\n<p>HSSFCell cell= row.CreateCell(1);<\/p>\n\n\n\n<p>\/\/ Style thecell with borders all around.<\/p>\n\n\n\n<p>HSSFCellStylestyle = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>style.BorderBottom=HSSFCellStyle.BORDER_THIN;<\/p>\n\n\n\n<p>style.BorderLeft=HSSFCellStyle.BORDER_THIN;<\/p>\n\n\n\n<p>style.BorderRight=HSSFCellStyle.BORDER_THIN;<\/p>\n\n\n\n<p>style.BorderTop= HSSFCellStyle.BORDER_THIN ;<\/p>\n\n\n\n<p>cell.CellStyle=style;<\/p>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f7f\u7528\u4e86\u6700\u666e\u901a\u7684\u7ec6\u8fb9\u6846\uff0c\u4f7f\u5f97\u8fd9\u4e2a\u5355\u5143\u683c\u770b\u4e0a\u53bb\u50cf\u5757\u7a7a\u5fc3\u7816\u5934\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u8fd9\u91cc\u6211\u4eec\u6ca1\u6709\u8bbe\u7f6e\u8fb9\u6846\u7684\u989c\u8272\uff0c\u4f46\u8fd9\u4e0d\u4f1a\u5f71\u54cd\u6700\u7ec8\u7684\u6548\u679c\uff0c\u56e0\u4e3aExcel\u4f1a\u7528\u9ed8\u8ba4\u7684\u9ed1\u8272\u7ed9\u8fb9\u6846\u4e0a\u8272\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u8bbe\u7f6e\u989c\u8272\u7684\u8bdd\uff0c\u4e5f\u5f88\u7b80\u5355\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>style.BottomBorderColor=HSSFColor.GREEN.index;<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c06\u5e95\u90e8\u8fb9\u6846\u8bbe\u7f6e\u4e3a\u7eff\u8272\uff0c\u8981\u6ce8\u610f\uff0c\u4e0d\u662f\u76f4\u63a5\u628aHSSFColor.GREEN\u8d4b\u7ed9XXXXBorderColor\u5c5e\u6027\uff0c\u800c\u662f\u628aindex\u7684\u503c\u8d4b\u7ed9\u5b83\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684SetBorderStyleInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/08\/1429499.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.5&nbsp;\u8bbe\u7f6e\u5355\u5143\u683c\u5b57\u4f53<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u672c\u8282\u6211\u4eec\u5c06\u7ee7\u7eed\u4f7f\u7528NPOI\u6765\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f\uff0c\u8fd9\u4e00\u8282\u6211\u4eec\u4e3b\u8981\u8bb2\u5982\u4f55\u8bbe\u7f6e\u201c\u5b57\u4f53\u201d\u3002<\/p>\n\n\n\n<p>\u5728\u8bbe\u7f6e\u5b57\u4f53\u4e4b\u524d\uff0c\u6211\u4eec\u9996\u5148\u8981\u505a\u7684\u5c31\u662f\u521b\u5efa\u5b57\u4f53\u5bf9\u8c61\uff0c\u8fd9\u548c\u521b\u5efa\u6570\u5b57\u683c\u5f0f\u5f88\u76f8\u4f3c\u3002<\/p>\n\n\n\n<p>HSSFFont font= hssfworkbook.CreateFont();<\/p>\n\n\n\n<p>\u8fd9\u53e5\u8bdd\u4f1a\u5728Excel\u6587\u4ef6\u5185\u90e8\u521b\u5efa\u76f8\u5e94\u7684FontRecord\uff0c\u6240\u4ee5\u4f60\u4e0d\u7528\u5ba2\u6237\u56e0\u4e3a\u81ea\u5df1\u673a\u5668\u4e0a\u7684Excel\u6ca1\u6709\u76f8\u5e94\u7684\u5b57\u4f53\u8bbe\u7f6e\u800c\u5bfc\u81f4\u8bbe\u7f6e\u4e22\u5931\u3002<\/p>\n\n\n\n<p>\u5b57\u4f53\u5728\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u628a\u5b83\u8d4b\u7ed9\u5355\u5143\u683c\u6837\u5f0f\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFCellStylestyle1 = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>style1.SetFont(font);<\/p>\n\n\n\n<p>cell1.CellStyle=style1;<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684cell1\u662fHSSFCell\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u5f00\u59cb\u5bf9\u5b57\u4f53\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u5b57\u4f53\u540d\u79f0<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684\u5b57\u4f53\u540d\u79f0\u662f\u901a\u8fc7HSSFFont.FontName\u8fdb\u884c\u8bbe\u7f6e\u7684\uff0c\u81f3\u4e8e\u5177\u4f53\u7684\u540d\u79f0\uff0c\u53ea\u8981\u662f\u5e38\u7528\u5b57\u4f53\u90fd\u53ef\u4ee5\uff0c\u6bd4\u5982\u8bf4Arial, Verdana\u7b49\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u662f\u4e2d\u6587\u5b57\u4f53\u540d\uff0c\u5982\u5b8b\u4f53\u3001\u9ed1\u4f53\u7b49\u3002\u4e0d\u8fc7\u8bbe\u7f6e\u5b57\u4f53\u540d\u79f0\u6709\u4e2a\u524d\u63d0\uff0c\u90a3\u5c31\u662f\u5047\u8bbe\u6253\u5f00\u8fd9\u4e2axls\u6587\u4ef6\u7684\u5ba2\u6237\u673a\u4e0a\u6709\u8fd9\u79cd\u5b57\u4f53\uff0c\u5982\u679c\u6ca1\u6709\uff0cExcel\u5c06\u4f7f\u7528\u9ed8\u8ba4\u5b57\u4f53\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u5c31\u662f\u8bbe\u7f6e\u5b57\u4f53\u540d\u79f0\u4e3a\u201c\u5b8b\u4f53\u201d\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>font.FontName=&#8221;\u5b8b\u4f53&#8221;;<\/p>\n\n\n\n<p>\u5b57\u53f7<\/p>\n\n\n\n<p>\u4e0e\u5b57\u53f7\u6709\u5173\u7684\u5c5e\u6027\u6709\u4e24\u4e2a\uff0c\u4e00\u4e2a\u662fFontHeight\uff0c\u4e00\u4e2a\u662fFontHeightInPoints\u3002\u533a\u522b\u5728\u4e8e\uff0cFontHeight\u7684\u503c\u662fFontHeightInPoints\u768420\u500d\uff0c\u901a\u5e38\u6211\u4eec\u5728Excel\u754c\u9762\u4e2d\u770b\u5230\u7684\u5b57\u53f7\uff0c\u6bd4\u5982\u8bf412\uff0c\u5bf9\u5e94\u7684\u662fFontHeightInPoints\u7684\u503c\uff0c\u800cFontHeight\u8981\u4ea7\u751f12\u53f7\u5b57\u4f53\u7684\u5927\u5c0f\uff0c\u503c\u5e94\u8be5\u662f240\u3002\u6240\u4ee5\u901a\u5e38\u5efa\u8bae\u4f60\u7528FontHeightInPoint\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u8bbe\u7f6e\u5b57\u53f7\u4e3a12\uff0c\u4ee3\u7801\u5c31\u662f<\/p>\n\n\n\n<p>font.FontHeightInPoints= 12;<\/p>\n\n\n\n<p>\u5b57\u4f53\u989c\u8272<\/p>\n\n\n\n<p>\u8fd9\u91cc\u53ef\u80fd\u4f1a\u4e0eCellStyle\u4e0a\u7684ForegroundColor\u548cBackgroundColor\u4ea7\u751f\u6df7\u6dc6\uff0c\u5176\u5b9e\u6240\u6709\u7684\u5b57\u4f53\u989c\u8272\u90fd\u662f\u5728HSSFFont\u7684\u5b9e\u4f8b\u4e0a\u8bbe\u7f6e\u7684\uff0cCellStyle\u7684ForegroundColor\u548cBackgroundColor\u5206\u522b\u6307\u80cc\u666f\u586b\u5145\u8272\u548c\u586b\u5145\u56fe\u6848\u7684\u989c\u8272\uff0c\u548c\u6587\u672c\u989c\u8272\u65e0\u5173\u3002<\/p>\n\n\n\n<p>\u8981\u8bbe\u7f6e\u5b57\u4f53\u989c\u8272\uff0c\u6211\u4eec\u53ef\u4ee5\u7528HSSFFont.Color\u5c5e\u6027\uff0c\u989c\u8272\u53ef\u4ee5\u901a\u8fc7HSSFColor\u83b7\u5f97\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>font.Color =HSSFColor.RED.index;<\/p>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u628a\u6587\u672c\u8bbe\u7f6e\u4e3a\u7ea2\u8272\u3002<\/p>\n\n\n\n<p>\u4e0b\u5212\u7ebf<\/p>\n\n\n\n<p>\u901a\u5e38\u6211\u4eec\u6240\u8bf4\u7684\u4e0b\u5212\u7ebf\u90fd\u662f\u5355\u7ebf\u6761\u7684\uff0c\u5176\u5b9eExcel\u652f\u6301\u597d\u51e0\u79cd\u4e0b\u5212\u7ebf\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u7c7b\u578b<\/td><td>\u5bf9\u5e94\u7684\u503c<\/td><\/tr><tr><td>\u5355\u4e0b\u5212\u7ebf<\/td><td>HSSFFont.U_SINGLE<\/td><\/tr><tr><td>\u53cc\u4e0b\u5212\u7ebf<\/td><td>HSSFFont.U_DOUBLE<\/td><\/tr><tr><td>\u4f1a\u8ba1\u7528\u5355\u4e0b\u5212\u7ebf<\/td><td>HSSFFont.U_SINGLE_ACCOUNTING<\/td><\/tr><tr><td>\u4f1a\u8ba1\u7528\u53cc\u4e0b\u5212\u7ebf<\/td><td>HSSFFont.U_DOUBLE_ACCOUNTING<\/td><\/tr><tr><td>\u65e0\u4e0b\u5212\u7ebf<\/td><td>HSSFFont.U_NONE<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u5f53\u4f60\u8981\u8bbe\u7f6e\u4e0b\u5212\u7ebf\u65f6\uff0c\u53ef\u4ee5\u7528HSSFFont.Underline\u5c5e\u6027\uff0c\u8fd9\u662f\u4e00\u4e2abyte\u7c7b\u578b\u7684\u503c\uff0c\u4f8b\u5982<\/p>\n\n\n\n<p>font.Underline=HSSFFont.U_SINGLE<\/p>\n\n\n\n<p>\u8fd9\u884c\u4ee3\u7801\u5c31\u662f\u8bbe\u7f6e\u5355\u4e0b\u5212\u7ebf\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>\u4e0a\u6807\u4e0b\u6807<\/p>\n\n\n\n<p>\u8bbe\u7f6e\u8fd9\u4e1c\u897f\u53ef\u4ee5\u7528HSSFFont.TypeOffset\u5c5e\u6027\uff0c\u503c\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>TypeOffset\u7684\u503c<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td>HSSFFont.SS_SUPER<\/td><td>\u4e0a\u6807<\/td><\/tr><tr><td>HSSFFont.SS_SUB<\/td><td>\u4e0b\u6807<\/td><\/tr><tr><td>HSSFFont.SS_NONE<\/td><td>\u666e\u901a\uff0c\u9ed8\u8ba4\u503c<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u6240\u4ee5\u5982\u679c\u4f60\u8981\u4e0a\u6807\u7684\u8bdd\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>font.TypeOffset=HSSFFont.SS_SUPER;<\/p>\n\n\n\n<p>\u5220\u9664\u7ebf<\/p>\n\n\n\n<p>\u8bbe\u7f6e\u8fd9\u4e1c\u897f\u53ef\u4ee5\u7528HSSFFont.IsStrikeout\u5c5e\u6027\uff0c\u5f53\u4e3atrue\u65f6\uff0c\u8868\u793a\u6709\u5220\u9664\u7ebf\uff1b\u4e3afalse\u5219\u8868\u793a\u6ca1\u6709\u5220\u9664\u7ebf\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684ApplyFontInXls\u7684\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/09\/1432096.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.6\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u80cc\u666f\u548c\u56fe\u6848<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u672c\u8282\u6211\u4eec\u5c06\u7528NPOI\u6765\u4e3a\u5355\u5143\u683c\u6dfb\u52a0\u80cc\u666f\u548c\u56fe\u6848\u3002<\/p>\n\n\n\n<p>\u5728\u4e4b\u524d\u7684\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5df2\u7ecf\u63d0\u5230HSSFCellStyle\u6709\u4e24\u4e2a\u80cc\u666f\u989c\u8272\u5c5e\u6027\uff0c\u4e00\u4e2a\u53ebFillBackgroundColor\uff0c\u53e6\u4e00\u4e2a\u53ebFillForegroundColor\uff0c\u4f46\u5176\u5b9e\u8fd9\u6307\u7684\u90fd\u662f\u80cc\u666f\u989c\u8272\uff0c\u90a3\u4e3a\u4ec0\u4e48\u8fd8\u6709ForegroundColor\u5462\uff1f\u4e3a\u4e86\u80fd\u591f\u5e2e\u52a9\u5927\u5bb6\u7406\u89e3\uff0c\u6211\u4eec\u4e3e\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6848\u662fExcel\u7684\u4e00\u4e2a\u5355\u5143\u683c\uff1a<\/p>\n\n\n\n<p>\u7ebf\u662f\u767d\u8272\u7684\uff0c\u80cc\u666f\u662f\u7ea2\u8272\u7684\u3002\u8fd9\u91cc\u7684\u7ebf\u5176\u5b9e\u5c31\u662f\u4e0b\u9762\u7684Excel\u754c\u9762\u4e2d\u7684\u56fe\u6848\uff1a<\/p>\n\n\n\n<p>\u81f3\u4e8e\u7ebf\u7684\u989c\u8272\u5219\u662f\u56fe\u6848\u989c\u8272\uff0c\u5373\u767d\u8272\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u4ee5\u4e0a\u5355\u5143\u683c\u5982\u679c\u8981\u7528NPOI\u6765\u8bbe\u7f6e\u5c31\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4ee3\u7801\u5b8c\u6210\uff1a<\/p>\n\n\n\n<p>\/\/fillbackground<\/p>\n\n\n\n<p>HSSFCellStylestyle8 = hssfworkbook.CreateCellStyle();<\/p>\n\n\n\n<p>style8.FillForegroundColor= NPOI.HSSF.Util.HSSFColor.WHITE.index;<\/p>\n\n\n\n<p>style8.FillPattern= HSSFCellStyle.SQUARES;<\/p>\n\n\n\n<p>style8.FillBackgroundColor= NPOI.HSSF.Util.HSSFColor.RED.index;<\/p>\n\n\n\n<p>sheet1.CreateRow(7).CreateCell(0).CellStyle= style8;<\/p>\n\n\n\n<p>\u73b0\u5728\u662f\u4e0d\u662f\u6e05\u695a\u4e00\u4e9b\u4e86\uff0c\u8fd9\u91cc\u7684FillPattern\u5c31\u56fe\u6848\u6837\u5f0f\uff0c\u6240\u6709\u7684\u679a\u4e3e\u503c\u90fd\u662fHSSFCellStyle\u7684\u5e38\u91cf\uff1bFillForegroundColor\u5c31\u662f\u56fe\u6848\u7684\u989c\u8272\uff0c\u800cFillBackgroundColor\u5219\u662f\u80cc\u666f\u7684\u989c\u8272\uff0c\u5373\u7ea2\u8272\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u7f57\u5217\u4e00\u4e0b\u56fe\u6848\u6837\u5f0f\u53ca\u5176\u5bf9\u5e94\u7684\u503c\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u56fe\u6848\u6837\u5f0f<\/td><td>\u5e38\u91cf<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.NO_FILL<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.ALT_BARS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.FINE_DOTS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.SPARSE_DOTS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.LESS_DOTS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.LEAST_DOTS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BRICKS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.BIG_SPOTS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THICK_FORWARD_DIAG<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THICK_BACKWARD_DIAG<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THICK_VERT_BANDS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THICK_HORZ_BANDS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THIN_HORZ_BANDS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THIN_VERT_BANDS<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THIN_BACKWARD_DIAG<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.THIN_FORWARD_DIAG<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.SQUARES<\/td><\/tr><tr><td>&nbsp;<\/td><td>HSSFCellStyle.DIAMONDS<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u5f20\u8868\uff0c\u4f60\u5c06\u5f88\u5bb9\u6613\u627e\u5230\u81ea\u5df1\u9700\u8981\u7684\u6837\u5f0f\uff0c\u4e0d\u7528\u518d\u53bb\u4e00\u4e2a\u4e00\u4e2a\u731c\u6d4b\u4e86\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684ColorfullMatrixTable\u548cFillBackgroundInXls\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/12\/1434106.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.2.7&nbsp;\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u5728Excel\u4e2d\uff0c\u5355\u5143\u683c\u7684\u5bbd\u5ea6\u5176\u5b9e\u5c31\u662f\u5217\u7684\u5bbd\u5ea6\uff0c\u56e0\u4e3aExcel\u5047\u8bbe\u8fd9\u4e00\u5217\u7684\u5355\u5143\u683c\u7684\u5bbd\u5ea6\u80af\u5b9a\u4e00\u81f4\u3002\u6240\u4ee5\u8981\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u5bbd\u5ea6\uff0c\u6211\u4eec\u5c31\u5f97\u4ece\u5217\u7684\u5bbd\u5ea6\u4e0b\u624b\uff0cHSSFSheet\u6709\u4e2a\u65b9\u6cd5\u53ebSetColumnWidth\uff0c\u5171\u6709\u4e24\u4e2a\u53c2\u6570\uff1a\u4e00\u4e2a\u662f\u5217\u7684\u7d22\u5f15\uff08\u4ece0\u5f00\u59cb\uff09\uff0c\u4e00\u4e2a\u662f\u5bbd\u5ea6\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u5047\u8bbe\u4f60\u8981\u8bbe\u7f6eB\u5217\u7684\u5bbd\u5ea6\uff0c\u5c31\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>HSSFSheetsheet1 = hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>sheet1.SetColumnWidth(1,100 * 256);<\/p>\n\n\n\n<p>\u8fd9\u91cc\u4f60\u4f1a\u53d1\u73b0\u4e00\u4e2a\u6709\u8da3\u7684\u73b0\u8c61\uff0cSetColumnWidth\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8981\u4e58\u4ee5256\uff0c\u8fd9\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f\u5176\u5b9e\uff0c\u8fd9\u4e2a\u53c2\u6570\u7684\u5355\u4f4d\u662f1\/256\u4e2a\u5b57\u7b26\u5bbd\u5ea6\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u91cc\u662f\u628aB\u5217\u7684\u5bbd\u5ea6\u8bbe\u7f6e\u4e3a\u4e86100\u4e2a\u5b57\u7b26\u3002<\/p>\n\n\n\n<p>\u521a\u624d\u8bf4\u7684\u662f\u5982\u4f55\u8bbe\u7f6e\uff0c\u90a3\u5982\u4f55\u53bb\u8bfb\u53d6\u4e00\u4e2a\u5217\u7684\u5bbd\u5ea6\u5462\uff1f\u76f4\u63a5\u7528GetColumnWidth\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u53ea\u6709\u4e00\u4e2a\u53c2\u6570\uff0c\u90a3\u5c31\u662f\u5217\u7684\u7d22\u5f15\u53f7\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>int&nbsp;col1width = sheet1.GetColumnWidth(1);<\/p>\n\n\n\n<p>\u8bf4\u5b8c\u5bbd\u5ea6\uff0c\u6211\u4eec\u6765\u8bf4\u9ad8\u5ea6\uff0c\u5728Excel\u4e2d\uff0c\u6bcf\u4e00\u884c\u7684\u9ad8\u5ea6\u4e5f\u662f\u8981\u6c42\u4e00\u81f4\u7684\uff0c\u6240\u4ee5\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u9ad8\u5ea6\uff0c\u5176\u5b9e\u5c31\u662f\u8bbe\u7f6e\u884c\u7684\u9ad8\u5ea6\uff0c\u6240\u4ee5\u76f8\u5173\u7684\u5c5e\u6027\u4e5f\u5e94\u8be5\u5728HSSFRow\u4e0a\uff0c\u5b83\u5c31\u662fHSSFRow.Height\u548cHeightInPoints\uff0c\u8fd9\u4e24\u4e2a\u5c5e\u6027\u7684\u533a\u522b\u5728\u4e8eHeightInPoints\u7684\u5355\u4f4d\u662f\u70b9\uff0c\u800cHeight\u7684\u5355\u4f4d\u662f1\/20\u4e2a\u70b9\uff0c\u6240\u4ee5Height\u7684\u503c\u6c38\u8fdc\u662fHeightInPoints\u768420\u500d\u3002<\/p>\n\n\n\n<p>\u8981\u8bbe\u7f6e\u7b2c\u4e00\u884c\u7684\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u7528\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).Height= 200*20;<\/p>\n\n\n\n<p>\u6216\u8005<\/p>\n\n\n\n<p>sheet1.CreateRow(0).HeightInPoints= 200;<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u83b7\u5f97\u67d0\u4e00\u884c\u7684\u884c\u9ad8\uff0c\u53ef\u4ee5\u76f4\u63a5\u62ffHSSFRow.Height\u5c5e\u6027\u7684\u8fd4\u56de\u503c\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u80fd\u89c9\u5f97\u4e00\u884c\u4e00\u884c\u8bbe\u7f6e\u884c\u9ad8\u6216\u8005\u4e00\u5217\u4e00\u5217\u8bbe\u7f6e\u5217\u5bbd\u5f88\u9ebb\u70e6\uff0c\u90a3\u4f60\u53ef\u4ee5\u8003\u8651\u4f7f\u7528HSSFSheet.DefaultColumnWidth\u3001HSSFSheet.DefaultRowHeight\u548cHSSFSheet.DefaultRowHeightInPoints\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u4e00\u65e6\u8bbe\u7f6e\u4e86\u8fd9\u4e9b\u5c5e\u6027\uff0c\u5982\u679c\u67d0\u4e00\u884c\u6216\u8005\u67d0\u4e00\u5217\u6ca1\u6709\u8bbe\u7f6e\u5bbd\u5ea6\uff0c\u5c31\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u5bbd\u5ea6\u6216\u9ad8\u5ea6\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>sheet1.DefaultColumnWidth=100*256;<\/p>\n\n\n\n<p>sheet1.DefaultRowHeight=30*20;<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684SetWidthAndHeightInXls\u9879\u76ee<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/10\/1564407.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.1\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u57fa\u672c\u8ba1\u7b97<\/strong><\/p>\n\n\n\n<p>\u4ece\u8fd9\u8282\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u5f00\u59cb\u5b66\u4e60Excel\u9ad8\u7ea7\u4e00\u70b9\u7684\u529f\u80fd&#8211;\u516c\u5f0f\u3002\u4e3a\u67d0\u4e2a\u5355\u5143\u683c\u6307\u5b9a\u516c\u5f0f\u540e\uff0c\u5355\u5143\u683c\u4e2d\u7684\u7c7b\u5bb9\u5c06\u6839\u636e\u516c\u5f0f\u8ba1\u7b97\u5f97\u51fa\uff0c\u5982\u56fe\uff1a<br><br>\u56fe\u4e2d\u8bbe\u7f6e\u7684\u662f\u4e00\u4e2a\u57fa\u672c\u8868\u8fbe\u5f0f\u201d1+2*3\u201d\uff0c\u5355\u5143\u683cA1\u4e2d\u5c06\u663e\u793a\u6b64\u8868\u8fbe\u5f0f\u8ba1\u7b97\u7684\u7ed3\u679c\u201d7\u201d\uff0c\u5982\u56fe\u6240\u793a\u3002\u5bf9\u5e94\u7684C#\u751f\u6210\u4ee3\u7801\u4e5f\u5f88\u7b80\u5355\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row1=sheet1.CreateRow(0);<br>HSSFCell&nbsp;cel1&nbsp;=&nbsp;row1.CreateCell(0);<br>HSSFCell&nbsp;cel2&nbsp;=&nbsp;row1.CreateCell(1);<br>HSSFCell&nbsp;cel3&nbsp;=&nbsp;row1.CreateCell(2);<br>cel1.SetCellFormula(&#8220;1+2*3&#8221;);<br>cel2.SetCellValue(5);<\/p>\n\n\n\n<p>\u540c\u6837\uff0cNPOI\u4e5f\u652f\u6301\u5355\u5143\u683c\u5f15\u7528\u7c7b\u578b\u7684\u516c\u5f0f\u8bbe\u7f6e\uff0c\u5982\u4e0b\u56fe\u4e2d\u7684C1=A1*B1\u3002<br><br>\u5bf9\u5e94\u7684\u516c\u5f0f\u8bbe\u7f6e\u4ee3\u7801\u4e3a\uff1a<\/p>\n\n\n\n<p>cel3.SetCellFormula(&#8220;A1*B1&#8221;);<\/p>\n\n\n\n<p><br>\u662f\u4e0d\u662f\u5f88\u7b80\u5355\u5462\uff1f\u4f46\u8981\u6ce8\u610f\uff0c\u5728\u5229\u7528NPOI\u5199\u7a0b\u5e8f\u65f6\uff0c\u884c\u548c\u5217\u7684\u8ba1\u6570\u90fd\u662f\u4ece0\u5f00\u59cb\u8ba1\u7b97\u7684\uff0c\u4f46\u5728\u8bbe\u7f6e\u516c\u5f0f\u65f6\u53c8\u662f\u6309\u7167Excel\u7684\u5355\u5143\u683c\u547d\u540d\u89c4\u5219\u6765\u7684\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/10\/1564412.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.2\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0dSUM\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>\u8fd9\u8282\u6211\u4eec\u5f00\u59cb\u5b66\u4e60Excel\u4e2d\u6700\u5e38\u7528\u7684\u51fd\u6570\u2014Sum\u6c42\u548c\u51fd\u6570\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0a\u6700\u7b80\u5355\u7684Sum\u51fd\u6570\uff1aSum(num1,num2,&#8230;)\u3002\u4f7f\u7528\u6548\u679c\u5982\u56fe<br><br>\u56fe\u4e2d\u7684E1=Sum(A1,C1)\u8868\u793a\u5c06A1\u4e0eC1\u7684\u548c\u586b\u5145\u5728E1\u5904\uff0c\u4e0e\u516c\u5f0f\u201dE1=A1+C1\u201d\u7b49\u6548\u3002\u5bf9\u5e94\u7684\u751f\u6210\u4ee3\u7801\u4e0e\u4e0a\u4e00\u8282\u4e2d\u7684\u57fa\u672c\u8ba1\u7b97\u516c\u5f0f\u7c7b\u4f3c\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>HSSFCell&nbsp;cel1&nbsp;=&nbsp;row1.CreateCell(0);<br>HSSFCell&nbsp;cel2&nbsp;=&nbsp;row1.CreateCell(1);<br>HSSFCell&nbsp;cel3&nbsp;=&nbsp;row1.CreateCell(2);<br>HSSFCell&nbsp;celSum1&nbsp;=&nbsp;row1.CreateCell(3);<br>HSSFCell&nbsp;celSum2&nbsp;=&nbsp;row1.CreateCell(4);<br>HSSFCell&nbsp;celSum3&nbsp;=&nbsp;row1.CreateCell(5);<br><br>cel1.SetCellValue(1);<br>cel2.SetCellValue(2);<br>cel3.SetCellValue(3);<br>celSum2.SetCellFormula(&#8220;sum(A1,C1)&#8221;);<\/p>\n\n\n\n<p>&nbsp;\u5f53\u7136\uff0c\u628a\u6bcf\u4e00\u4e2a\u5355\u5143\u683c\u4f5c\u4e3aSum\u51fd\u6570\u7684\u53c2\u6570\u5f88\u5bb9\u6613\u7406\u89e3\uff0c\u4f46\u5982\u679c\u8981\u6c42\u548c\u7684\u5355\u5143\u683c\u5f88\u591a\uff0c\u90a3\u4e48\u516c\u5f0f\u5c31\u4f1a\u5f88\u957f\uff0c\u65e2\u4e0d\u65b9\u4fbf\u9605\u8bfb\u4e5f\u4e0d\u65b9\u4fbf\u4e66\u5199\u3002\u6240\u4ee5Excel\u63d0\u4f9b\u4e86\u53e6\u5916\u4e00\u79cd\u591a\u4e2a\u5355\u5143\u683c\u6c42\u548c\u7684\u5199\u6cd5\uff1a<br><br>\u5982\u4e0a\u56fe\u4e2d\u7684\u201cSum(A1:C1)\u201d\u8868\u793a\u6c42\u4eceA1\u5230C1\u6240\u6709\u5355\u5143\u683c\u7684\u548c\uff0c\u76f8\u5f53\u4e8eA1+B1+C1\u3002<br>\u5bf9\u5e94\u7684\u4ee3\u7801\u4e3a\uff1a<\/p>\n\n\n\n<p>celSum1.SetCellFormula(&#8220;sum(A1:C1)&#8221;);<\/p>\n\n\n\n<p><br>\u6700\u540e\uff0c\u8fd8\u6709\u4e00\u79cd\u6c42\u548c\u7684\u65b9\u6cd5\u3002\u5c31\u662f\u5148\u5b9a\u4e49\u4e00\u4e2a\u533a\u57df\uff0c\u5982\u201drange1\u201d\uff0c\u7136\u540e\u518d\u8bbe\u7f6eSum(range1)\uff0c\u6b64\u65f6\u5c06\u8ba1\u7b97\u533a\u57df\u4e2d\u6240\u6709\u5355\u5143\u683c\u7684\u548c\u3002<br>\u5b9a\u4e49\u533a\u57df\u7684\u4ee3\u7801\u4e3a\uff1a<\/p>\n\n\n\n<p>HSSFName&nbsp;range&nbsp;=&nbsp;hssfworkbook.CreateName();<br>range.Reference&nbsp;=&nbsp;&#8220;Sheet1!$A1:$C1&#8221;;<br>range.NameName&nbsp;=&nbsp;&#8220;range1&#8221;;<\/p>\n\n\n\n<p>\u6267\u884c\u6b64\u4ee3\u7801\u540e\u7684Excel\u6587\u4ef6\u5c06\u5728\u7684\u516c\u5f0f\u83dc\u5355\u4e0b\u7684\u540d\u79f0\u7ba1\u7406\u5668(Excel2007\u7684\u83dc\u5355\u8def\u5f84,2003\u7a0d\u6709\u4e0d\u540c)\u4e2d\u770b\u5230\u5982\u4e0b\u533a\u57df\u5b9a\u4e49\uff1a<br>&nbsp;<br>\u7ed9\u5355\u5143\u683cF1\u52a0\u4e0a\u516c\u5f0f\uff1a<\/p>\n\n\n\n<p>celSum3.SetCellFormula(&#8220;sum(range1)&#8221;);<\/p>\n\n\n\n<p>\u751f\u6210\u7684Excel\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br>&nbsp;<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565644.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.3\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u65e5\u671f\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>Excel\u4e2d\u6709\u975e\u5e38\u4e30\u5bcc\u7684\u65e5\u671f\u5904\u7406\u51fd\u6570\uff0c\u5728NPOI\u4e2d\u540c\u6837\u5f97\u5230\u4e86\u5f88\u597d\u7684\u652f\u6301\u3002\u5982\u4e0b\u56fe\uff1a<br>\u5bf9\u5e94\u7684\u4e0e\u524d\u9762\u7684\u57fa\u672c\u516c\u5f0f\u8bbe\u7f6e\u7c7b\u4f3c\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row1.CreateCell(0).SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u53c2\u52a0\u5de5\u4f5c\u65f6\u95f4&#8221;);<br>row1.CreateCell(2).SetCellValue(&#8220;\u5f53\u524d\u65e5\u671f&#8221;);<br>row1.CreateCell(3).SetCellValue(&#8220;\u5de5\u4f5c\u5e74\u9650&#8221;);<br><br>HSSFCell&nbsp;cel1&nbsp;=&nbsp;row2.CreateCell(0);<br>HSSFCell&nbsp;cel2&nbsp;=&nbsp;row2.CreateCell(1);<br>HSSFCell&nbsp;cel3&nbsp;=&nbsp;row2.CreateCell(2);<br>HSSFCell&nbsp;cel4&nbsp;=&nbsp;row2.CreateCell(3);<br><br>cel1.SetCellValue(&#8220;aTao.Xiang&#8221;);<br>cel2.SetCellValue(new&nbsp;DateTime(2004,&nbsp;7,&nbsp;1));<br>cel3.SetCellFormula(&#8220;TODAY()&#8221;);<br>cel4.SetCellFormula(&#8220;CONCATENATE(DATEDIF(B2,TODAY(),\\&#8221;y\\&#8221;),\\&#8221;\u5e74\\&#8221;,DATEDIF(B2,TODAY(),\\&#8221;ym\\&#8221;),\\&#8221;\u4e2a\u6708\\&#8221;)&#8221;);<br><br>\/\/\u5728poi\u4e2d\u65e5\u671f\u662f\u4ee5double\u7c7b\u578b\u8868\u793a\u7684\uff0c\u6240\u4ee5\u8981\u683c\u5f0f\u5316<br>HSSFCellStyle&nbsp;cellStyle&nbsp;=&nbsp;hssfworkbook.CreateCellStyle();<br>HSSFDataFormat&nbsp;format&nbsp;=&nbsp;hssfworkbook.CreateDataFormat();<br>cellStyle.DataFormat&nbsp;=&nbsp;format.GetFormat(&#8220;yyyy-m-d&#8221;);<br><br>cel2.CellStyle&nbsp;=&nbsp;cellStyle;<br>cel3.CellStyle&nbsp;=&nbsp;cellStyle;<\/p>\n\n\n\n<p>\u4e0b\u9762\u5bf9\u4e0a\u4f8b\u4e2d\u7528\u5230\u7684\u51e0\u4e2a\u4e3b\u8981\u51fd\u6570\u4f5c\u4e00\u4e9b\u8bf4\u660e\uff1a<br>TODAY()\uff1a\u53d6\u5f97\u5f53\u524d\u65e5\u671f;<br>DATEDIF(B2,TODAY(),&#8221;y&#8221;)\uff1a\u53d6\u5f97B2\u5355\u5143\u683c\u7684\u65e5\u671f\u4e0e\u524d\u65e5\u671f\u4ee5\u5e74\u4e3a\u5355\u4f4d\u7684\u65f6\u95f4\u95f4\u9694\u3002(\u201cY\u201d:\u8868\u793a\u4ee5\u5e74\u4e3a\u5355\u4f4d,\u201dm\u201d\u8868\u793a\u4ee5\u6708\u4e3a\u5355\u4f4d;\u201dd\u201d\u8868\u793a\u4ee5\u5929\u4e3a\u5355\u4f4d);<br>CONCATENATE(str1,str2,&#8230;)\uff1a\u8fde\u63a5\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u9644\u4e0aExcel\u4e2d\u5e38\u7528\u7684\u65e5\u671f\u51fd\u6570\u5217\u8868\uff0c\u53ea\u9700\u8981\u5c06\u6b64\u53e5\u4ee3\u7801\u4f5c\u9002\u5f53\u4fee\u6539\u5373\u53ef\uff1a<\/p>\n\n\n\n<p>cel4.SetCellFormula(&#8220;CONCATENATE(DATEDIF(B2,TODAY(),\\&#8221;y\\&#8221;),\\&#8221;\u5e74\\&#8221;,DATEDIF(B2,TODAY(),\\&#8221;ym\\&#8221;),\\&#8221;\u4e2a\u6708\\&#8221;)&#8221;);<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u51fd\u6570\u540d<\/td><td>\u51fd\u6570\u8bf4\u660e<\/td><td>\u8bed\u6cd5<\/td><\/tr><tr><td>DATE<\/td><td>\u8fd4\u56de\u4ee3\u8868\u7279\u5b9a\u65e5\u671f\u7684\u7cfb\u5217\u6570\u3002<\/td><td>DATE(year,month,day)<\/td><\/tr><tr><td>DATEDIF<\/td><td>\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u3001\u6708\u6570\u6216\u5e74\u6570\u3002<\/td><td>DATEDIF(start_date,end_date,unit)<\/td><\/tr><tr><td>DATEVALUE<\/td><td>\u51fd\u6570&nbsp;DATEVALUE\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c06\u4ee5\u6587\u5b57\u8868\u793a\u7684\u65e5\u671f\u8f6c\u6362\u6210\u4e00\u4e2a\u7cfb\u5217\u6570\u3002<\/td><td>DATEVALUE(date_text)<\/td><\/tr><tr><td>DAY<\/td><td>\u8fd4\u56de\u4ee5\u7cfb\u5217\u6570\u8868\u793a\u7684\u67d0\u65e5\u671f\u7684\u5929\u6570\uff0c\u7528\u6574\u6570&nbsp;1\u5230&nbsp;31&nbsp;\u8868\u793a\u3002<\/td><td>DAY(serial_number)<\/td><\/tr><tr><td>DAYS360<\/td><td>\u6309\u7167\u4e00\u5e74&nbsp;360\u5929\u7684\u7b97\u6cd5\uff08\u6bcf\u4e2a\u6708\u4ee5&nbsp;30&nbsp;\u5929\u8ba1\uff0c\u4e00\u5e74\u5171\u8ba1&nbsp;12&nbsp;\u4e2a\u6708\uff09\uff0c\u8fd4\u56de\u4e24\u65e5\u671f\u95f4\u76f8\u5dee\u7684\u5929\u6570\u3002<\/td><td>DAYS360(start_date,end_date,method)<\/td><\/tr><tr><td>EDATE<\/td><td>\u8fd4\u56de\u6307\u5b9a\u65e5\u671f&nbsp;(start_date)\u4e4b\u524d\u6216\u4e4b\u540e\u6307\u5b9a\u6708\u4efd\u6570\u7684\u65e5\u671f\u7cfb\u5217\u6570\u3002\u4f7f\u7528\u51fd\u6570&nbsp;EDATE\u53ef\u4ee5\u8ba1\u7b97\u4e0e\u53d1\u884c\u65e5\u5904\u4e8e\u4e00\u6708\u4e2d\u540c\u4e00\u5929\u7684\u5230\u671f\u65e5\u7684\u65e5\u671f\u3002<\/td><td>EDATE(start_date,months)<\/td><\/tr><tr><td>EOMONTH<\/td><td>\u8fd4\u56de&nbsp;start-date\u4e4b\u524d\u6216\u4e4b\u540e\u6307\u5b9a\u6708\u4efd\u4e2d\u6700\u540e\u4e00\u5929\u7684\u7cfb\u5217\u6570\u3002\u7528\u51fd\u6570&nbsp;EOMONTH\u53ef\u8ba1\u7b97\u7279\u5b9a\u6708\u4efd\u4e2d\u6700\u540e\u4e00\u5929\u7684\u65f6\u95f4\u7cfb\u5217\u6570\uff0c\u7528\u4e8e\u8bc1\u5238\u7684\u5230\u671f\u65e5\u7b49\u8ba1\u7b97\u3002<\/td><td>EOMONTH(start_date,months)<\/td><\/tr><tr><td>HOUR<\/td><td>\u8fd4\u56de\u65f6\u95f4\u503c\u7684\u5c0f\u65f6\u6570\u3002\u5373\u4e00\u4e2a\u4ecb\u4e8e&nbsp;0 (12:00 A.M.)\u5230&nbsp;23 (11:00 P.M.)\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>HOUR(serial_number)<\/td><\/tr><tr><td>MINUTE<\/td><td>\u8fd4\u56de\u65f6\u95f4\u503c\u4e2d\u7684\u5206\u949f\u3002\u5373\u4e00\u4e2a\u4ecb\u4e8e&nbsp;0\u5230&nbsp;59&nbsp;\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>MINUTE(serial_number)<\/td><\/tr><tr><td>MONTH<\/td><td>\u8fd4\u56de\u4ee5\u7cfb\u5217\u6570\u8868\u793a\u7684\u65e5\u671f\u4e2d\u7684\u6708\u4efd\u3002\u6708\u4efd\u662f\u4ecb\u4e8e&nbsp;1\uff08\u4e00\u6708\uff09\u548c&nbsp;12\uff08\u5341\u4e8c\u6708\uff09\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>MONTH(serial_number)<\/td><\/tr><tr><td>NETWORKDAYS<\/td><td>\u8fd4\u56de\u53c2\u6570&nbsp;start-data\u548c&nbsp;end-data&nbsp;\u4e4b\u95f4\u5b8c\u6574\u7684\u5de5\u4f5c\u65e5\u6570\u503c\u3002\u5de5\u4f5c\u65e5\u4e0d\u5305\u62ec\u5468\u672b\u548c\u4e13\u95e8\u6307\u5b9a\u7684\u5047\u671f<\/td><td>NETWORKDAYS(start_date,end_date,holidays)<\/td><\/tr><tr><td>NOW<\/td><td>\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4\u6240\u5bf9\u5e94\u7684\u7cfb\u5217\u6570\u3002<\/td><td>NOW( )<\/td><\/tr><tr><td>SECOND<\/td><td>\u8fd4\u56de\u65f6\u95f4\u503c\u7684\u79d2\u6570\u3002\u8fd4\u56de\u7684\u79d2\u6570\u4e3a&nbsp;0\u81f3&nbsp;59&nbsp;\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>SECOND(serial_number)<\/td><\/tr><tr><td>TIME<\/td><td>\u8fd4\u56de\u67d0\u4e00\u7279\u5b9a\u65f6\u95f4\u7684\u5c0f\u6570\u503c\uff0c\u51fd\u6570&nbsp;TIME\u8fd4\u56de\u7684\u5c0f\u6570\u503c\u4e3a\u4ece&nbsp;0&nbsp;\u5230&nbsp;0.99999999&nbsp;\u4e4b\u95f4\u7684\u6570\u503c\uff0c\u4ee3\u8868\u4ece&nbsp;0:00:00 (12:00:00 A.M)\u5230&nbsp;23:59:59 (11:59:59 P.M)\u4e4b\u95f4\u7684\u65f6\u95f4\u3002<\/td><td>TIME(hour,minute,second)<\/td><\/tr><tr><td>TIMEVALUE<\/td><td>\u8fd4\u56de\u7531\u6587\u672c\u4e32\u6240\u4ee3\u8868\u7684\u65f6\u95f4\u7684\u5c0f\u6570\u503c\u3002\u8be5\u5c0f\u6570\u503c\u4e3a\u4ece&nbsp;0\u5230&nbsp;0.999999999&nbsp;\u7684\u6570\u503c\uff0c\u4ee3\u8868\u4ece&nbsp;0:00:00 (12:00:00 AM)\u5230&nbsp;23:59:59 (11:59:59 PM)\u4e4b\u95f4\u7684\u65f6\u95f4\u3002<\/td><td>TIMEVALUE(time_text)<\/td><\/tr><tr><td>TODAY<\/td><td>\u8fd4\u56de\u5f53\u524d\u65e5\u671f\u7684\u7cfb\u5217\u6570\uff0c\u7cfb\u5217\u6570\u662f&nbsp;Microsoft Excel\u7528\u4e8e\u65e5\u671f\u548c\u65f6\u95f4\u8ba1\u7b97\u7684\u65e5\u671f-\u65f6\u95f4\u4ee3\u7801\u3002<\/td><td>TODAY( )<\/td><\/tr><tr><td>WEEKDAY<\/td><td>\u8fd4\u56de\u67d0\u65e5\u671f\u4e3a\u661f\u671f\u51e0\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5176\u503c\u4e3a&nbsp;1\uff08\u661f\u671f\u5929\uff09\u5230&nbsp;7\uff08\u661f\u671f\u516d\uff09\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>WEEKDAY(serial_number,return_type)<\/td><\/tr><tr><td>WEEKNUM<\/td><td>\u8fd4\u56de\u4e00\u4e2a\u6570\u5b57\uff0c\u8be5\u6570\u5b57\u4ee3\u8868\u4e00\u5e74\u4e2d\u7684\u7b2c\u51e0\u5468\u3002<\/td><td>WEEKNUM(serial_num,return_type)<\/td><\/tr><tr><td>WORKDAY<\/td><td>\u8fd4\u56de\u67d0\u65e5\u671f\uff08\u8d77\u59cb\u65e5\u671f\uff09\u4e4b\u524d\u6216\u4e4b\u540e\u76f8\u9694\u6307\u5b9a\u5de5\u4f5c\u65e5\u7684\u67d0\u4e00\u65e5\u671f\u7684\u65e5\u671f\u503c\u3002\u5de5\u4f5c\u65e5\u4e0d\u5305\u62ec\u5468\u672b\u548c\u4e13\u95e8\u6307\u5b9a\u7684\u5047\u65e5\u3002<\/td><td>WORKDAY(start_date,days,holidays)<\/td><\/tr><tr><td>YEAR<\/td><td>\u8fd4\u56de\u67d0\u65e5\u671f\u7684\u5e74\u4efd\u3002\u8fd4\u56de\u503c\u4e3a&nbsp;1900\u5230&nbsp;9999&nbsp;\u4e4b\u95f4\u7684\u6574\u6570\u3002<\/td><td>YEAR(serial_number)<\/td><\/tr><tr><td>YEARFRAC<\/td><td>\u8fd4\u56de&nbsp;start_date\u548c&nbsp;end_date&nbsp;\u4e4b\u95f4\u7684\u5929\u6570\u5360\u5168\u5e74\u5929\u6570\u7684\u767e\u5206\u6bd4\u3002<\/td><td>YEARFRAC(start_date,end_date,basis)<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565899.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.4\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u5b57\u7b26\u4e32\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u4e00\u8282\u6211\u4eec\u5f00\u59cb\u5b66\u4e60Excel\u53e6\u4e00\u7c7b\u975e\u5e38\u5e38\u89c1\u7684\u51fd\u6570\u2014\u5b57\u7b26\u4e32\u51fd\u6570\u3002\u5728Excel\u4e2d\u63d0\u4f9b\u4e86\u975e\u5e38\u4e30\u5bcc\u7684\u5b57\u7b26\u4e32\u51fd\u6570\uff0c\u5728NPOI\u4e2d\u540c\u6837\u5f97\u5230\u4e86\u5f88\u597d\u7684\u652f\u6301\u3002<br><strong>\u4e00\u3001&nbsp;\u5927\u5c0f\u5199\u8f6c\u6362\u7c7b\u51fd\u6570<br><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOWER(String)\uff1a\u5c06\u4e00\u4e2a\u6587\u5b57\u4e32\u4e2d\u7684\u6240\u6709\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UPPER(String)\uff1a\u5c06\u6587\u672c\u8f6c\u6362\u6210\u5927\u5199\u5f62\u5f0f\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PROPER(String)\uff1a\u5c06\u6587\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u53ca\u4efb\u4f55\u975e\u5b57\u6bcd\u5b57\u7b26\u4e4b\u540e\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u3002\u5c06\u5176\u4f59\u7684\u5b57\u6bcd\u8f6c\u6362\u6210\u5c0f\u5199\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5bf9\u5e94\u7684C#\u4ee3\u7801\u4e0e\u524d\u51e0\u8282\u8bb2\u7684\u8bbe\u7f6e\u516c\u5f0f\u7684\u4ee3\u7801\u7c7b\u4f3c\uff1a<\/p>\n\n\n\n<p><strong>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u5f85\u64cd\u4f5c\u5b57\u7b26\u4e32&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u64cd\u4f5c\u51fd\u6570&#8221;);<br>row1.CreateCell(2).SetCellValue(&#8220;\u64cd\u4f5c\u7ed3\u679c&#8221;);<br><br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row2.CreateCell(0).SetCellValue(&#8220;This&nbsp;is&nbsp;a&nbsp;NPOI&nbsp;example!&#8221;);<br>row2.CreateCell(1).SetCellValue(&#8220;LOWER(A2)&#8221;);<br>\/\/\u5c06\u6b64\u53e5\u4e2d\u7684\u201cLOWER(A2)\u201d\u6362\u6210UPPER&nbsp;(A2)\u3001PROPER&nbsp;(A2)\u53ef\u4ee5\u770b\u5230\u4e0d\u540c\u6548\u679c\u3002<br>row2.CreateCell(2).SetCellFormula(&#8220;LOWER(A2)&#8221;);<\/strong><\/p>\n\n\n\n<p><strong>\u4e8c\u3001&nbsp;\u53d6\u51fa\u5b57\u7b26\u4e32\u4e2d\u7684\u90e8\u5206\u5b57\u7b26<\/strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LEFT(text,num_chars)\uff1aLEFT(text,num_chars)\u5176\u4e2dText\u662f\u5305\u542b\u8981\u63d0\u53d6\u5b57\u7b26\u7684\u6587\u672c\u4e32\u3002Num_chars\u6307\u5b9a\u8981\u7531&nbsp;LEFT&nbsp;\u6240\u63d0\u53d6\u7684\u5b57\u7b26\u6570\u3002<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MID(text,start_num,num_chars)\uff1aMID(text,start_num,num_chars)\u5176\u4e2dText\u662f\u5305\u542b\u8981\u63d0\u53d6\u5b57\u7b26\u7684\u6587\u672c\u4e32\u3002Start_num\u662f\u6587\u672c\u4e2d\u8981\u63d0\u53d6\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u4f4d\u7f6e\uff0cnum_chars\u8868\u793a\u8981\u63d0\u53d6\u7684\u5b57\u7b26\u7684\u6570\u3002<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RIGHT(text,num_chars)\uff1aRIGHT(text,num_chars)\u5176\u4e2dText\u662f\u5305\u542b\u8981\u63d0\u53d6\u5b57\u7b26\u7684\u6587\u672c\u4e32\u3002Num_chars\u6307\u5b9a\u5e0c\u671b&nbsp;RIGHT&nbsp;\u63d0\u53d6\u7684\u5b57\u7b26\u6570\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4ee3\u7801\u4e0e\u4e0a\u9762\u7c7b\u4f3c\uff0c\u5c31\u4e0d\u5199\u4e86\u3002<br><br><strong>\u4e09\u3001&nbsp;\u53bb\u9664\u5b57\u7b26\u4e32\u7684\u7a7a\u767d<br><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRIM(text)\uff1a\u5176\u4e2dText\u4e3a\u9700\u8981\u6e05\u9664\u5176\u4e2d\u7a7a\u683c\u7684\u6587\u672c\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e0eC#\u4e2d\u7684Trim\u4e0d\u540c\uff0cExcel\u4e2d\u7684Trim\u51fd\u6570\u4e0d\u4ec5\u4f1a\u5220\u9664\u5b57\u7b26\u4e32\u5934\u5c3e\u7684\u5b57\u7b26\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u591a\u4f59\u5b57\u7b26\u4e5f\u4f1a\u5220\u9664\uff0c\u5355\u8bcd\u4e4b\u95f4\u53ea\u4f1a\u4fdd\u7559\u4e00\u4e2a\u7a7a\u683c\u3002<\/p>\n\n\n\n<p><strong>\u56db\u3001&nbsp;\u5b57\u7b26\u4e32\u7684\u6bd4\u8f83<\/strong><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXACT(text1,text2)\uff1a\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49\uff0c\u533a\u5206\u5927\u5c0f\u5199\u3002<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6267\u884c\u6548\u679c\u5982\u4e0b\uff1a<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5728\u6b64\u53ea\u7b80\u5355\u7684\u8bb2\u4e86\u4e00\u4e0b\u5e38\u7528\u7684\u51fd\u6570\uff0cExcel\u4e2d\u8fd8\u6709\u5f88\u591a\u7684\u5b57\u7b26\u4e32\u51fd\u6570\uff0c\u5728\u6b64\u9644\u4e0a\uff0c\u8bfb\u8005\u53ef\u4ee5\u4e00\u4e2a\u4e00\u4e2a\u53bb\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u51fd\u6570\u540d<\/td><td>\u51fd\u6570\u8bf4\u660e<\/td><td>\u8bed\u6cd5<\/td><\/tr><tr><td>ASC<\/td><td>\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5168\u89d2\uff08\u53cc\u5b57\u8282\uff09\u82f1\u6587\u5b57\u6bcd\u66f4\u6539\u4e3a\u534a\u89d2\uff08\u5355\u5b57\u8282\uff09\u5b57\u7b26\u3002<\/td><td>ASC(text)<\/td><\/tr><tr><td>CHAR<\/td><td>\u8fd4\u56de\u5bf9\u5e94\u4e8e\u6570\u5b57\u4ee3\u7801\u7684\u5b57\u7b26\uff0c\u51fd\u6570&nbsp;CHAR\u53ef\u5c06\u5176\u4ed6\u7c7b\u578b\u8ba1\u7b97\u673a\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\u8f6c\u6362\u4e3a\u5b57\u7b26\u3002<\/td><td>CHAR(number)<\/td><\/tr><tr><td>CLEAN<\/td><td>\u5220\u9664\u6587\u672c\u4e2d\u4e0d\u80fd\u6253\u5370\u7684\u5b57\u7b26\u3002\u5bf9\u4ece\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u4f7f\u7528&nbsp;CLEAN\u51fd\u6570\uff0c\u5c06\u5220\u9664\u5176\u4e2d\u542b\u6709\u7684\u5f53\u524d\u64cd\u4f5c\u7cfb\u7edf\u65e0\u6cd5\u6253\u5370\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5220\u9664\u901a\u5e38\u51fa\u73b0\u5728\u6570\u636e\u6587\u4ef6\u5934\u90e8\u6216\u5c3e\u90e8\u3001\u65e0\u6cd5\u6253\u5370\u7684\u4f4e\u7ea7\u8ba1\u7b97\u673a\u4ee3\u7801\u3002<\/td><td>CLEAN(text)<\/td><\/tr><tr><td>CODE<\/td><td>\u8fd4\u56de\u6587\u5b57\u4e32\u4e2d\u7b2c\u4e00\u4e2a\u5b57\u7b26\u7684\u6570\u5b57\u4ee3\u7801\u3002\u8fd4\u56de\u7684\u4ee3\u7801\u5bf9\u5e94\u4e8e\u8ba1\u7b97\u673a\u5f53\u524d\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u3002<\/td><td>CODE(text)<\/td><\/tr><tr><td>CONCATENATE<\/td><td>\u5c06\u82e5\u5e72\u6587\u5b57\u4e32\u5408\u5e76\u5230\u4e00\u4e2a\u6587\u5b57\u4e32\u4e2d\u3002<\/td><td>CONCATENATE (text1,text2,&#8230;)<\/td><\/tr><tr><td>DOLLAR<\/td><td>\u4f9d\u7167\u8d27\u5e01\u683c\u5f0f\u5c06\u5c0f\u6570\u56db\u820d\u4e94\u5165\u5230\u6307\u5b9a\u7684\u4f4d\u6570\u5e76\u8f6c\u6362\u6210\u6587\u5b57\u3002<\/td><td>DOLLAR&nbsp;\u6216&nbsp;RMB(number,decimals)<\/td><\/tr><tr><td>EXACT<\/td><td>\u8be5\u51fd\u6570\u6d4b\u8bd5\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u5b8c\u5168\u76f8\u540c\u3002\u5982\u679c\u5b83\u4eec\u5b8c\u5168\u76f8\u540c\uff0c\u5219\u8fd4\u56de&nbsp;TRUE\uff1b\u5426\u5219\uff0c\u8fd4\u56de&nbsp;FALSE\u3002\u51fd\u6570&nbsp;EXACT&nbsp;\u80fd\u533a\u5206\u5927\u5c0f\u5199\uff0c\u4f46\u5ffd\u7565\u683c\u5f0f\u4e0a\u7684\u5dee\u5f02\u3002\u5229\u7528\u51fd\u6570&nbsp;EXACT\u53ef\u4ee5\u6d4b\u8bd5\u8f93\u5165\u6587\u6863\u5185\u7684\u6587\u5b57\u3002<\/td><td>EXACT(text1,text2)<\/td><\/tr><tr><td>FIND<\/td><td>FIND&nbsp;\u7528\u4e8e\u67e5\u627e\u5176\u4ed6\u6587\u672c\u4e32&nbsp;(within_text)\u5185\u7684\u6587\u672c\u4e32&nbsp;(find_text)\uff0c\u5e76\u4ece&nbsp;within_text\u7684\u9996\u5b57\u7b26\u5f00\u59cb\u8fd4\u56de&nbsp;find_text\u7684\u8d77\u59cb\u4f4d\u7f6e\u7f16\u53f7\u3002<\/td><td>FIND(find_text,within_text,start_num)<\/td><\/tr><tr><td>FIXED<\/td><td>\u6309\u6307\u5b9a\u7684\u5c0f\u6570\u4f4d\u6570\u8fdb\u884c\u56db\u820d\u4e94\u5165\uff0c\u5229\u7528\u53e5\u70b9\u548c\u9017\u53f7\uff0c\u4ee5\u5c0f\u6570\u683c\u5f0f\u5bf9\u8be5\u6570\u8bbe\u7f6e\u683c\u5f0f\uff0c\u5e76\u4ee5\u6587\u5b57\u4e32\u5f62\u5f0f\u8fd4\u56de\u7ed3\u679c\u3002<\/td><td>FIXED(number,decimals,no_commas)<\/td><\/tr><tr><td>JIS<\/td><td>\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u534a\u89d2\uff08\u5355\u5b57\u8282\uff09\u82f1\u6587\u5b57\u6bcd\u6216\u7247\u5047\u540d\u66f4\u6539\u4e3a\u5168\u89d2\uff08\u53cc\u5b57\u8282\uff09\u5b57\u7b26\u3002<\/td><td>JIS(text)<\/td><\/tr><tr><td>LEFT<\/td><td>LEFT&nbsp;\u57fa\u4e8e\u6240\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u6216\u524d\u51e0\u4e2a\u5b57\u7b26\u3002<br>LEFTB&nbsp;\u57fa\u4e8e\u6240\u6307\u5b9a\u7684\u5b57\u8282\u6570\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u7684\u7b2c\u4e00\u4e2a\u6216\u524d\u51e0\u4e2a\u5b57\u7b26\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u53cc\u5b57\u8282\u5b57\u7b26\u3002<\/td><td>LEFT(text,num_chars)<br>LEFTB(text,num_bytes)<\/td><\/tr><tr><td>LEN<\/td><td>LEN&nbsp;\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u7684\u5b57\u7b26\u6570\u3002<br>LENB&nbsp;\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u7528\u4e8e\u4ee3\u8868\u5b57\u7b26\u7684\u5b57\u8282\u6570\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u53cc\u5b57\u8282\u5b57\u7b26\u3002<\/td><td>LEN(text)<br>LENB(text)<\/td><\/tr><tr><td>LOWER<\/td><td>\u5c06\u4e00\u4e2a\u6587\u5b57\u4e32\u4e2d\u7684\u6240\u6709\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002<\/td><td>LOWER(text)<\/td><\/tr><tr><td>MID<\/td><td>MID&nbsp;\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u4ece\u6307\u5b9a\u4f4d\u7f6e\u5f00\u59cb\u7684\u7279\u5b9a\u6570\u76ee\u7684\u5b57\u7b26\uff0c\u8be5\u6570\u76ee\u7531\u7528\u6237\u6307\u5b9a\u3002<br>MIDB&nbsp;\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u4ece\u6307\u5b9a\u4f4d\u7f6e\u5f00\u59cb\u7684\u7279\u5b9a\u6570\u76ee\u7684\u5b57\u7b26\uff0c\u8be5\u6570\u76ee\u7531\u7528\u6237\u6307\u5b9a\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u53cc\u5b57\u8282\u5b57\u7b26\u3002<\/td><td>MID(text,start_num,num_chars)<br>MIDB(text,start_num,num_bytes)<\/td><\/tr><tr><td>PHONETIC<\/td><td>\u63d0\u53d6\u6587\u672c\u4e32\u4e2d\u7684\u62fc\u97f3&nbsp;(furigana)\u5b57\u7b26\u3002<\/td><td>PHONETIC(reference)<\/td><\/tr><tr><td>PROPER<\/td><td>\u5c06\u6587\u5b57\u4e32\u7684\u9996\u5b57\u6bcd\u53ca\u4efb\u4f55\u975e\u5b57\u6bcd\u5b57\u7b26\u4e4b\u540e\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u6210\u5927\u5199\u3002\u5c06\u5176\u4f59\u7684\u5b57\u6bcd\u8f6c\u6362\u6210\u5c0f\u5199\u3002<\/td><td>PROPER(text)<\/td><\/tr><tr><td>REPLACE<\/td><td>REPLACE&nbsp;\u4f7f\u7528\u5176\u4ed6\u6587\u672c\u4e32\u5e76\u6839\u636e\u6240\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u66ff\u6362\u67d0\u6587\u672c\u4e32\u4e2d\u7684\u90e8\u5206\u6587\u672c\u3002<br>REPLACEB&nbsp;\u4f7f\u7528\u5176\u4ed6\u6587\u672c\u4e32\u5e76\u6839\u636e\u6240\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u66ff\u6362\u67d0\u6587\u672c\u4e32\u4e2d\u7684\u90e8\u5206\u6587\u672c\u3002\u6b64\u51fd\u6570\u4e13\u4e3a\u53cc\u5b57\u8282\u5b57\u7b26\u4f7f\u7528\u3002<\/td><td>REPLACE(old_text,start_num,num_chars,new_text)<br>REPLACEB(old_text,start_num,num_bytes,new_text)<\/td><\/tr><tr><td>REPT<\/td><td>\u6309\u7167\u7ed9\u5b9a\u7684\u6b21\u6570\u91cd\u590d\u663e\u793a\u6587\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570&nbsp;REPT\u6765\u4e0d\u65ad\u5730\u91cd\u590d\u663e\u793a\u67d0\u4e00\u6587\u5b57\u4e32\uff0c\u5bf9\u5355\u5143\u683c\u8fdb\u884c\u586b\u5145\u3002<\/td><td>REPT(text,number_times)<\/td><\/tr><tr><td>RIGHT<\/td><td>RIGHT&nbsp;\u6839\u636e\u6240\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u6700\u540e\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002<br>RIGHTB&nbsp;\u6839\u636e\u6240\u6307\u5b9a\u7684\u5b57\u7b26\u6570\u8fd4\u56de\u6587\u672c\u4e32\u4e2d\u6700\u540e\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u53cc\u5b57\u8282\u5b57\u7b26\u3002<\/td><td>RIGHT(text,num_chars)<br>RIGHTB(text,num_bytes)<\/td><\/tr><tr><td>SEARCH<\/td><td>SEARCH&nbsp;\u8fd4\u56de\u4ece&nbsp;start_num\u5f00\u59cb\u9996\u6b21\u627e\u5230\u7279\u5b9a\u5b57\u7b26\u6216\u6587\u672c\u4e32\u7684\u4f4d\u7f6e\u4e0a\u7279\u5b9a\u5b57\u7b26\u7684\u7f16\u53f7\u3002\u4f7f\u7528&nbsp;SEARCH\u53ef\u786e\u5b9a\u5b57\u7b26\u6216\u6587\u672c\u4e32\u5728\u5176\u4ed6\u6587\u672c\u4e32\u4e2d\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u5c31\u53ef\u4f7f\u7528MID\u6216&nbsp;REPLACE&nbsp;\u51fd\u6570\u66f4\u6539\u6587\u672c\u3002<br>SEARCHB&nbsp;\u4e5f\u53ef\u5728\u5176\u4ed6\u6587\u672c\u4e32&nbsp;(within_text)\u4e2d\u67e5\u627e\u6587\u672c\u4e32&nbsp;(find_text)\uff0c\u5e76\u8fd4\u56de&nbsp;find_text\u7684\u8d77\u59cb\u4f4d\u7f6e\u7f16\u53f7\u3002\u6b64\u7ed3\u679c\u662f\u57fa\u4e8e\u6bcf\u4e2a\u5b57\u7b26\u6240\u4f7f\u7528\u7684\u5b57\u8282\u6570\uff0c\u5e76\u4ece&nbsp;start_num\u5f00\u59cb\u7684\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u53cc\u5b57\u8282\u5b57\u7b26\u3002\u6b64\u5916\uff0c\u4e5f\u53ef\u4f7f\u7528&nbsp;FINDB\u5728\u5176\u4ed6\u6587\u672c\u4e32\u4e2d\u67e5\u627e\u6587\u672c\u4e32\u3002<\/td><td>SEARCH(find_text,within_text,start_num)<br>SEARCHB(find_text,within_text,start_num)<\/td><\/tr><tr><td>SUBSTITUTE<\/td><td>\u5728\u6587\u5b57\u4e32\u4e2d\u7528&nbsp;new_text\u66ff\u4ee3&nbsp;old_text\u3002\u5982\u679c\u9700\u8981\u5728\u67d0\u4e00\u6587\u5b57\u4e32\u4e2d\u66ff\u6362\u6307\u5b9a\u7684\u6587\u672c\uff0c\u8bf7\u4f7f\u7528\u51fd\u6570&nbsp;SUBSTITUTE\uff1b\u5982\u679c\u9700\u8981\u5728\u67d0\u4e00\u6587\u5b57\u4e32\u4e2d\u66ff\u6362\u6307\u5b9a\u4f4d\u7f6e\u5904\u7684\u4efb\u610f\u6587\u672c\uff0c\u8bf7\u4f7f\u7528\u51fd\u6570&nbsp;REPLACE\u3002<\/td><td>SUBSTITUTE(text,old_text,new_text,instance_num)<\/td><\/tr><tr><td>T<\/td><td>\u5c06\u6570\u503c\u8f6c\u6362\u6210\u6587\u672c\u3002<\/td><td>T(value)<\/td><\/tr><tr><td>TEXT<\/td><td>\u5c06\u4e00\u6570\u503c\u8f6c\u6362\u4e3a\u6309\u6307\u5b9a\u6570\u5b57\u683c\u5f0f\u8868\u793a\u7684\u6587\u672c\u3002<\/td><td>TEXT(value,format_text)<\/td><\/tr><tr><td>TRIM<\/td><td>\u9664\u4e86\u5355\u8bcd\u4e4b\u95f4\u7684\u5355\u4e2a\u7a7a\u683c\u5916\uff0c\u6e05\u9664\u6587\u672c\u4e2d\u6240\u6709\u7684\u7a7a\u683c\u3002\u5728\u4ece\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u83b7\u53d6\u5e26\u6709\u4e0d\u89c4\u5219\u7a7a\u683c\u7684\u6587\u672c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570&nbsp;TRIM\u3002<\/td><td>TRIM(text)<\/td><\/tr><tr><td>UPPER<\/td><td>\u5c06\u6587\u672c\u8f6c\u6362\u6210\u5927\u5199\u5f62\u5f0f\u3002<\/td><td>UPPER(text)<\/td><\/tr><tr><td>VALUE<\/td><td>\u5c06\u4ee3\u8868\u6570\u5b57\u7684\u6587\u5b57\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u3002<\/td><td>VALUE(text)<\/td><\/tr><tr><td>WIDECHAR<\/td><td>\u5c06\u5355\u5b57\u8282\u5b57\u7b26\u8f6c\u6362\u4e3a\u53cc\u5b57\u8282\u5b57\u7b26\u3002<\/td><td>WIDECHAR(text)<\/td><\/tr><tr><td>YEN<\/td><td>\u4f7f\u7528\uffe5\uff08\u65e5\u5706\uff09\u8d27\u5e01\u683c\u5f0f\u5c06\u6570\u5b57\u8f6c\u6362\u6210\u6587\u672c\uff0c\u5e76\u5bf9\u6307\u5b9a\u4f4d\u7f6e\u540e\u7684\u6570\u5b57\u56db\u820d\u4e94\u5165\u3002<\/td><td>YEN(number,decimals)<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/15\/1566667.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.5\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0dIf\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5728Excel\u4e2d,IF(logical_test,value_if_true,value_if_false)\u7528\u6765\u7528\u4f5c\u903b\u8f91\u5224\u65ad\u3002\u5176\u4e2dLogical_test\u8868\u793a\u8ba1\u7b97\u7ed3\u679c\u4e3a&nbsp;TRUE&nbsp;\u6216&nbsp;FALSE&nbsp;\u7684\u4efb\u610f\u503c\u6216\u8868\u8fbe\u5f0f&nbsp;; value_if_true\u8868\u793a\u5f53\u8868\u8fbe\u5f0fLogical_test\u7684\u503c\u4e3aTRUE\u65f6\u7684\u8fd4\u56de\u503c\uff1bvalue_if_false\u8868\u793a\u5f53\u8868\u8fbe\u5f0fLogical_test\u7684\u503c\u4e3aFALSE\u65f6\u7684\u8fd4\u56de\u503c\u3002\u540c\u6837\u5728NPOI\u4e2d\u4e5f\u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u8fdb\u884c\u5404\u79cd\u903b\u8f91\u8fd0\u7b97\u3002\u5982\u4e0b\u4ee3\u7801\u5206\u522b\u8bbe\u7f6e\u4e86B2\u548cD2\u5355\u5143\u683c\u7684\u7528\u4e8e\u903b\u8f91\u5224\u65ad\u7684\u516c\u5f0f\u3002<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u8eab\u4efd\u8bc1\u53f7&#8221;);<br>row1.CreateCell(2).SetCellValue(&#8220;\u6027\u522b&#8221;);<br>row1.CreateCell(3).SetCellValue(&#8220;\u8bed\u6587&#8221;);<br>row1.CreateCell(4).SetCellValue(&#8220;\u662f\u5426\u5408\u683c&#8221;);<br><br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row2.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>row2.CreateCell(1).SetCellValue(&#8220;420821198808101014&#8221;);<br>row2.CreateCell(2).SetCellFormula(&#8220;IF(MOD(MID(B2,18,1),2)=0,\\&#8221;\u7537\\&#8221;,\\&#8221;\u5973\\&#8221;)&#8221;);<br>row2.CreateCell(3).SetCellValue(85);<br>row2.CreateCell(4).SetCellFormula(&#8220;IF(D2&gt;60,IF(D2&gt;90,\\&#8221;\u4f18\u79c0\\&#8221;,\\&#8221;\u5408\u683c\\&#8221;),\\&#8221;\u4e0d\u5408\u683c\\&#8221;)&#8221;);<\/p>\n\n\n\n<p>\u5176\u4e2d\u6700\u5173\u952e\u7684\u4e24\u53e5\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>row2.CreateCell(2).SetCellFormula(&#8220;IF(MOD(MID(B2,18,1),2)=0,\\&#8221;\u7537\\&#8221;,\\&#8221;\u5973\\&#8221;)&#8221;);<\/p>\n\n\n\n<p>row2.CreateCell(4).SetCellFormula(&#8220;IF(D2&gt;60,IF(D2&gt;90,\\&#8221;\u4f18\u79c0\\&#8221;,\\&#8221;\u5408\u683c\\&#8221;),\\&#8221;\u4e0d\u5408\u683c\\&#8221;)&#8221;);<\/p>\n\n\n\n<p>&nbsp;<br><br>\u4e0b\u9762\u5206\u522b\u5bf9\u8fd9\u51e0\u4e2a\u51fd\u6570\u4f5c\u4e00\u4e9b\u8bf4\u660e\uff1a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MOD(MID(B2,18,1),2)\uff1a\u6211\u4eec\u77e5\u905318\u4f4d\u8eab\u4efd\u8bc1\u53f7\u7684\u7b2c18\u4f4d\u8868\u793a\u6027\u522b\uff0c\u5076\u6570\u4e3a\u7537\u6027\uff0c\u5947\u6570\u4e3a\u5973\u6027\uff0c\u6240\u4ee5\u7528\u4e86MID(B2,18,1)\u53d6\u7b2c18\u4f4d\u6570\u5b57\uff08\u4e0eC#\u4e2d\u4e00\u822c\u4ece0\u8ba1\u6570\u4e0d\u540c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4ece1\u7b97\u8d77\uff0c\u6709\u5173MID\u51fd\u6570\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u89c1<a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565899.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u5b57\u7b26\u4e32\u51fd\u6570<\/a>\uff09\uff0c\u7528MOD\u53d6\u4f59\u51fd\u6570\u5224\u65ad\u5947\u5076\u3002\u5728Excel\u4e2d\u5bf9\u6570\u636e\u7c7b\u578b\u7684\u63a7\u5236\u6ca1\u6709C#\u4e2d\u90a3\u4e48\u4e25\u683c\uff0c\u5982\u6b64\u4f8b\u4e2d\u6211\u622a\u53d6\u51fa\u6765\u7684\u662f\u5b57\u7b26\u4e32\uff0c\u4f46\u5f53\u6211\u505a\u53d6\u4f59\u8fd0\u7b97\u65f6Excel\u4f1a\u81ea\u52a8\u8f6c\u6362\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF(D2&gt;60,IF(D2&gt;90,&#8221;\u4f18\u79c0&#8221;,&#8221;\u5408\u683c&#8221;),&#8221;\u4e0d\u5408\u683c&#8221;)\uff1a\u8fd9\u662fIF\u7684\u5d4c\u5957\u4f7f\u7528\uff0c\u8868\u793a90\u5206\u4ee5\u4e0a\u4e3a\u4f18\u79c0\uff0c60\u5206\u4ee5\u4e0a\u4e3a\u5408\u683c\uff0c\u5426\u5219\u4e3a\u4e0d\u5408\u683c\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/16\/1567379.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.6\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0dCOUNTIF\u548cSUMIF\u51fd\u6570<\/strong><\/p>\n\n\n\n<p><strong>\u4e00\u3001COUNTIF&nbsp;<br><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u4e00\u8282\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u5b66\u4e60Excel\u4e2d\u53e6\u4e00\u4e2a\u5e38\u7528\u7684\u51fd\u6570&#8211;COUNTIF\u51fd\u6570\uff0c\u770b\u51fd\u6570\u540d\u5c31\u77e5\u9053\u8fd9\u662f\u4e00\u4e2a\u7528\u6765\u5728\u505a\u6ee1\u8db3\u67d0\u6761\u4ef6\u7684\u8ba1\u6570\u7684\u51fd\u6570\u3002\u5148\u6765\u770b\u4e00\u770b\u5b83\u7684\u8bed\u6cd5\uff1aCOUNTIF(range,criteria)\uff0c\u53c2\u6570\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>Range<\/td><td>\u9700\u8981\u8fdb\u884c\u8bfb\u6570\u7684\u8ba1\u6570<\/td><\/tr><tr><td>Criteria<\/td><td>\u6761\u4ef6\u8868\u8fbe\u5f0f\uff0c\u53ea\u6709\u5f53\u6ee1\u8db3\u6b64\u6761\u4ef6\u65f6\u624d\u8fdb\u884c\u8ba1\u6570<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u63a5\u4e0b\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u6210\u7ee9&#8221;);<br><br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row2.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>row2.CreateCell(1).SetCellValue(85);<br><br>HSSFRow&nbsp;row3&nbsp;=&nbsp;sheet1.CreateRow(2);<br>row3.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8&#8221;);<br>row3.CreateCell(1).SetCellValue(90);<br><br>HSSFRow&nbsp;row4&nbsp;=&nbsp;sheet1.CreateRow(3);<br>row4.CreateCell(0).SetCellValue(&#8220;\u4efb\u6211\u884c&#8221;);<br>row4.CreateCell(1).SetCellValue(70);<br><br>HSSFRow&nbsp;row5&nbsp;=&nbsp;sheet1.CreateRow(4);<br>row5.CreateCell(0).SetCellValue(&#8220;\u5de6\u51b7\u5a75&#8221;);<br>row5.CreateCell(1).SetCellValue(45);<br><br>HSSFRow&nbsp;row6&nbsp;=&nbsp;sheet1.CreateRow(5);<br>row6.CreateCell(0).SetCellValue(&#8220;\u5cb3\u4e0d\u7fa4&#8221;);<br>row6.CreateCell(1).SetCellValue(50);<br><br>HSSFRow&nbsp;row7&nbsp;=&nbsp;sheet1.CreateRow(6);<br>row7.CreateCell(0).SetCellValue(&#8220;\u5408\u683c\u4eba\u6570\uff1a&#8221;);<br>row7.CreateCell(1).SetCellFormula(&#8220;COUNTIF(B2:B6,\\&#8221;&gt;60\\&#8221;)&#8221;);<\/p>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cCountIf\u51fd\u6570\u6210\u529f\u7684\u7edf\u8ba1\u51fa\u4e86\u533a\u57df\u201cB2\uff1aB6\u201d\u4e2d\u6210\u7ee9\u5408\u683c\u7684\u4eba\u6570\uff08\u8fd9\u91cc\u5b9a\u4e49\u6210\u7ee9\u5927\u4e8e60\u4e3a\u5408\u683c\uff09\u3002<br><br><strong>\u4e8c\u3001SUMIF<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u63a5\u4e0b\u6765\uff0c\u987a\u4fbf\u8c08\u8c08\u53e6\u4e00\u4e2a\u4e0eCountIF\u7c7b\u4f3c\u7684\u51fd\u6570\u2014SumIf\u51fd\u6570\u3002\u6b64\u51fd\u6570\u7528\u4e8e\u7edf\u8ba1\u67d0\u533a\u57df\u5185\u6ee1\u8db3\u67d0\u6761\u4ef6\u7684\u503c\u7684\u6c42\u548c(CountIf\u662f\u8ba1\u6570)\u3002\u4e0eCountIF\u4e0d\u540c\uff0cSumIF\u6709\u4e09\u4e2a\u53c2\u6570\uff0c\u8bed\u6cd5\u4e3aSumIF(criteria_range, criteria,sum_range)\uff0c\u5404\u53c2\u6570\u7684\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>criteria_range<\/td><td>\u6761\u4ef6\u6d4b\u8bd5\u533a\u57df\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570Criteria\u4e2d\u7684\u6761\u4ef6\u5c06\u4e0e\u6b64\u533a\u57df\u4e2d\u7684\u503c\u8fdb\u884c\u6bd4\u8f83<\/td><\/tr><tr><td>criteria<\/td><td>\u6761\u4ef6\u6d4b\u8bd5\u503c\uff0c\u6ee1\u8db3\u6761\u4ef6\u7684\u5bf9\u5e94\u7684sum_range\u9879\u5c06\u8fdb\u884c\u6c42\u548c\u8ba1\u7b97<\/td><\/tr><tr><td>sum_range<\/td><td>\u6c47\u603b\u6570\u636e\u6240\u5728\u533a\u57df\uff0c\u6c42\u548c\u65f6\u4f1a\u6392\u9664\u6389\u4e0d\u6ee1\u8db3Criteria\u6761\u4ef6\u7684\u5bf9\u5e94\u7684\u9879<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>\u6211\u4eec\u8fd8\u662f\u4ee5\u4f8b\u5b50\u6765\u52a0\u4ee5\u8bf4\u660e\uff1a<\/p>\n\n\n\n<p>Code<br>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u6708\u4efd&#8221;);<br>row1.CreateCell(2).SetCellValue(&#8220;\u9500\u552e\u989d&#8221;);<br><br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row2.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>row2.CreateCell(1).SetCellValue(&#8220;\u4e00\u6708&#8221;);<br>row2.CreateCell(2).SetCellValue(1000);<br><br>HSSFRow&nbsp;row3&nbsp;=&nbsp;sheet1.CreateRow(2);<br>row3.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8&#8221;);<br>row3.CreateCell(1).SetCellValue(&#8220;\u4e00\u6708&#8221;);<br>row3.CreateCell(2).SetCellValue(900);<br><br>HSSFRow&nbsp;row4&nbsp;=&nbsp;sheet1.CreateRow(3);<br>row4.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>row4.CreateCell(1).SetCellValue(&#8220;\u4e8c\u6708&#8221;);<br>row4.CreateCell(2).SetCellValue(2000);<br><br>HSSFRow&nbsp;row5&nbsp;=&nbsp;sheet1.CreateRow(4);<br>row5.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8&#8221;);<br>row5.CreateCell(1).SetCellValue(&#8220;\u4e8c\u6708&#8221;);<br>row5.CreateCell(2).SetCellValue(1000);<br><br>HSSFRow&nbsp;row6&nbsp;=&nbsp;sheet1.CreateRow(5);<br>row6.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>row6.CreateCell(1).SetCellValue(&#8220;\u4e09\u6708&#8221;);<br>row6.CreateCell(2).SetCellValue(3000);<br><br>HSSFRow&nbsp;row7&nbsp;=&nbsp;sheet1.CreateRow(6);<br>row7.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8&#8221;);<br>row7.CreateCell(1).SetCellValue(&#8220;\u4e09\u6708&#8221;);<br>row7.CreateCell(2).SetCellValue(1200);<br><br>HSSFRow&nbsp;row8&nbsp;=&nbsp;sheet1.CreateRow(7);<br>row8.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2\u4e00\u5b63\u5ea6\u9500\u552e\u989d\uff1a&#8221;);<br>row8.CreateCell(2).SetCellFormula(&#8220;SUMIF(A2:A7,\\&#8221;=\u4ee4\u72d0\u51b2\\&#8221;,C2:C7)&#8221;);<br><br>HSSFRow&nbsp;row9&nbsp;=&nbsp;sheet1.CreateRow(8);<br>row9.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8\u4e00\u5b63\u5ea6\u9500\u552e\u989d\uff1a&#8221;);<br>row9.CreateCell(2).SetCellFormula(&#8220;SUMIF(A2:A7,\\&#8221;=\u4efb\u76c8\u76c8\\&#8221;,C2:C7)&#8221;);<\/p>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br><br>\u5982\u4e0a\u56fe\uff0cSUMIF\u7edf\u8ba1\u51fa\u4e86\u4e0d\u540c\u4eba\u4e00\u5b63\u5ea6\u7684\u9500\u552e\u989d\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575317.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.7\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0dLOOKUP\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4eca\u5929\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60Excel\u4e2d\u7684\u67e5\u8be2\u51fd\u6570\uff0d\uff0dLOOKUP\u3002\u5176\u57fa\u672c\u8bed\u6cd5\u5f62\u5f0f\u4e3aLOOKUP(lookup_value,lookup_vector,result_vector)\u3002\u8fd8\u662f\u4ee5\u4f8b\u5b50\u52a0\u4ee5\u8bf4\u660e\u66f4\u5bb9\u6613\u7406\u89e3\uff1a<\/p>\n\n\n\n<p>Code<br>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u6536\u5165\u6700\u4f4e&#8221;);<br>row1.CreateCell(1).SetCellValue(&#8220;\u6536\u5165\u6700\u9ad8&#8221;);<br>row1.CreateCell(2).SetCellValue(&#8220;\u7a0e\u7387&#8221;);<br><br>HSSFRow&nbsp;row2&nbsp;=&nbsp;sheet1.CreateRow(1);<br>row2.CreateCell(0).SetCellValue(0);<br>row2.CreateCell(1).SetCellValue(3000);<br>row2.CreateCell(2).SetCellValue(0.1);<br><br>HSSFRow&nbsp;row3&nbsp;=&nbsp;sheet1.CreateRow(2);<br>row3.CreateCell(0).SetCellValue(3001);<br>row3.CreateCell(1).SetCellValue(10000);<br>row3.CreateCell(2).SetCellValue(0.2);<br><br>HSSFRow&nbsp;row4&nbsp;=&nbsp;sheet1.CreateRow(3);<br>row4.CreateCell(0).SetCellValue(10001);<br>row4.CreateCell(1).SetCellValue(20000);<br>row4.CreateCell(2).SetCellValue(0.3);<br><br>HSSFRow&nbsp;row5&nbsp;=&nbsp;sheet1.CreateRow(4);<br>row5.CreateCell(0).SetCellValue(20001);<br>row5.CreateCell(1).SetCellValue(50000);<br>row5.CreateCell(2).SetCellValue(0.4);<br><br>HSSFRow&nbsp;row6&nbsp;=&nbsp;sheet1.CreateRow(5);<br>row6.CreateCell(0).SetCellValue(50001);<br>row6.CreateCell(2).SetCellValue(0.5);<br><br><br>HSSFRow&nbsp;row8&nbsp;=&nbsp;sheet1.CreateRow(7);<br>row8.CreateCell(0).SetCellValue(&#8220;\u6536\u5165&#8221;);<br>row8.CreateCell(1).SetCellValue(&#8220;\u7a0e\u7387&#8221;);<br><br>HSSFRow&nbsp;row9&nbsp;=&nbsp;sheet1.CreateRow(8);<br>row9.CreateCell(0).SetCellValue(7800);<br>row9.CreateCell(1).SetCellFormula(&#8220;LOOKUP(A9,$A$2:$A$6,$C$2:$C$6)&#8221;);<\/p>\n\n\n\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u662f\u4e00\u4e2a\u6839\u636e\u5de5\u8d44\u67e5\u8be2\u76f8\u5e94\u7a0e\u7387\u7684\u4f8b\u5b50\u3002\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e0d\u540c\u5de5\u8d44\u533a\u95f4\u5bf9\u5e94\u7a0e\u7387\u7684\u5b57\u5178\uff0c\u7136\u540e\u6839\u636e\u5177\u4f53\u7684\u5de5\u8d44\u5728\u5b57\u5178\u4e2d\u627e\u51fa\u5bf9\u5e94\u7684\u7a0e\u7387\u3002\u6267\u884c\u540e\u751f\u6210\u7684Excel\u5982\u4e0b\uff1a<br>&nbsp;<br>\u4e0b\u9762\u5bf9\u5404\u53c2\u6570\u52a0\u4ee5\u8bf4\u660e\uff1a<br>\u7b2c\u4e00\u4e2a\u53c2\u6570\uff1a\u9700\u8981\u67e5\u627e\u7684\u5185\u5bb9\uff0c\u672c\u4f8b\u4e2d\u6307\u5411A9\u5355\u5143\u683c\uff0c\u4e5f\u5c31\u662f7800\uff1b<br>\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff1a\u6bd4\u8f83\u5bf9\u8c61\u533a\u57df\uff0c\u672c\u4f8b\u4e2d\u7684\u5de5\u8d44\u9700\u8981\u4e0e$A$2:$A$6\u4e2d\u7684\u5404\u5355\u5143\u683c\u4e2d\u7684\u503c\u8fdb\u884c\u6bd4\u8f83\uff1b\u7b2c\u4e09\u4e2a\u53c2\u6570\uff1a\u67e5\u627e\u7ed3\u679c\u533a\u57df\uff0c\u5982\u679c\u5339\u914d\u5230\u4f1a\u5c06\u6b64\u533a\u57df\u4e2d\u5bf9\u5e94\u7684\u6570\u636e\u8fd4\u56de\u3002\u5982\u672c\u4f8b\u4e2d\u8fd4\u56de$C$2:$C$6\u4e2d\u5bf9\u5e94\u7684\u503c\u3002<br>\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff0c\u5b57\u5178\u4e2d\u6ca1\u67097800\u5bf9\u5e94\u7684\u7a0e\u7387\u554a\uff0c\u90a3\u4e48Excel\u4e2d\u600e\u4e48\u5339\u914d\u7684\u5462\uff1f\u7b54\u6848\u662f\u6a21\u7cca\u5339\u914d\uff0c\u5e76\u4e14LOOKUP\u51fd\u6570\u53ea\u652f\u6301\u6a21\u7cca\u5339\u914d\u3002Excel\u4f1a\u5728$A$2:$A$6\u4e2d\u627e\u5c0f\u4e8e7800\u7684\u6700\u5927\u503c\uff0c\u4e5f\u5c31\u662fA3\u5bf9\u5e94\u76843001\uff0c\u7136\u540e\u5c06\u5bf9\u5e94\u7684$C$2:$C$6\u533a\u57df\u4e2d\u7684C3\u4e2d\u7684\u503c\u8fd4\u56de\uff0c\u8fd9\u5c31\u662f\u6700\u7ec8\u7ed3\u679c0.2\u7684\u7531\u6765\u3002\u8fd9\u4e0b\u660e\u767d\u4e86\u5427\uff1a\uff09<br><br><strong>VLOOKUP<br><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u53e6\u5916\uff0cLOOKUP\u51fd\u6570\u8fd8\u6709\u4e00\u4f4d\u5927\u54e5\uff0d\uff0dVLOOKUP\u3002\u4e24\u5144\u5f1f\u6709\u5f88\u591a\u76f8\u4f3c\u4e4b\u5904\uff0c\u4f46\u5927\u54e5\u672c\u9886\u66f4\u5927\u3002Vlookup\u7528\u5bf9\u6bd4\u6570\u4e0e\u4e00\u4e2a\u201c\u8868\u201d\u8fdb\u884c\u5bf9\u6bd4\uff0c\u800c\u4e0d\u662fLookup\u51fd\u6570\u7684\u67d01\u5217\u62161\u884c\uff0c\u5e76\u4e14Vlookup\u53ef\u4ee5\u9009\u62e9\u91c7\u7528\u7cbe\u786e\u67e5\u8be2\u6216\u662f\u6a21\u7cca\u67e5\u8be2\u65b9\u5f0f\uff0c\u800cLookup\u53ea\u6709\u6a21\u7cca\u67e5\u8be2\u3002<br>\u5c06\u4e0a\u4f8b\u4e2d\u8bbe\u7f6e\u516c\u5f0f\u7684\u4ee3\u7801\u6362\u6210\uff1a<\/p>\n\n\n\n<p>row9.CreateCell(1).SetCellFormula(&#8220;VLOOKUP(A9,$A$2:$C$6,3,TRUE)&#8221;);<\/p>\n\n\n\n<p>\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6837\u5f0f\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p>\u7b2c\u4e00\u4e2a\u53c2\u6570\uff1a\u9700\u8981\u67e5\u627e\u7684\u5185\u5bb9\uff0c\u8fd9\u91cc\u662fA9\u5355\u5143\u683c\uff1b<br>\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff1a\u9700\u8981\u6bd4\u8f83\u7684\u8868\uff0c\u8fd9\u91cc\u662f$A$2:$C$6\uff0c\u6ce8\u610fVLOOKUP\u5339\u914d\u65f6\u53ea\u4e0e\u8868\u4e2d\u7684\u7b2c\u4e00\u5217\u8fdb\u884c\u5339\u914d\u3002<br>\u7b2c\u4e09\u4e2a\u53c2\u6570\uff1a\u5339\u914d\u7ed3\u679c\u5bf9\u5e94\u7684\u5217\u5e8f\u53f7\u3002\u8fd9\u91cc\u8981\u5bf9\u5e94\u7684\u662f\u7a0e\u7387\u5217\uff0c\u6240\u4ee5\u4e3a3\u3002<br>\u7b2c\u56db\u4e2a\u53c2\u6570\uff1a\u6307\u660e\u662f\u5426\u6a21\u7cca\u5339\u914d\u3002\u4f8b\u5b50\u4e2d\u7684TRUE\u8868\u793a\u6a21\u7cca\u5339\u914d\uff0c\u4e0e\u4e0a\u4f8b\u4e2d\u4e00\u6837\u3002\u5339\u914d\u5230\u7684\u662f\u7b2c\u4e09\u884c\u3002\u5982\u679c\u5c06\u6b64\u53c2\u6570\u6539\u4e3aFALSE\uff0c\u56e0\u4e3a\u5728\u8868\u4e2d\u7684\u7b2c1\u5217\u4e2d\u627e\u4e0d\u52307800\uff0c\u6240\u4ee5\u4f1a\u62a5\u201c#N\/A\u201d\u7684\u8ba1\u7b97\u9519\u8bef\u3002<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u53e6\u5916\uff0c\u8fd8\u6709\u4e0eVLOKUP\u7c7b\u4f3c\u7684HLOOKUP\u3002\u4e0d\u540c\u7684\u662fVLOOKUP\u7528\u4e8e\u5728\u8868\u683c\u6216\u6570\u503c\u6570\u7ec4\u7684\u9996\u5217\u67e5\u627e\u6307\u5b9a\u7684\u6570\u503c\uff0c\u5e76\u7531\u6b64\u8fd4\u56de\u8868\u683c\u6216\u6570\u7ec4\u5f53\u524d\u884c\u4e2d\u6307\u5b9a\u5217\u5904\u7684\u6570\u503c\u3002\u800cHLOOKUP\u7528\u4e8e\u5728\u8868\u683c\u6216\u6570\u503c\u6570\u7ec4\u7684\u9996\u884c\u67e5\u627e\u6307\u5b9a\u7684\u6570\u503c\uff0c\u5e76\u7531\u6b64\u8fd4\u56de\u8868\u683c\u6216\u6570\u7ec4\u5f53\u524d\u5217\u4e2d\u6307\u5b9a\u884c\u5904\u7684\u6570\u503c\u3002\u8bfb\u8005\u53ef\u4ee5\u81ea\u5df2\u53bb\u5c1d\u8bd5\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575327.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.8\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u968f\u673a\u6570\u51fd\u6570<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u4eec\u77e5\u9053\uff0c\u5728\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\u90fd\u6709\u968f\u673a\u6570\u51fd\u6570\u3002\u5728Excel\u4e2d\uff0c\u540c\u6837\u5b58\u5728\u7740\u8fd9\u6837\u4e00\u4e2a\u51fd\u6570\u2014RAND()\u51fd\u6570\uff0c\u7528\u4e8e\u751f\u6210\u968f\u673a\u6570\u3002\u5148\u6765\u770b\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;RAND()&#8221;);<\/p>\n\n\n\n<p>RAND()\u51fd\u6570\u5c06\u8fd4\u56de\u4e00\u4e2a0-1\u4e4b\u95f4\u7684\u968f\u673a\u6570\uff0c\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6587\u4ef6\u5982\u4e0b\uff1a<br><br>\u8fd9\u53ea\u662f\u6700\u7b80\u5355\u76f4\u63a5\u7684RAND()\u51fd\u6570\u7684\u5e94\u7528\uff0c\u53ea\u8981\u6211\u4eec\u7a0d\u52a0\u4fee\u6539\uff0c\u5c31\u53ef\u4ee5\u4f5c\u51fa\u5f88\u591a\u79cd\u53d8\u6362\u3002\u5982<br>\u53d60-100\u4e4b\u524d\u7684\u968f\u673a\u6574\u6570\uff0c\u53ef\u8bbe\u7f6e\u516c\u5f0f\u4e3a\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;int(RAND()*100)&#8221;);<\/p>\n\n\n\n<p>\u53d610-20\u4e4b\u95f4\u7684\u968f\u673a\u5b9e\u6570\uff0c\u53ef\u8bbe\u7f6e\u516c\u5f0f\u4e3a\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;rand()*(20-10)+10&#8221;);<\/p>\n\n\n\n<p>\u968f\u673a\u5c0f\u5199\u5b57\u6bcd\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;CHAR(INT(RAND()*26)+97)&#8221;);<\/p>\n\n\n\n<p>\u968f\u673a\u5927\u5199\u5b57\u6bcd\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;CHAR(INT(RAND()*26)+65)&#8221;)<\/p>\n\n\n\n<p>\u968f\u673a\u5927\u5c0f\u5199\u5b57\u6bcd\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(0).SetCellFormula(&#8220;CHAR(INT(RAND()*26)+if(INT(RAND()*2)=0,65,97))&#8221;);<\/p>\n\n\n\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4e0a\u9762\u51e0\u4f8b\u4e2d\u9664\u4e86\u7528\u5230RAND\u51fd\u6570\u4ee5\u5916\uff0c\u8fd8\u7528\u5230\u4e86CHAR\u51fd\u6570\u7528\u6765\u5c06ASCII\u7801\u6362\u4e3a\u5b57\u6bcd\uff0cINT\u51fd\u6570\u7528\u6765\u53d6\u6574\u3002\u503c\u5f97\u6ce8\u610f\u7684\u662fINT\u51fd\u6570\u4e0d\u4f1a\u56db\u820d\u4e94\u5165\uff0c\u65e0\u8bba\u5c0f\u6570\u70b9\u540e\u662f\u591a\u5c11\u90fd\u4f1a\u88ab\u820d\u53bb\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u91cc\u53ea\u662fRAND\u51fd\u6570\u7684\u51e0\u4e2a\u7b80\u5355\u5e94\u7528\uff0c\u8fd8\u6709\u5f88\u591a\u968f\u673a\u6570\u7684\u4f8b\u5b50\u90fd\u53ef\u4ee5\u6839\u636e\u8fd9\u4e9b\uff0c\u518d\u7ed3\u5408\u4e0d\u540c\u7684\u5176\u5b83\u51fd\u6570\u5f15\u7533\u51fa\u6765\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/12\/1582085.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.3.9\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u901a\u8fc7NPOI\u83b7\u5f97\u516c\u5f0f\u7684\u8fd4\u56de\u503c<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u524d\u9762\u6211\u4eec\u5b66\u4e60\u4e86\u901a\u8fc7NPOI\u5411Excel\u4e2d\u8bbe\u7f6e\u516c\u5f0f\uff0c\u90a3\u4e48\u6709\u4e9b\u8bfb\u8005\u53ef\u80fd\u4f1a\u95ee\uff1a\u201cNPOI\u80fd\u4e0d\u80fd\u83b7\u53d6\u516c\u5f0f\u7684\u8fd4\u56de\u503c\u5462\uff1f\u201d\uff0c\u7b54\u6848\u662f\u53ef\u4ee5\uff01<br><strong>\u4e00\u3001\u83b7\u53d6\u6a21\u677f\u6587\u4ef6\u4e2d\u516c\u5f0f\u7684\u8fd4\u56de\u503c<br><\/strong>\u5982\u5728D\u76d8\u4e2d\u6709\u4e00\u4e2a\u540d\u4e3atext.xls\u7684Excel\u6587\u4ef6\uff0c\u5176\u5185\u5bb9\u5982\u4e0b\uff1a<br><br>\u6ce8\u610fC1\u5355\u5143\u683c\u4e2d\u8bbe\u7f6e\u7684\u662f\u516c\u5f0f\u201c$A1*$B1\u201d\uff0c\u800c\u4e0d\u662f\u503c\u201c12\u201d\u3002\u5229\u7528NPOI\uff0c\u53ea\u9700\u8981\u5199\u7b80\u5355\u7684\u51e0\u53e5\u4ee3\u7801\u5c31\u53ef\u4ee5\u53d6\u5f97\u6b64\u516c\u5f0f\u7684\u8fd4\u56de\u503c\uff1a<\/p>\n\n\n\n<p>HSSFWorkbook&nbsp;wb&nbsp;=&nbsp;new&nbsp;HSSFWorkbook(new&nbsp;FileStream(&#8220;d:\/test.xls&#8221;,FileMode.Open));<br>HSSFCell&nbsp;cell&nbsp;=&nbsp;wb.GetSheet(&#8220;Sheet1&#8221;).GetRow(0).GetCell(2);<br>System.Console.WriteLine(cell.NumericCellValue);<\/p>\n\n\n\n<p>\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<br><br>\u53ef\u89c1NPOI\u6210\u529f\u7684\u201c\u89e3\u6790\u201d\u4e86\u6b64.xls\u6587\u4ef6\u4e2d\u7684\u516c\u5f0f\u3002\u6ce8\u610fNumericCellValue\u5c5e\u6027\u4f1a\u81ea\u52a8\u6839\u636e\u5355\u5143\u683c\u7684\u7c7b\u578b\u5904\u7406\uff0c\u5982\u679c\u4e3a\u7a7a\u5c06\u8fd40\uff0c\u5982\u679c\u4e3a\u6570\u503c\u5c06\u8fd4\u56de\u6570\u503c\uff0c\u5982\u679c\u4e3a\u516c\u5f0f\u5c06\u8fd4\u56de\u516c\u5f0f\u8ba1\u7b97\u540e\u7684\u7ed3\u679c\u3002\u5355\u5143\u683c\u7684\u7c7b\u578b\u53ef\u4ee5\u901a\u8fc7CellType\u5c5e\u6027\u83b7\u53d6\u3002<br><br><strong>\u4e8c\u3001\u83b7\u53d6NPOI\u751f\u6210\u7684Excel\u6587\u4ef6\u4e2d\u516c\u5f0f\u7684\u8fd4\u56de\u503c<br><\/strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4e0a\u4f8b\u4e2d\u662f\u4ece\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684Excel\u6587\u4ef6\u4e2d\u83b7\u53d6\u516c\u5f0f\u7684\u8fd4\u56de\u503c\uff0c\u90a3\u4e48\u5982\u679cExcel\u6587\u4ef6\u662f\u901a\u8fc7NPOI\u521b\u5efa\u7684\uff0c\u76f4\u63a5\u7528\u4e0a\u9762\u7684\u65b9\u6cd5\u83b7\u53d6\uff0c\u53ef\u80fd\u5f97\u4e0d\u5230\u60f3\u8981\u7684\u7ed3\u679c\u3002\u5982\uff1a<\/p>\n\n\n\n<p>1&nbsp;HSSFWorkbook&nbsp;hssfworkbook&nbsp;=&nbsp;new&nbsp;HSSFWorkbook();<br>2&nbsp;HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>3&nbsp;HSSFRow&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(0);<br>4&nbsp;row.CreateCell(0).SetCellValue(3);<br>5&nbsp;row.CreateCell(1).SetCellValue(4);<br>6&nbsp;HSSFCell&nbsp;cell&nbsp;=&nbsp;row.CreateCell(2);<br>7&nbsp;<br>8&nbsp;cell.SetCellFormula(&#8220;$A1+$B1&#8221;);<br>9&nbsp;System.Console.WriteLine(cell.NumericCellValue);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6267\u884c\u4e0a\u9762\u4ee3\u7801\uff0c\u5c06\u8f93\u51fa\u7ed3\u679c\u201c0\u201d\uff0c\u800c\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u7ed3\u679c\u201c7\u201d\u3002\u90a3\u4e48\u5c06\u5982\u4f55\u89e3\u51b3\u5462\uff1f\u8fd9\u65f6\u8981\u7528\u5230HSSFFormulaEvaluator\u7c7b\u3002\u5728\u7b2c8\u884c\u540e\u52a0\u4e0a\u8fd9\u4e24\u53e5\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n\n\n\n<p>HSSFFormulaEvaluator&nbsp;e&nbsp;=&nbsp;new&nbsp;HSSFFormulaEvaluator(hssfworkbook);<br>cell&nbsp;=&nbsp;e.EvaluateInCell(cell);<\/p>\n\n\n\n<p>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565645.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.1\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u753b\u7ebf<\/strong><\/p>\n\n\n\n<p>\u4e4b\u6240\u6709\u8bf4NPOI\u5f3a\u5927\uff0c\u662f\u56e0\u4e3a\u5e38\u7528\u7684Excel\u64cd\u4f5c\u5979\u90fd\u53ef\u4ee5\u901a\u8fc7\u7f16\u7a0b\u7684\u65b9\u5f0f\u5b8c\u6210\u3002\u8fd9\u8282\u5f00\u59cb\uff0c\u6211\u4eec\u5f00\u59cb\u5b66\u4e60NPOI\u7684\u753b\u56fe\u529f\u80fd\u3002\u5148\u4ece\u6700\u7b80\u5355\u7684\u5f00\u59cb\uff0c\u753b\u4e00\u6761\u76f4\u7ebf\uff1a<br><br>\u5bf9\u5e94\u7684\u4ee3\u7801\u4e3a\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>HSSFClientAnchor&nbsp;a1&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(255,&nbsp;125,&nbsp;1023,&nbsp;150,&nbsp;0,&nbsp;0,2,&nbsp;2);<br>HSSFSimpleShape&nbsp;line1&nbsp;=&nbsp;patriarch.CreateSimpleShape(a1);<br><br>line1.ShapeType&nbsp;=&nbsp;HSSFSimpleShape.OBJECT_TYPE_LINE;<br>line1.LineStyle&nbsp;=&nbsp;HSSFShape.LINESTYLE_SOLID;<br>\/\/\u5728NPOI\u4e2d\u7ebf\u7684\u5bbd\u5ea612700\u8868\u793a1pt,\u6240\u4ee5\u8fd9\u91cc\u662f0.5pt\u7c97\u7684\u7ebf\u6761\u3002<br>line1.LineWidth&nbsp;=&nbsp;6350;<\/p>\n\n\n\n<p>\u901a\u5e38\uff0c\u5229\u7528NPOI\u753b\u56fe\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<br>1.&nbsp;\u521b\u5efa\u4e00\u4e2aPatriarch\uff1b<br>2.&nbsp;\u521b\u5efa\u4e00\u4e2aAnchor\uff0c\u4ee5\u786e\u5b9a\u56fe\u5f62\u7684\u4f4d\u7f6e\uff1b<br>3.&nbsp;\u8c03\u7528Patriarch\u521b\u5efa\u56fe\u5f62\uff1b<br>4.&nbsp;\u8bbe\u7f6e\u56fe\u5f62\u7c7b\u578b(\u76f4\u7ebf\uff0c\u77e9\u5f62\uff0c\u5706\u5f62\u7b49)\u53ca\u6837\u5f0f\uff08\u989c\u8272\uff0c\u7c97\u7ec6\u7b49\uff09\u3002<\/p>\n\n\n\n<p>\u5173\u4e8eHSSFClientAnchor(dx1,dy1,dx2,dy2,col1,row1,col2,row2)\u7684\u53c2\u6570\uff0c\u6709\u5fc5\u8981\u5728\u8fd9\u91cc\u8bf4\u660e\u4e00\u4e0b\uff1a<br>dx1\uff1a\u8d77\u59cb\u5355\u5143\u683c\u7684x\u504f\u79fb\u91cf\uff0c\u5982\u4f8b\u5b50\u4e2d\u7684255\u8868\u793a\u76f4\u7ebf\u8d77\u59cb\u4f4d\u7f6e\u8dddA1\u5355\u5143\u683c\u5de6\u4fa7\u7684\u8ddd\u79bb\uff1b<br>dy1\uff1a\u8d77\u59cb\u5355\u5143\u683c\u7684y\u504f\u79fb\u91cf\uff0c\u5982\u4f8b\u5b50\u4e2d\u7684125\u8868\u793a\u76f4\u7ebf\u8d77\u59cb\u4f4d\u7f6e\u8dddA1\u5355\u5143\u683c\u4e0a\u4fa7\u7684\u8ddd\u79bb\uff1b<br>dx2\uff1a\u7ec8\u6b62\u5355\u5143\u683c\u7684x\u504f\u79fb\u91cf\uff0c\u5982\u4f8b\u5b50\u4e2d\u76841023\u8868\u793a\u76f4\u7ebf\u8d77\u59cb\u4f4d\u7f6e\u8dddC3\u5355\u5143\u683c\u5de6\u4fa7\u7684\u8ddd\u79bb\uff1b<br>dy2\uff1a\u7ec8\u6b62\u5355\u5143\u683c\u7684y\u504f\u79fb\u91cf\uff0c\u5982\u4f8b\u5b50\u4e2d\u7684150\u8868\u793a\u76f4\u7ebf\u8d77\u59cb\u4f4d\u7f6e\u8dddC3\u5355\u5143\u683c\u4e0a\u4fa7\u7684\u8ddd\u79bb\uff1b<br>col1\uff1a\u8d77\u59cb\u5355\u5143\u683c\u5217\u5e8f\u53f7\uff0c\u4ece0\u5f00\u59cb\u8ba1\u7b97\uff1b<br>row1\uff1a\u8d77\u59cb\u5355\u5143\u683c\u884c\u5e8f\u53f7\uff0c\u4ece0\u5f00\u59cb\u8ba1\u7b97\uff0c\u5982\u4f8b\u5b50\u4e2dcol1=0,row1=0\u5c31\u8868\u793a\u8d77\u59cb\u5355\u5143\u683c\u4e3aA1\uff1b<br>col2\uff1a\u7ec8\u6b62\u5355\u5143\u683c\u5217\u5e8f\u53f7\uff0c\u4ece0\u5f00\u59cb\u8ba1\u7b97\uff1b<br>row2\uff1a\u7ec8\u6b62\u5355\u5143\u683c\u884c\u5e8f\u53f7\uff0c\u4ece0\u5f00\u59cb\u8ba1\u7b97\uff0c\u5982\u4f8b\u5b50\u4e2dcol2=2,row2=2\u5c31\u8868\u793a\u8d77\u59cb\u5355\u5143\u683c\u4e3aC3\uff1b<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u5173\u4e8eLineStyle\u5c5e\u6027\uff0c\u6709\u5982\u4e0b\u4e00\u4e9b\u53ef\u9009\u503c\uff0c\u5bf9\u5e94\u7684\u6548\u679c\u5206\u522b\u5982\u56fe\u6240\u793a\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565901.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.2\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u753b\u77e9\u5f62<\/strong><\/p>\n\n\n\n<p>\u4e0a\u4e00\u8282\u6211\u4eec\u8bb2\u4e86NPOI\u4e2d\u753b\u56fe\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<br>1.&nbsp;\u521b\u5efa\u4e00\u4e2aPatriarch\uff1b<br>2.&nbsp;\u521b\u5efa\u4e00\u4e2aAnchor\uff0c\u4ee5\u786e\u5b9a\u56fe\u5f62\u7684\u4f4d\u7f6e\uff1b<br>3.&nbsp;\u8c03\u7528Patriarch\u521b\u5efa\u56fe\u5f62\uff1b<br>4.&nbsp;\u8bbe\u7f6e\u56fe\u5f62\u7c7b\u578b(\u76f4\u7ebf\uff0c\u77e9\u5f62\uff0c\u5706\u5f62\u7b49)\u53ca\u6837\u5f0f\uff08\u989c\u8272\uff0c\u7c97\u7ec6\u7b49\uff09\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e00\u8282\u6211\u4eec\u5c06\u6309\u7167\u8fd9\u4e2a\u6b65\u9aa4\u521b\u5efa\u4e00\u4e2a\u77e9\u5f62\u3002\u5e9f\u8bdd\u5c11\u8bf4\uff0c\u4e0a\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>HSSFClientAnchor&nbsp;a1&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(255,&nbsp;125,&nbsp;1023,&nbsp;150,&nbsp;0,&nbsp;0,&nbsp;2,&nbsp;2);<br>HSSFSimpleShape&nbsp;rec1&nbsp;=&nbsp;patriarch.CreateSimpleShape(a1);<br>\/\/\u6b64\u5904\u8bbe\u7f6e\u56fe\u5f62\u7c7b\u578b\u4e3a\u77e9\u5f62<br>rec1.ShapeType&nbsp;=&nbsp;HSSFSimpleShape.OBJECT_TYPE_RECTANGLE;<br>\/\/\u8bbe\u7f6e\u586b\u5145\u8272<br>rec1.SetFillColor(125,&nbsp;125,&nbsp;125);<br>\/\/\u8bbe\u7f6e\u8fb9\u6846\u6837\u5f0f<br>rec1.LineStyle&nbsp;=&nbsp;HSSFShape.LINESTYLE_DASHGEL;<br>\/\/\u8bbe\u7f6e\u8fb9\u6846\u5bbd\u5ea6<br>rec1.LineWidth&nbsp;=&nbsp;25400;<br>\/\/\u8bbe\u7f6e\u8fb9\u6846\u989c\u8272<br>rec1.SetLineStyleColor(100,&nbsp;0,&nbsp;100);<\/p>\n\n\n\n<p>\u4ee3\u7801\u6267\u884c\u6548\u679c\uff1a<br>&nbsp;<br>\u5176\u4e2dSetFillColor\u548cSetLineStyleColor\u51fd\u6570\u7684\u4e09\u4e2a\u53c2\u6570\u5206\u522b\u662fRGB\u4e09\u8272\u503c\uff0c\u5177\u4f53\u8868\u793a\u4ec0\u4e48\u989c\u8272\uff0c\u627e\u4e2aPhotoshop\u8bd5\u8bd5\uff1a\uff09<br>\u5173\u4e8eHSSFClientAnchor\u53c2\u6570\u8bf4\u660e\u3001\u8fb9\u6846\u6837\u5f0f\uff0c\u8fb9\u6846\u5bbd\u5ea6\u7684\u8bf4\u660e\u53ef\u4ee5\u53c2\u89c1\u524d\u4e00\u7bc7\u535a\u6587\uff1a<br><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565645.html\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565645.html<\/a><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/27\/1575309.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.3\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u753b\u5706\u5f62<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u524d\u9762\u6211\u4eec\u5b66\u4e60\u4e86NPOI\u4e2d\u7684\u753b\u7b80\u5355\u76f4\u7ebf\u548c\u77e9\u5f62\u7684\u529f\u80fd\uff0c\u4eca\u5929\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\u4e00\u4e0b\u5b83\u652f\u6301\u7684\u53e6\u4e00\u79cd\u7b80\u5355\u56fe\u5f62\uff0d\uff0d\u5706\u5f62\u3002\u540c\u6837\uff0c\u6309\u7167\u524d\u9762\u6240\u8bb2\u7684\u7ed8\u56fe\u201c\u56db\u6b65\u66f2\u201d\uff1a<br>1.&nbsp;\u521b\u5efa\u4e00\u4e2aPatriarch\uff1b<br>2.&nbsp;\u521b\u5efa\u4e00\u4e2aAnchor\uff0c\u4ee5\u786e\u5b9a\u56fe\u5f62\u7684\u4f4d\u7f6e\uff1b<br>3.&nbsp;\u8c03\u7528Patriarch\u521b\u5efa\u56fe\u5f62\uff1b<br>4.&nbsp;\u8bbe\u7f6e\u56fe\u5f62\u7c7b\u578b(\u76f4\u7ebf\uff0c\u77e9\u5f62\uff0c\u5706\u5f62\u7b49)\u53ca\u6837\u5f0f\uff08\u989c\u8272\uff0c\u7c97\u7ec6\u7b49\uff09\u3002<br>\u8fd8\u662f\u4ee5\u4f8b\u5b50\u52a0\u4ee5\u8bf4\u660e\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>HSSFClientAnchor&nbsp;a1&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(0,&nbsp;0,&nbsp;1023,&nbsp;0,&nbsp;0,&nbsp;0,&nbsp;1,&nbsp;3);<br>HSSFSimpleShape&nbsp;rec1&nbsp;=&nbsp;patriarch.CreateSimpleShape(a1);<br>rec1.ShapeType&nbsp;=&nbsp;HSSFSimpleShape.OBJECT_TYPE_OVAL;<br><br>rec1.SetFillColor(125,&nbsp;125,&nbsp;125);<br>rec1.LineStyle&nbsp;=&nbsp;HSSFShape.LINESTYLE_DASHGEL;<br>rec1.LineWidth&nbsp;=&nbsp;12700;<br>rec1.SetLineStyleColor(100,&nbsp;0,&nbsp;100);<br>WriteToFile();<\/p>\n\n\n\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u91ccrec1.ShapeType =HSSFSimpleShape.OBJECT_TYPE_OVAL;\u8868\u793a\u56fe\u5f62\u4e3a\u692d\u5706\u3002\u9002\u5f53\u8c03\u6574HSSFClientAnchor\u7684\u5404\u53c2\u6570\u53ef\u4ee5\u5f97\u5230\u5706\u5f62\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5173\u4e8eHSSFClientAnchor\u6784\u9020\u51fd\u6570\u548c\u8fb9\u6846\u3001\u586b\u5145\u8272\u7b49\u524d\u4e24\u8282\u90fd\u6709\u4ecb\u7ecd\uff0c\u8fd9\u91cc\u4e0d\u518d\u91cd\u8ff0\u3002\u8be6\u60c5\u60c5\u89c1\uff1a<a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565901.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u753b\u77e9\u5f62<\/a>\u548c<a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/13\/1565645.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u753b\u7ebf<\/a>\u3002<br><br>\u4e0a\u9762\u4ee3\u7801\u6267\u884c\u751f\u6210\u7684Excel\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/25\/1589570.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.4\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u753bGrid<\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u5728NPOI\u4e2d\uff0c\u672c\u8eab\u6ca1\u6709\u753bGrid\u7684\u65b9\u6cd5\u3002\u4f46\u6211\u4eec\u77e5\u9053Grid\u5176\u5b9e\u5c31\u662f\u7531\u6a2a\u7ebf\u548c\u7ad6\u7ebf\u6784\u6210\u7684\uff0c\u6240\u5728\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u753b\u7ebf\u7684\u65b9\u5f0f\u6765\u6a21\u62df\u753bGrid\u3002<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(2);<br>row.CreateCell(1);<br>row.HeightInPoints&nbsp;=&nbsp;240;<br>sheet1.SetColumnWidth(2,&nbsp;9000);<br>int&nbsp;linesCount&nbsp;=&nbsp;20;<br><br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>\/\/\u56e0\u4e3aHSSFClientAnchor\u4e2ddx\u53ea\u80fd\u57280-1023\u4e4b\u95f4,dy\u53ea\u80fd\u57280-255\u4e4b\u95f4\uff0c\u6240\u4ee5\u8fd9\u91cc\u91c7\u7528\u6bd4\u4f8b\u7684\u65b9\u5f0f<br>double&nbsp;xRatio&nbsp;=&nbsp;1023.0&nbsp;\/&nbsp;(linesCount*10);<br>double&nbsp;yRatio&nbsp;=&nbsp;255.0&nbsp;\/&nbsp;(linesCount*10);<br><br>\/\/\u753b\u7ad6\u7ebf<br>int&nbsp;x1&nbsp;=&nbsp;0;<br>int&nbsp;y1&nbsp;=&nbsp;0;<br>int&nbsp;x2&nbsp;=&nbsp;0;<br>int&nbsp;y2&nbsp;=&nbsp;200;<br>for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;linesCount;&nbsp;i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFClientAnchor&nbsp;a2&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor();<br>&nbsp;&nbsp;&nbsp;&nbsp;a2.SetAnchor((short)2,&nbsp;2,&nbsp;(int)(x1&nbsp;*&nbsp;xRatio),&nbsp;(int)(y1&nbsp;*&nbsp;yRatio),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(short)2,&nbsp;2,&nbsp;(int)(x2&nbsp;*&nbsp;xRatio),&nbsp;(int)(y2&nbsp;*&nbsp;yRatio));<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFSimpleShape&nbsp;shape2&nbsp;=&nbsp;patriarch.CreateSimpleShape(a2);<br>&nbsp;&nbsp;&nbsp;&nbsp;shape2.ShapeType&nbsp;=&nbsp;(HSSFSimpleShape.OBJECT_TYPE_LINE);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;x1&nbsp;+=&nbsp;10;<br>&nbsp;&nbsp;&nbsp;&nbsp;x2&nbsp;+=&nbsp;10;<br>}<br><br>\/\/\u753b\u6a2a\u7ebf<br>x1&nbsp;=&nbsp;0;<br>y1&nbsp;=&nbsp;0;<br>x2&nbsp;=&nbsp;200;<br>y2&nbsp;=&nbsp;0;<br>for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;linesCount;&nbsp;i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFClientAnchor&nbsp;a2&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor();<br>&nbsp;&nbsp;&nbsp;&nbsp;a2.SetAnchor((short)2,&nbsp;2,&nbsp;(int)(x1&nbsp;*&nbsp;xRatio),&nbsp;(int)(y1&nbsp;*&nbsp;yRatio),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(short)2,&nbsp;2,&nbsp;(int)(x2&nbsp;*&nbsp;xRatio),&nbsp;(int)(y2&nbsp;*&nbsp;yRatio));<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFSimpleShape&nbsp;shape2&nbsp;=&nbsp;patriarch.CreateSimpleShape(a2);<br>&nbsp;&nbsp;&nbsp;&nbsp;shape2.ShapeType&nbsp;=&nbsp;(HSSFSimpleShape.OBJECT_TYPE_LINE);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;y1&nbsp;+=&nbsp;10;<br>&nbsp;&nbsp;&nbsp;&nbsp;y2&nbsp;+=&nbsp;10;<br>}<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610fHSSFClientAnchor\u5bf9\u8c61\u4e2d\u7684dx\u53ea\u80fd\u53d60-1023\u4e4b\u95f4\u7684\u6570\uff0cdy\u53ea\u80fd\u53d60-255\u4e4b\u95f4\u7684\u6570\u3002\u6211\u4eec\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u5c06\u5355\u5143\u683c\u7684\u5bbd\u548c\u9ad8\u5e73\u5206\u6210\u4e861023\u548c255\u4efd\uff0c\u8bbe\u7f6edx\u548cdy\u65f6\u76f8\u5f53\u4e8e\u6309\u6bd4\u4f8b\u53d6\u5bf9\u5e94\u7684\u5ea7\u6807\u3002\u6700\u7ec8\u751f\u6210\u7684Excel\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/28\/1576044.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.4.5\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u63d2\u5165\u56fe\u7247<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u4eec\u77e5\u9053\uff0c\u5728Excel\u4e2d\u662f\u53ef\u4ee5\u63d2\u5165\u56fe\u7247\u7684\u3002\u64cd\u4f5c\u83dc\u5355\u662f\u201c\u63d2\u5165\uff0d&gt;\u56fe\u7247\u201d\uff0c\u7136\u540e\u9009\u62e9\u8981\u63d2\u5165\u56fe\u7247\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u5728Excel\u63d2\u5165\u56fe\u7247\u3002\u540c\u6837\uff0c\u5728NPOI\u4e2d\uff0c\u5229\u7528\u4ee3\u7801\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u540c\u6837\u7684\u6548\u679c\u3002\u5728NPOI\u4e2d\u63d2\u5165\u56fe\u7247\u7684\u65b9\u6cd5\u4e0e\u753b\u56fe\u7684\u65b9\u6cd5\u6709\u70b9\u7c7b\u4f3c\uff1a<\/p>\n\n\n\n<p>\/\/add&nbsp;picture&nbsp;data&nbsp;to&nbsp;this&nbsp;workbook.<br>byte[]&nbsp;bytes&nbsp;=&nbsp;System.IO.File.ReadAllBytes(@&#8221;D:\\MyProject\\NPOIDemo\\ShapeImage\\image1.jpg&#8221;);<br>int&nbsp;pictureIdx&nbsp;=&nbsp;hssfworkbook.AddPicture(bytes,&nbsp;HSSFWorkbook.PICTURE_TYPE_JPEG);<br><br>\/\/create&nbsp;sheet<br>HSSFSheet&nbsp;sheet&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>\/\/&nbsp;Create&nbsp;the&nbsp;drawing&nbsp;patriarch.&nbsp;&nbsp;This&nbsp;is&nbsp;the&nbsp;top&nbsp;level&nbsp;container&nbsp;for&nbsp;all&nbsp;shapes.&nbsp;<br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet.CreateDrawingPatriarch();<br><br>\/\/add&nbsp;a&nbsp;picture<br>HSSFClientAnchor&nbsp;anchor&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(0,&nbsp;0,&nbsp;1023,&nbsp;0,&nbsp;0,&nbsp;0,&nbsp;1,&nbsp;3);<br>HSSFPicture&nbsp;pict&nbsp;=&nbsp;patriarch.CreatePicture(anchor,&nbsp;pictureIdx);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4e0e\u753b\u7b80\u5355\u56fe\u5f62\u4e0d\u540c\u7684\u662f\uff0c\u9996\u5148\u8981\u5c06\u56fe\u7247\u8bfb\u5165\u5230byte\u6570\u7ec4\uff0c\u7136\u540e\u6dfb\u52a0\u5230workbook\u4e2d\uff1b\u6700\u540e\u8c03\u7528\u7684\u662fpatriarch.CreatePicture(anchor, pictureIdx)\u65b9\u6cd5\u663e\u793a\u56fe\u7247\uff0c\u800c\u4e0d\u662fpatriarch.CreateSimpleShape(anchor)\u65b9\u6cd5\u3002\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6587\u4ef6\u6837\u5f0f\u5982\u4e0b\uff1a<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6211\u4eec\u53d1\u73b0\uff0c\u63d2\u5165\u7684\u56fe\u7247\u88ab\u62c9\u4f38\u586b\u5145\u5728HSSFClientAnchor\u6307\u5b9a\u7684\u533a\u57df\u3002\u6709\u65f6\u53ef\u80fd\u6211\u4eec\u5e76\u4e0d\u9700\u8981\u62c9\u4f38\u7684\u6548\u679c\uff0c\u600e\u4e48\u529e\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u5728\u6700\u540e\u52a0\u4e0a\u8fd9\u6837\u4e00\u53e5\u7528\u6765\u81ea\u52a8\u8c03\u8282\u56fe\u7247\u5927\u5c0f\uff1a<\/p>\n\n\n\n<p>pict.Resize();<\/p>\n\n\n\n<p>\u6dfb\u52a0\u4ee3\u7801\u540e\u518d\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u751f\u6210\u7684Excel\u6837\u5f0f\u5982\u4e0b\uff1a<br><br>\u56fe\u7247\u5df2\u7ecf\u81ea\u52a8\u4f38\u7f29\u5230\u539f\u59cb\u5927\u5c0f\u4e86\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/05\/10\/1453589.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211; 2.5&nbsp;\u6253\u5370\u76f8\u5173\u8bbe\u7f6e<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u6253\u5370\u8bbe\u7f6e\u4e3b\u8981\u5305\u62ec\u65b9\u5411\u8bbe\u7f6e\u3001\u7f29\u653e\u3001\u7eb8\u5f20\u8bbe\u7f6e\u3001\u9875\u8fb9\u8ddd\u7b49\u3002NPOI 1.2\u652f\u6301\u5927\u90e8\u5206\u6253\u5370\u5c5e\u6027\uff0c\u80fd\u591f\u8ba9\u4f60\u8f7b\u677e\u6ee1\u8db3\u5ba2\u6237\u7684\u6253\u5370\u9700\u8981\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u662f\u65b9\u5411\u8bbe\u7f6e\uff0cExcel\u652f\u6301\u4e24\u79cd\u9875\u9762\u65b9\u5411\uff0c\u5373\u7eb5\u5411\u548c\u6a2a\u5411\u3002<\/p>\n\n\n\n<p>\u5728NPOI\u4e2d\u5982\u4f55\u8bbe\u7f6e\u5462\uff1f\u4f60\u53ef\u4ee5\u901a\u8fc7HSSFSheet.PrintSetup.Landscape\u6765\u8bbe\u7f6e\uff0cLandscape\u662f\u5e03\u5c14\u7c7b\u578b\u7684\uff0c\u5728\u82f1\u8bed\u4e2d\u662f\u6a2a\u5411\u7684\u610f\u601d\u3002\u5982\u679cLandscape\u7b49\u4e8etrue\uff0c\u5219\u8868\u793a\u9875\u9762\u65b9\u5411\u4e3a\u6a2a\u5411\uff1b\u5426\u5219\u4e3a\u7eb5\u5411\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\u662f\u7f29\u653e\u8bbe\u7f6e\uff0c<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684\u7f29\u653e\u6bd4\u4f8b\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.Scale\uff0c\u800c\u9875\u5bbd\u548c\u9875\u9ad8\u5206\u522b\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.FitWidth\u548cHSSFSheet.PrintSetup.FitHeight\u3002\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u7684PrintSetup.Scale\u5e94\u8be5\u88ab\u8bbe\u7f6e\u4e3a0-100\u4e4b\u95f4\u7684\u503c\uff0c\u800c\u4e0d\u662f\u5c0f\u6570\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u7eb8\u5f20\u8bbe\u7f6e\u4e86\uff0c\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.PaperSize\uff0c\u4f46\u8fd9\u91cc\u7684PaperSize\u5e76\u4e0d\u662f\u968f\u4fbf\u8bbe\u7f6e\u7684\uff0c\u800c\u662f\u7531\u4e00\u4e9b\u56fa\u5b9a\u7684\u503c\u51b3\u5b9a\u7684\uff0c\u5177\u4f53\u7684\u503c\u4e0e\u5bf9\u5e94\u7684\u7eb8\u5f20\u5982\u4e0b\u8868\u6240\u793a\uff1a<\/p>\n\n\n\n<table class=\"wp-block-table\"><tbody><tr><td>\u503c<\/td><td>\u7eb8\u5f20<\/td><\/tr><tr><td>1<\/td><td>US Letter 8 1\/2 x 11 in<\/td><\/tr><tr><td>2<\/td><td>US&nbsp;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&#8211;DO NOT USE<\/td><\/tr><tr><td>49<\/td><td>RESERVED&#8211;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><\/tbody><\/table>\n\n\n\n<p>\uff08\u6b64\u8868\u6458\u81ea\u300aExcel Binary File Format (.xls) Structure Specification.pdf\u300b\uff09<\/p>\n\n\n\n<p>HSSFSheet\u4e0b\u9762\u5b9a\u4e49\u4e86\u4e00\u4e9bxxxx_PAPERSIZE\u7684\u5e38\u91cf\uff0c\u4f46\u90fd\u662f\u975e\u5e38\u5e38\u7528\u7684\u7eb8\u5f20\u5927\u5c0f\uff0c\u5982\u679c\u6ee1\u8db3\u4e0d\u4e86\u4f60\u7684\u9700\u8981\uff0c\u53ef\u4ee5\u6839\u636e\u4e0a\u8868\u81ea\u5df1\u7ed9PaperSize\u5c5e\u6027\u8d4b\u503c\u3002\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u8981\u8bbe\u7f6e\u7eb8\u5f20\u5927\u5c0f\u53ef\u4ee5\u7528\u8fd9\u6837\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>HSSFSheet.PrintSetup.PaperSize=HSSFSheet.A4_PAPERSIZE;<\/p>\n\n\n\n<p>\u6216<\/p>\n\n\n\n<p>HSSFSheet.PrintSetup.PaperSize=9;(A4 210*297mm)<\/p>\n\n\n\n<p>\u518d\u4e0b\u6765\u5c31\u662f\u6253\u5370\u7684\u8d77\u59cb\u9875\u7801\uff0c\u5b83\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.PageStart\u548cHSSFSheet.PrintSetup.UsePage\uff0c\u5982\u679cUsePage=false\uff0c\u90a3\u4e48\u5c31\u76f8\u5f53\u4e8e\u201c\u81ea\u52a8\u201d\uff0c\u8fd9\u65f6PageStart\u4e0d\u8d77\u4f5c\u7528\uff1b\u5982\u679cUsePage=true\uff0cPageStart\u624d\u4f1a\u8d77\u4f5c\u7528\u3002\u6240\u4ee5\u5728\u8bbe\u7f6ePageStart\u4e4b\u524d\uff0c\u5fc5\u987b\u5148\u628aUsePage\u8bbe\u7f6e\u4e3atrue\u3002<\/p>\n\n\n\n<p>\u201c\u6253\u5370\u201d\u680f\u4e2d\u7684\u201c\u7f51\u683c\u7ebf\u201d\u8bbe\u7f6e\u5bf9\u5e94\u4e8eHSSFSheet.IsPrintGridlines\uff0c\u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u4e0d\u662fHSSFSheet.PrintSetup\u4e0b\u9762\uff0c\u6240\u4ee5\u522b\u641e\u6df7\u4e86\u3002\u8fd9\u91cc\u4e4b\u6240\u4ee5\u4e0d\u96b6\u5c5e\u4e8ePrintSetup\u662f\u7531\u5e95\u5c42\u5b58\u50a8\u8be5\u4fe1\u606f\u7684record\u51b3\u5b9a\u7684\uff0c\u5e95\u5c42\u662f\u628aIsGridsPrinted\u653e\u5728GridsetRecord\u91cc\u9762\u7684\uff0c\u800c\u4e0d\u662fPrintSetupRecord\u91cc\u9762\u7684\uff0c\u5c3d\u7ba1\u754c\u9762\u4e0a\u662f\u653e\u5728\u4e00\u8d77\u7684\u3002\u53e6\u5916\u8fd8\u6709\u4e00\u4e2aHSSFSheet.IsGridsPrinted\u5c5e\u6027\uff0c\u8fd9\u4e2a\u5c5e\u6027\u5bf9\u5e94\u4e8e\u5e95\u5c42\u7684gridset Record\uff0c\u4f46\u8fd9\u4e2arecord\u662f\u4fdd\u7559\u7684\uff0c\u4ece\u5fae\u8f6f\u7684\u6587\u6863\u663e\u793a\u6ca1\u6709\u4efb\u4f55\u610f\u4e49\uff0c\u6240\u4ee5\u8fd9\u4e2a\u5c5e\u6027\u8bf7\u4e0d\u8981\u53bb\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u201c\u5355\u8272\u6253\u5370\u201d\u5219\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.NoColors\uff0c\u8fd9\u662f\u5e03\u5c14\u7c7b\u578b\u7684\uff0c\u503c\u4e3atrue\u65f6\uff0c\u8868\u793a\u5355\u8272\u6253\u5370\u3002<\/p>\n\n\n\n<p>\u201c\u8349\u7a3f\u54c1\u8d28\u201d\u5bf9\u5e94\u4e8eHSSFSheet.PrintSetup.IsDraft\uff0c\u4e5f\u662f\u5e03\u5c14\u7c7b\u578b\u7684\uff0c\u503c\u4e3atrue\u65f6\uff0c\u8868\u793a\u7528\u8349\u7a3f\u54c1\u8d28\u6253\u5370\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684\u6253\u5370\u987a\u5e8f\u662f\u7531HSSFSheet.PrintSetup.LeftToRight\u51b3\u5b9a\u7684\uff0c\u5b83\u662f\u5e03\u5c14\u7c7b\u578b\u7684\uff0c\u5f53\u4e3atrue\u65f6\uff0c\u5219\u8868\u793a\u201c\u5148\u884c\u540e\u5217\u201d\uff1b\u5982\u679c\u662ffalse\uff0c\u5219\u8868\u793a\u201c\u5148\u5217\u540e\u884c\u201d\u3002<\/p>\n\n\n\n<p>\u5728NPOI 1.2\u4e2d\uff0c\u201c\u884c\u53f7\u5217\u6807\u201d\u3001\u201c\u6279\u6ce8\u201d\u548c\u201c\u9519\u8bef\u5355\u5143\u683c\u6253\u5370\u4e3a\u201d\u3001\u201c\u9875\u8fb9\u8ddd\u201d\u6682\u4e0d\u652f\u6301\uff0c\u5c06\u5728\u4ee5\u540e\u7684\u7248\u672c\u4e2d\u652f\u6301\u3002<\/p>\n\n\n\n<p>\u6709\u5173\u6253\u5370\u7684\u8303\u4f8b\u53ef\u4ee5\u53c2\u8003<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=21991\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684&nbsp;SetPrintSettingsInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/28\/1576063.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.1\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u8c03\u6574\u8868\u5355\u663e\u793a\u6bd4\u4f8b<\/strong><\/p>\n\n\n\n<p>\u5728Excel\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u53f3\u4e0b\u89d2\u7684\u6eda\u52a8\u6761\u6765\u8c03\u6574Sheet\u7684\u663e\u793a\u6bd4\u4f8b\u3002\u5982\u56fe\uff1a<br><br>\u5728NPOI\u4e2d\uff0c\u4e5f\u80fd\u901a\u8fc7\u4ee3\u7801\u5b9e\u73b0\u8fd9\u6837\u7684\u529f\u80fd\uff0c\u5e76\u4e14\u4ee3\u7801\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>sheet1.CreateRow(0).CreateCell(0).SetCellValue(&#8220;This&nbsp;is&nbsp;a&nbsp;test.&#8221;);<br>\/\/50%&nbsp;zoom<br>sheet1.SetZoom(1,2);&nbsp;<\/p>\n\n\n\n<p>\u6211\u4eec\u53d1\u73b0\uff0cSetZoom\u6709\u4e24\u4e2a\u53c2\u6570\u3002\u5176\u4e2d\u7b2c\u4e00\u4e2a\u53c2\u6570\u8868\u793a\u7f29\u653e\u6bd4\u4f8b\u7684\u5206\u5b50\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u7f29\u653e\u6bd4\u4f8b\u7684\u5206\u6bcd\uff0c\u6240\u4ee5SetZoom(1,2)\u5c31\u8868\u793a\u7f29\u5c0f\u52301\/2\uff0c\u4e5f\u5c31\u662f50%\u3002\u4ee3\u7801\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6837\u5f0f\u5982\u4e0b\uff1a<br><br><br>\u5982\u679c\u5c06SetZoom\u7684\u53c2\u6570\u6539\u6210(2,1)\uff0c\u4ee3\u7801\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6837\u5f0f\u5982\u4e0b\uff0c\u8868\u793a\u6269\u5927\u4e24\u500d\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/18\/1568917.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.2\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u8bbe\u7f6e\u5bc6\u7801<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6709\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u67d0\u4e9b\u5355\u5143\u683c\u53ea\u8bfb\uff0c\u5982\u5728\u505a\u6a21\u677f\u65f6\uff0c\u6a21\u677f\u4e2d\u7684\u6570\u636e\u662f\u4e0d\u80fd\u968f\u610f\u8ba9\u522b\u4eba\u6539\u7684\u3002\u5728Excel\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u201c\u5ba1\u9605-&gt;\u4fdd\u62a4\u5de5\u4f5c\u8868\u201d\u6765\u5b8c\u6210\uff0c\u5982\u4e0b\u56fe\uff1a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;\u90a3\u4e48\uff0c\u5728NPOI\u4e2d\u6709\u6ca1\u6709\u529e\u6cd5\u901a\u8fc7\u7f16\u7801\u7684\u65b9\u5f0f\u8fbe\u5230\u8fd9\u4e00\u6548\u679c\u5462\uff1f\u7b54\u6848\u662f\u80af\u5b9a\u7684\u3002<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>HSSFCell&nbsp;cel1&nbsp;=&nbsp;row1.CreateCell(0);<br>HSSFCell&nbsp;cel2&nbsp;=&nbsp;row1.CreateCell(1);<br><br>HSSFCellStyle&nbsp;unlocked&nbsp;=&nbsp;hssfworkbook.CreateCellStyle();<br>unlocked.IsLocked&nbsp;=&nbsp;false;<br><br>HSSFCellStyle&nbsp;locked&nbsp;=&nbsp;hssfworkbook.CreateCellStyle();<br>locked.IsLocked&nbsp;=&nbsp;true;<br><br>cel1.SetCellValue(&#8220;\u6ca1\u88ab\u9501\u5b9a&#8221;);<br>cel1.CellStyle&nbsp;=&nbsp;unlocked;<br><br>cel2.SetCellValue(&#8220;\u88ab\u9501\u5b9a&#8221;);<br>cel2.CellStyle&nbsp;=&nbsp;locked;<br><br>sheet1.ProtectSheet(&#8220;password&#8221;);<\/p>\n\n\n\n<p>\u6b63\u5982\u4ee3\u7801\u4e2d\u6240\u770b\u5230\u7684\uff0c\u6211\u4eec\u901a\u8fc7\u8bbe\u7f6eCellStype\u7684ISLocked\u4e3aTrue\uff0c\u8868\u793a\u6b64\u5355\u5143\u683c\u5c06\u88ab\u9501\u5b9a\u3002\u76f8\u5f53\u4e8e\u5728Excel\u4e2d\u6267\u884c\u4e86\u5982\u4e0b\u64cd\u4f5c\uff1a<br><br>\u7136\u540e\u901a\u8fc7ProtectSheet\u8bbe\u7f6e\u5bc6\u7801\u3002<br><br>\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p>\u6ca1\u88ab\u9501\u5b9a\u7684\u5217\u53ef\u4ee5\u4efb\u610f\u4fee\u6539\u3002<br>&nbsp;<\/p>\n\n\n\n<p>\u88ab\u9501\u5b9a\u7684\u5217\u4e0d\u80fd\u4fee\u6539\u3002<br>&nbsp;<br><br><br>\u8f93\u5165\u5bc6\u7801\u53ef\u4ee5\u89e3\u9664\u9501\u5b9a\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/13\/1434453.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211;&nbsp;\u7ec4\u5408\u884c\u3001\u5217<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>Excel 2007\u4e2d\u6709\u4e00\u4e2a\u9762\u677f\u662f\u4e13\u95e8\u7528\u4e8e\u8bbe\u7f6e\u7ec4\u5408\u529f\u80fd\u7684\uff0c\u53eb\u505a\u201c\u5206\u7ea7\u663e\u793a\u201d\u9762\u677f\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>\u53ef\u80fd\u6211\u4eec\u5728\u8fc7\u53bb\u751f\u6210Excel\u6587\u4ef6\u7684\u65f6\u5019\u6839\u672c\u4e0d\u4f1a\u7528\u8fd9\u4e2a\u529f\u80fd\uff0c\u4e5f\u6ca1\u529e\u6cd5\u7528\uff0c\u56e0\u4e3acvs\u6cd5\u548chtml\u6cd5\u6ca1\u529e\u6cd5\u63a7\u5236\u8fd9\u4e9b\u4e1c\u897f\u3002\u8fd9\u91cc\u7b80\u5355\u7684\u4ecb\u7ecd\u4e00\u4e0b\u4ec0\u4e48\u53eb\u505a\u7ec4\u5408\uff1a<\/p>\n\n\n\n<p>\u7ec4\u5408\u5206\u4e3a\u884c\u7ec4\u5408\u548c\u5217\u7ec4\u5408\uff0c\u6240\u8c13\u884c\u7ec4\u5408\uff0c\u5c31\u662f\u8ba9n\u884c\u7ec4\u5408\u6210\u4e00\u4e2a\u96c6\u5408\uff0c\u80fd\u591f\u8fdb\u884c\u5c55\u5f00\u548c\u5408\u62e2\u64cd\u4f5c\uff0c\u5728Excel\u4e2d\u663e\u793a\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u56fe\u4e2d\u5de6\u4fa7\u5c31\u662f\u7528\u4e8e\u63a7\u5236\u884c\u7ec4\u5408\u6298\u53e0\u7684\u56fe\u6807\uff0c\u56fe\u4e2d\u4e0a\u90e8\u5c31\u662f\u7528\u4e8e\u63a7\u5236\u5217\u7ec4\u5408\u7684\uff0c\u662f\u4e0d\u662f\u6709\u70b9\u50cfTreeView\u4e2d\u7684\u6298\u53e0\u8282\u70b9\uff1f\u5f88\u591a\u65f6\u5019\u7531\u4e8e\u6570\u636e\u592a\u591a\uff0c\u4e3a\u4e86\u8ba9\u7528\u6237\u5bf9\u4e8e\u5927\u91cf\u6570\u636e\u4e00\u76ee\u4e86\u7136\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u884c\u5217\u7ec4\u5408\u6765\u89e3\u51b3\u663e\u793a\u5927\u7eb2\uff0c\u8fd9\u548cVisual Studio&nbsp;\u91cc\u9762\u7684region\u7684\u6982\u5ff5\u662f\u7c7b\u4f3c\u7684\u3002<\/p>\n\n\n\n<p>\u7ec6\u5fc3\u7684\u670b\u53cb\u53ef\u80fd\u5df2\u7ecf\u6ce8\u610f\u5230\u4e86\uff0c\u6211\u4eec\u5176\u5b9e\u53ef\u4ee5\u5bf9\u4e00\u884c\u505a\u591a\u6b21\u7ec4\u5408\u64cd\u4f5c\uff0c\u8fd9\u5c31\u662f\u5206\u7ea7\u663e\u793a\u7684\u6982\u5ff5\uff0c\u56fe\u4e2d\u5c31\u628a\u884c2-3\u5206\u4e3a2\u4e2a\u7ec4\u5408\uff0c\u7b2c2\u884c\u5230\u7b2c4\u884c\u4e3a\u4e00\u4e2a\u7ec4\u5408\uff0c\u7b2c2\u884c\u5230\u7b2c5\u884c\u4e00\u4e2a\u7ec4\u5408\uff0c\u6240\u4ee5\u662f\u5206\u4e24\u7ea7\u3002<\/p>\n\n\n\n<p>\u5728NPOI\u4e2d\uff0c\u8981\u5b9e\u73b0\u5206\u7ec4\u5176\u5b9e\u5e76\u4e0d\u96be\uff0c\u4f60\u53ea\u9700\u8981\u8c03\u7528HSSFSheet.GroupRow\u548cHSSFSheet.GroupColumn\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u6765\u770bHSSFSheet.GroupRow\uff0cGroupRow\u67092\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u662ffromRow\u548ctoRow\uff0c\u8868\u793a\u8d77\u59cb\u884c\u53f7\u548c\u7ed3\u675f\u884c\u53f7\uff0c\u8fd9\u4e9b\u884c\u53f7\u90fd\u662f\u4ece0\u5f00\u59cb\u7b97\u8d77\u7684\u3002<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>HSSFSheet s =hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>s.GroupRow(1,3);<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u628a\u7b2c2\u884c\u5230\u7b2c4\u884c\u505a\u4e86\u7ec4\u5408\u3002<\/p>\n\n\n\n<p>\u8981\u7ec4\u5408\u5217\uff0c\u5176\u5b9e\u4ee3\u7801\u5f88\u76f8\u4f3c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>s.GroupColumn(1,3)<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u628aB\u81f3D\u5217\u505a\u4e86\u7ec4\u5408\u3002<\/p>\n\n\n\n<p>\u6b63\u5982\u4e0a\u56fe\u4e2dExcel\u7684\u201c\u5206\u7ea7\u663e\u793a\u201d\u9762\u677f\u6240\u793a\uff0c\u6709\u201c\u7ec4\u5408\u201d\uff0c\u4e5f\u4e00\u5b9a\u6709\u201c\u53d6\u6d88\u7ec4\u5408\u201d\uff0cNPOI\u4e2d\u4f60\u53ef\u4ee5\u7528HSSFSheet.UngroupRow\u548cHSSFSheet.UngroupColumn\uff0c\u53c2\u6570\u548cGroupXXX\u662f\u4e00\u6837\u7684\uff0c\u5982\u679c\u8981\u53d6\u6d88\u7b2c2\u5230\u7b2c4\u884c\u7684\u7ec4\u5408\uff0c\u5c31\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>s.UngroupColumn(1,3)<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u8bf7\u89c1<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6b63\u5f0f\u7248<\/a>\u4e2d\u7684GroupRowAndColumnInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/18\/1568918.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.4\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u9501\u5b9a\u5217<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5728Excel\u4e2d\uff0c\u6709\u65f6\u53ef\u80fd\u4f1a\u51fa\u73b0\u5217\u6570\u592a\u591a\u6216\u662f\u884c\u6570\u592a\u591a\u7684\u60c5\u51b5\uff0c\u8fd9\u65f6\u53ef\u4ee5\u901a\u8fc7\u9501\u5b9a\u5217\u6765\u51bb\u7ed3\u90e8\u5206\u5217\uff0c\u4e0d\u968f\u6eda\u52a8\u6761\u6ed1\u52a8\uff0c\u65b9\u4fbf\u67e5\u770b\u3002\u5728Excel\u4e2d\u8bbe\u7f6e\u51bb\u7ed3\u5217\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a<br><br><br>\u540c\u6837\uff0c\u5229\u7528NPOI\uff0c\u901a\u8fc7\u4ee3\u7801\u4e5f\u80fd\u5b9e\u73b0\u4e0a\u9762\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u51bb\u7ed3\u5217&#8221;);<br>sheet1.CreateFreezePane(1,&nbsp;0,&nbsp;1,&nbsp;0);<\/p>\n\n\n\n<p><br>\u4ee3\u7801\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p>\u4e0b\u9762\u5bf9CreateFreezePane\u7684\u53c2\u6570\u4f5c\u4e00\u4e0b\u8bf4\u660e\uff1a<br>\u7b2c\u4e00\u4e2a\u53c2\u6570\u8868\u793a\u8981\u51bb\u7ed3\u7684\u5217\u6570\uff1b<br>\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u8981\u51bb\u7ed3\u7684\u884c\u6570\uff0c\u8fd9\u91cc\u53ea\u51bb\u7ed3\u5217\u6240\u4ee5\u4e3a0\uff1b<br>\u7b2c\u4e09\u4e2a\u53c2\u6570\u8868\u793a\u53f3\u8fb9\u533a\u57df\u53ef\u89c1\u7684\u9996\u5217\u5e8f\u53f7\uff0c\u4ece1\u5f00\u59cb\u8ba1\u7b97\uff1b<br>\u7b2c\u56db\u4e2a\u53c2\u6570\u8868\u793a\u4e0b\u8fb9\u533a\u57df\u53ef\u89c1\u7684\u9996\u884c\u5e8f\u53f7\uff0c\u4e5f\u662f\u4ece1\u5f00\u59cb\u8ba1\u7b97\uff0c\u8fd9\u91cc\u662f\u51bb\u7ed3\u5217\uff0c\u6240\u4ee5\u4e3a0\uff1b<\/p>\n\n\n\n<p>\u4e3e\u4f8b\u8bf4\u660e\u4e5f\u8bb8\u66f4\u597d\u7406\u89e3\uff0c\u5c06\u5404\u53c2\u6570\u8bbe\u7f6e\u4e3a\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>sheet1.CreateFreezePane(2,0,5,0);<\/p>\n\n\n\n<p>\u5f97\u5230\u7684\u6548\u679c\u5982\u4e0b\u56fe\uff1a<br><br>\u6ce8\u610f\u56fe\u4e2dC\u3001D\u548cE\u5217\u9ed8\u8ba4\u662f\u770b\u4e0d\u5230\u7684\uff0c\u6eda\u52a8\u624d\u770b\u5f97\u5230\uff0c\u8fd9\u5c31\u662f\u7b2c\u4e09\u4e2a\u53c2\u65705\u8d77\u4e86\u4f5c\u7528\uff0c\u662f\u4e0d\u662f\u5f88\u597d\u7406\u89e3\u4e86\u5462\uff1a\uff09<br><br>\u63a5\u4e0b\u6765\uff0c\u770b\u4e00\u4e0b\u51bb\u7ed3\u884c\u7684\u6548\u679c\u3002\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u7a0d\u4f5c\u4fee\u6539\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row1&nbsp;=&nbsp;sheet1.CreateRow(0);<br>row1.CreateCell(0).SetCellValue(&#8220;\u51bb\u7ed3\u884c&#8221;);<br>sheet1.CreateFreezePane(0,&nbsp;1,&nbsp;0,&nbsp;1);<\/p>\n\n\n\n<p>\u6267\u884c\u540e\u751f\u6210\u7684Excel\u6587\u4ef6\u6548\u679c\u89c1\u4e0b\u56fe\uff1a<br><br><br>\u90a3\u4e48\uff0c\u5982\u679c\u8981\u884c\u548c\u5217\u540c\u65f6\u51bb\u7ed3\u8be5\u600e\u4e48\u505a\u5462\uff1f\u806a\u660e\u7684\u4f60\u4e00\u5b9a\u80fd\u60f3\u5f97\u5230\uff0c\u5475\u5475~~<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/04\/14\/1434100.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;&#8211;&nbsp;\u663e\u793a\/\u9690\u85cfExcel\u7f51\u683c\u7ebf<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u7f51\u683c\u7ebf\uff0c\u800c\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u4e0d\u9700\u8981\uff0c\u8fd9\u53d6\u51b3\u4e8e\u5b9e\u9645\u7684\u4e1a\u52a1\u9700\u6c42\u3002\u524d\u4e24\u5929inmegin\u5144\u5c31\u95ee\u6211\uff0c\u600e\u4e48\u628a\u7f51\u683c\u7ed9\u53bb\u6389\uff0c\u56e0\u4e3a\u4ed6\u4eec\u8981\u628aExcel\u6587\u6863\u5f53Word\u4f7f\uff0c\u4e5f\u8bb8\u662f\u56e0\u4e3aExcel\u6392\u7248\u65b9\u4fbf\u5427\u3002<\/p>\n\n\n\n<p>Excel\u4e2d\u7684\u7f51\u683c\u7ebf\u8bbe\u7f6e\u662f\u4ee5\u8868\uff08Sheet\uff09\u4e3a\u5355\u4f4d\u8fdb\u884c\u7ba1\u7406\u7684\uff0c\u8fd9\u4e5f\u5c31\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u8ba9\u4e00\u4e2a\u8868\u663e\u793a\u7f51\u683c\u7ebf\uff0c\u800c\u53e6\u4e00\u4e2a\u8868\u4e0d\u663e\u793a\uff0c\u8fd9\u662f\u4e0d\u51b2\u7a81\u7684\u3002<\/p>\n\n\n\n<p>\u5728Excel 2007\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u7528\u201c\u5de5\u4f5c\u8868\u9009\u9879\u201d\u9762\u677f\u6765\u8bbe\u7f6e\u8fd9\u4e2a\u5c5e\u6027:<\/p>\n\n\n\n<p>\u5728\u9762\u677f\u4e2d\uff0c\u4f60\u4f1a\u53d1\u73b0\u67092\u4e2a\u591a\u9009\u6846\uff0c\u4e00\u4e2a\u662f\u67e5\u770b\uff0c\u4e00\u4e2a\u662f\u6253\u5370\uff0c\u4e5f\u5c31\u662f\u8bf4Excel\u662f\u628a\u67e5\u770b\u548c\u6253\u5370\u7f51\u683c\u7ebf\u4f5c\u4e3a\u4e24\u4e2a\u8bbe\u7f6e\u6765\u5904\u7406\u7684\uff0c\u5b58\u50a8\u7684Record\u4e5f\u662f\u4e0d\u540c\u7684\u3002<\/p>\n\n\n\n<p>\u5728NPOI\u4e2d\uff0c\u5982\u679c\u8981\u8ba9\u7f51\u683c\u7ebf\u5728\u67e5\u770b\u65f6\u663e\u793a\/\u9690\u85cf\uff0c\u4f60\u53ef\u4ee5HSSFSheet.DisplayGridlines\u5c5e\u6027\uff0c\u9ed8\u8ba4\u503c\u4e3atrue\uff08\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u6211\u4eec\u80fd\u591f\u770b\u5230\u7f51\u683c\u7ebf\uff09\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u5c31\u662f\u8ba9\u7f51\u683c\u7ebf\u5728\u67e5\u770b\u65f6\u4e0d\u53ef\u89c1\u7684\uff1a<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook =newHSSFWorkbook();<\/p>\n\n\n\n<p>HSSFSheet s1= hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<\/p>\n\n\n\n<p>s1.DisplayGridlines=false;<\/p>\n\n\n\n<p>\u5982\u679c\u8981\u5728\u6253\u5370\u65f6\u663e\u793a\/\u9690\u85cf\u7f51\u683c\u7ebf\uff0c\u4f60\u53ef\u4ee5\u7528HSSFSheet.IsGridlinesPrinted\u5c5e\u6027\uff0c\u9ed8\u8ba4\u503c\u4e3afalse\uff08\u8fd9\u5c31\u662f\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u6253\u5370\u770b\u4e0d\u5230\u7f51\u683c\u7ebf\u7684\u539f\u56e0\uff09\u3002\u4ee3\u7801\u548c\u4e0a\u9762\u5dee\u4e0d\u591a\uff1a<\/p>\n\n\n\n<p>s1.IsGridsPrinted=true;<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u5728\u6253\u5370\u65f6\u663e\u793a\u7f51\u683c\u7ebf\uff0c\u6253\u5370\u7684\u6548\u679c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p>\u5728\u6b64\u4e5f\u63d0\u9192\u5927\u5bb6\uff0c\u5982\u679c\u8fd9\u4e2aExcel\u6700\u7ec8\u5ba2\u6237\u6709\u6253\u5370\u610f\u5411\uff0c\u53ef\u522b\u5fd8\u4e86\u628aIsGridPrinted\u5c5e\u6027\u4e5f\u8bbe\u7f6e\u4e0a\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u8303\u4f8b\u53ef\u4ee5\u53c2\u8003NPOI 1.2\u6b63\u5f0f\u7248\u4e2d\u7684DisplayGridlinesInXls\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/11\/15\/1603516.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.6\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u8bbe\u7f6e\u521d\u59cb\u89c6\u56fe\u7684\u884c\u3001\u5217<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u6709\u4e9b\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u5e0c\u671b\u751f\u6210\u7684Excel\u6587\u4ef6\u5728\u88ab\u6253\u5f00\u7684\u65f6\u5019\u81ea\u52a8\u5c06\u7126\u70b9\u5b9a\u4f4d\u5728\u67d0\u4e2a\u5355\u5143\u683c\u6216\u662f\u9009\u4e2d\u67d0\u4e2a\u533a\u57df\u4e2d\u3002\u5728NPOI\u4e2d\u53ef\u4ee5\u901a\u8fc7SetAsActiveCell\u548cSetActiveCellRange\u7b49\u51e0\u4e2a\u65b9\u6cd5\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u770b\u4e00\u4e0b\u8bbe\u7f6e\u521d\u59cb\u89c6\u56fe\u4e2d\u9009\u4e2d\u67d0\u4e2a\u5355\u5143\u683c\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<p>\/\/use&nbsp;HSSFCell.SetAsActiveCell()&nbsp;to&nbsp;select&nbsp;B6&nbsp;as&nbsp;the&nbsp;active&nbsp;column<br>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet&nbsp;A&#8221;);<br>CreateCellArray(sheet1);<br>sheet1.GetRow(5).GetCell(1).SetAsActiveCell();<br>\/\/set&nbsp;TopRow&nbsp;and&nbsp;LeftCol&nbsp;to&nbsp;make&nbsp;B6&nbsp;the&nbsp;first&nbsp;cell&nbsp;in&nbsp;the&nbsp;visible&nbsp;area<br>sheet1.TopRow&nbsp;=&nbsp;5;<br>sheet1.LeftCol&nbsp;=&nbsp;1;<\/p>\n\n\n\n<p>\u5176\u4e2dCreateCellArray(sheet1)\u65b9\u6cd5\u7528\u6765\u5199\u793a\u8303\u6570\u636e\uff0c\u5176\u4ee3\u7801\u4e3a\uff08\u4e0b\u540c\uff09\uff1a<\/p>\n\n\n\n<p>static&nbsp;void&nbsp;CreateCellArray(HSSFSheet&nbsp;sheet)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;300;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;row=sheet.CreateRow(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;150;&nbsp;j++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cell&nbsp;=&nbsp;row.CreateCell(j);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(i*j);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<\/p>\n\n\n\n<p>\u751f\u6210\u7684Excel\u6253\u5f00\u65f6\u6548\u679c\u5982\u4e0b\uff0c\u6ce8\u610fB6\u4e3a\u9ed8\u8ba4\u9009\u4e2d\u72b6\u6001\uff0cTopRow\u548cLeftCol\u8bbe\u7f6eB6\u4e3a\u5f53\u524d\u53ef\u89c1\u533a\u57df\u7684\u7b2c\u4e00\u4e2a\u5355\u5143\u683c\uff1a<\/p>\n\n\n\n<p>\u5982\u679c\u4e0d\u8bbe\u7f6eTopRow\u548cLeftCol\u5c5e\u6027\uff0c\u9ed8\u8ba4\u7684\u53ef\u89c1\u57df\u7684\u7b2c\u4e00\u4e2a\u5355\u5143\u683c\u4e3aA1\uff0c\u5982\u4e0b\u662f\u53e6\u4e00\u79cd\u8bbe\u7f6e\u6d3b\u52a8\u5355\u5143\u683c\u7684\u65b9\u6cd5\uff0c\u4f46\u6ca1\u6709\u8bbe\u7f6e\u6b64Sheet\u7684TopRow\u548cLeftCol\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet2&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet&nbsp;B&#8221;);<br>sheet2.Sheet.SetActiveCell(1,&nbsp;5);<\/p>\n\n\n\n<p>\u5bf9\u5e94\u751f\u6210\u7684Excel\u663e\u793a\u4e3a:<\/p>\n\n\n\n<p>\u9664\u4e86\u8bbe\u7f6e\u67d0\u4e2a\u5355\u5143\u683c\u4e3a\u9009\u4e2d\u72b6\u6001\u5916\uff0c\u8fd8NPOI\u53ef\u4ee5\u8bbe\u7f6e\u67d0\u4e2a\u533a\u57df\u4e3a\u9009\u4e2d\u72b6\u6001\uff1a<\/p>\n\n\n\n<p>\/\/use&nbsp;Sheet.SetActiveCellRange&nbsp;to&nbsp;select&nbsp;a&nbsp;cell&nbsp;range<br>HSSFSheet&nbsp;sheet3&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet&nbsp;C&#8221;);<br>CreateCellArray(sheet3);<br>sheet3.Sheet.SetActiveCellRange(2,&nbsp;5,&nbsp;1,&nbsp;5);<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u4ee3\u7801\u8bbe\u7f6e\u4e86Sheet C\u7684\u9009\u4e2d\u533a\u57df\u4e3aB3:F6\uff1a<\/p>\n\n\n\n<p>\u8fd8\u6709\u66f4\u5f3a\u5927\u7684\uff0c\u8bbe\u7f6e\u591a\u4e2a\u9009\u4e2d\u533a\u57df\uff1a<\/p>\n\n\n\n<p>\/\/use&nbsp;Sheet.SetActiveCellRange&nbsp;to&nbsp;select&nbsp;multiple&nbsp;cell&nbsp;ranges<br>HSSFSheet&nbsp;sheet4&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet&nbsp;D&#8221;);<br>CreateCellArray(sheet4);<br>List&lt;CellRangeAddress8Bit&gt;&nbsp;cellranges&nbsp;=&nbsp;new&nbsp;List&lt;CellRangeAddress8Bit&gt;();<br>cellranges.Add(new&nbsp;CellRangeAddress8Bit(1,3,2,5));<br>cellranges.Add(new&nbsp;CellRangeAddress8Bit(6,7,8,9));<br>sheet4.Sheet.SetActiveCellRange(cellranges,1,6,9);<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2aExcel\u6587\u4ef6\u4e2d\u6709\u591a\u4e2aSheet\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u8bed\u53e5\u8bbe\u7f6e\u6253\u5f00\u65f6\u7684\u521d\u59cbSheet\uff1a<\/p>\n\n\n\n<p>hssfworkbook.ActiveSheetIndex&nbsp;=&nbsp;2;<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/22\/1572170.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.7\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u6570\u636e\u6709\u6548\u6027<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff08\u6bd4\u5982Excel\u5f15\u5165\uff09\uff0c\u6211\u4eec\u53ef\u80fd\u4e0d\u5141\u8bb8\u7528\u6237\u5728Excel\u968f\u610f\u8f93\u5165\u4e00\u4e9b\u65e0\u6548\u6570\u636e\uff0c\u8fd9\u65f6\u5c31\u8981\u5728\u6a21\u677f\u4e2d\u52a0\u4e00\u4e9b\u6570\u636e\u6709\u6548\u6027\u7684\u9a8c\u8bc1\u3002\u5728Excel\u4e2d\uff0c\u8bbe\u7f6e\u6570\u636e\u6709\u6548\u6027\u7684\u65b9\u6b65\u9aa4\u5982\u4e0b\uff1a<br>\uff081\uff09\u5148\u9009\u5b9a\u4e00\u4e2a\u533a\u57df\uff1b<br>\u6570\u636e\u6709\u6548\u6027\u201d\u4e2d\u8bbe\u7f6e\u6570\u636e\u6709\u6548\u6027\u9a8c\u8bc1\uff08\u5982\u56fe\uff09\u3002\u00e0\uff082\uff09\u5728\u83dc\u5355\u201c\u6570\u636e<br><br><br>\u540c\u6837\uff0c\u5229\u7528NPOI\uff0c\u7528\u4ee3\u7801\u4e5f\u53ef\u4ee5\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>sheet1.CreateRow(0).CreateCell(0).SetCellValue(&#8220;\u65e5\u671f\u5217&#8221;);<br>CellRangeAddressList&nbsp;regions1&nbsp;=&nbsp;new&nbsp;CellRangeAddressList(1,&nbsp;65535,&nbsp;0,&nbsp;0);<br>DVConstraint&nbsp;constraint1&nbsp;=&nbsp;DVConstraint.CreateDateConstraint(DVConstraint.OperatorType.BETWEEN,&nbsp;&#8220;1900-01-01&#8221;,&nbsp;&#8220;2999-12-31&#8221;,&nbsp;&#8220;yyyy-MM-dd&#8221;);<br>HSSFDataValidation&nbsp;dataValidate1&nbsp;=&nbsp;new&nbsp;HSSFDataValidation(regions1,&nbsp;constraint1);<br>dataValidate1.CreateErrorBox(&#8220;error&#8221;,&nbsp;&#8220;You&nbsp;must&nbsp;input&nbsp;a&nbsp;date.&#8221;);<br>sheet1.AddValidationData(dataValidate1);<\/p>\n\n\n\n<p>\u4e0a\u9762\u662f\u4e00\u4e2a\u5728\u7b2c\u4e00\u5217\u8981\u6c42\u8f93\u51651900-1-1\u81f32999-12-31\u4e4b\u95f4\u65e5\u671f\u7684\u6709\u6548\u6027\u9a8c\u8bc1\u7684\u4f8b\u5b50\uff0c\u751f\u6210\u7684Excel\u6548\u679c\u5982\u4e0b\uff0c\u5f53\u8f93\u5165\u975e\u6cd5\u65f6\u5c06\u7ed9\u51fa\u8b66\u544a\uff1a<br><br><br>\u4e0b\u9762\u5bf9\u521a\u624d\u7528\u5230\u7684\u51e0\u4e2a\u65b9\u6cd5\u52a0\u4ee5\u8bf4\u660e\uff1a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CellRangeAddressList\u7c7b\u8868\u793a\u4e00\u4e2a\u533a\u57df\uff0c\u6784\u9020\u51fd\u6570\u4e2d\u7684\u56db\u4e2a\u53c2\u6570\u5206\u522b\u8868\u793a\u8d77\u59cb\u884c\u5e8f\u53f7\uff0c\u7ec8\u6b62\u884c\u5e8f\u53f7\uff0c\u8d77\u59cb\u5217\u5e8f\u53f7\uff0c\u7ec8\u6b62\u5217\u5e8f\u53f7\u3002\u6240\u4ee5\u7b2c\u4e00\u5217\u6240\u5728\u533a\u57df\u5c31\u8868\u793a\u4e3a\uff1a<\/p>\n\n\n\n<p>\/\/\u6240\u6709\u5e8f\u53f7\u90fd\u4ece\u96f6\u7b97\u8d77\uff0c\u7b2c\u4e00\u884c\u6807\u9898\u884c\u9664\u5916\uff0c\u6240\u4ee5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f1\uff0c65535\u662f\u4e00\u4e2aSheet\u7684\u6700\u5927\u884c\u6570<br>new&nbsp;CellRangeAddressList(1,&nbsp;65535,&nbsp;0,&nbsp;0);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u53e6\u5916\uff0cCreateDateConstraint\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u9664\u4e86\u8bbe\u7f6e\u6210DVConstraint.OperatorType.BETWEEN\u5916\uff0c\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u6210\u5982\u4e0b\u4e00\u4e9b\u503c\uff0c\u5927\u5bb6\u53ef\u4ee5\u81ea\u5df1\u4e00\u4e2a\u4e2a\u53bb\u8bd5\u770b\u770b\u6548\u679c\uff1a<br><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6700\u540e\uff0cdataValidate1.CreateErrorBox(title,text)\uff0c\u7528\u6765\u521b\u5efa\u51fa\u9519\u65f6\u7684\u63d0\u793a\u4fe1\u606f\u3002\u7b2c\u4e00\u4e2a\u53c2\u6570\u8868\u793a\u63d0\u793a\u6846\u7684\u6807\u9898\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u8868\u793a\u63d0\u793a\u6846\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u7406\u89e3\u4e86\u4e0a\u9762\u8fd9\u4e9b\uff0c\u521b\u5efa\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u6709\u6548\u6027\u9a8c\u8bc1\u4e5f\u4e0d\u96be\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<p>sheet1.CreateRow(0).CreateCell(1).SetCellValue(&#8220;\u6570\u503c\u5217&#8221;);<br>CellRangeAddressList&nbsp;regions2&nbsp;=&nbsp;new&nbsp;CellRangeAddressList(1,&nbsp;65535,&nbsp;1,&nbsp;1);<br>DVConstraint&nbsp;constraint2&nbsp;=&nbsp;DVConstraint.CreateNumericConstraint(DVConstraint.ValidationType.INTEGER,DVConstraint.OperatorType.BETWEEN,&nbsp;&#8220;0&#8221;,&nbsp;&#8220;100&#8221;);<br>HSSFDataValidation&nbsp;dataValidate2&nbsp;=&nbsp;new&nbsp;HSSFDataValidation(regions2,&nbsp;constraint2);<br>dataValidate2.CreateErrorBox(&#8220;error&#8221;,&nbsp;&#8220;You&nbsp;must&nbsp;input&nbsp;a&nbsp;numeric&nbsp;between&nbsp;0&nbsp;and&nbsp;100.&#8221;);<br>sheet1.AddValidationData(dataValidate2);<\/p>\n\n\n\n<p>\u751f\u6210\u7684Excel\u6548\u679c\u4e3a\uff1a<br><br><br>\u4e0b\u4e00\u8282\u6211\u4eec\u5c06\u5b66\u4e60\u5229\u7528\u6570\u636e\u6709\u6548\u6027\u521b\u5efa\u4e0b\u62c9\u5217\u8868\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/24\/1572980.html\" target=\"_blank\" rel=\"noreferrer noopener\">2.6.8\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u751f\u6210\u4e0b\u62c9\u5217\u8868<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4e0a\u4e00\u8282\u6211\u4eec\u8bb2\u4e86\u7b80\u5355\u7684\u6570\u636e\u6709\u6548\u6027\u9a8c\u8bc1\uff0c\u8fd9\u4e00\u8282\u6211\u4eec\u5b66\u4e60\u4e00\u4e0b\u6570\u636e\u6709\u6548\u6027\u7684\u53e6\u4e00\u4e2a\u5e94\u7528\uff0d\uff0d\u4e0b\u62c9\u5217\u8868\u3002\u5728Excel\u4e2d\uff0c\u5e76\u6ca1\u6709\u7c7b\u4f3cWeb\u4e2d\u7684\u4e0b\u62c9\u63a7\u4ef6\uff0c\u5176\u4e0b\u62c9\u6548\u679c\u662f\u901a\u8fc7\u6570\u636e\u6709\u6548\u6027\u6765\u5b9e\u73b0\u7684\u3002\u8bbe\u7f6e\u6b65\u9aa4\u4e3a\uff1a<br>\uff081\uff09\u9009\u5b9a\u4e00\u4e2a\u8981\u751f\u6210\u4e0b\u62c9\u5217\u8868\u7684\u533a\u57df\uff1b<br>\uff082\uff09\u8bbe\u7f6e\u6570\u636e\u6709\u6548\u6027\u4e3a\u5e8f\u5217\uff0c\u5e76\u5728\u6765\u6e90\u4e2d\u586b\u5145\u53ef\u9009\u4e0b\u62c9\u7684\u503c\uff0c\u7528\u201c,\u201d\u9694\u5f00\uff08\u5982\u56fe\uff09\u3002<br><br>\u5bf9\u5e94\u7684\u6548\u679c\u4e3a\uff1a<br><br><br>\u540c\u6837\uff0c\u5229\u7528NPOI\u4ee3\u7801\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u4e0a\u9762\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br><br>CellRangeAddressList&nbsp;regions&nbsp;=&nbsp;new&nbsp;CellRangeAddressList(0,&nbsp;65535,&nbsp;0,&nbsp;0);<br>DVConstraint&nbsp;constraint&nbsp;=&nbsp;DVConstraint.CreateExplicitListConstraint(new&nbsp;string[]&nbsp;{&nbsp;&#8220;itemA&#8221;,&nbsp;&#8220;itemB&#8221;,&nbsp;&#8220;itemC&#8221;&nbsp;});<br>HSSFDataValidation&nbsp;dataValidate&nbsp;=&nbsp;new&nbsp;HSSFDataValidation(regions,&nbsp;constraint);<br>sheet1.AddValidationData(dataValidate);<\/p>\n\n\n\n<p>\u4e0b\u9762\u5bf9\u4ee3\u7801\u4f5c\u4e00\u4e0b\u7b80\u8981\u8bf4\u660e\uff1a<br>\u5148\u8bbe\u7f6e\u4e00\u4e2a\u9700\u8981\u63d0\u4f9b\u4e0b\u62c9\u7684\u533a\u57df\uff0c\u5173\u4e8eCellRangeAddressList\u6784\u9020\u51fd\u6570\u53c2\u6570\u7684\u8bf4\u660e\u8bf7\u53c2\u89c1<a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/22\/1572170.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u4e0a\u4e00\u8282<\/a>\uff1a<\/p>\n\n\n\n<p>CellRangeAddressList&nbsp;regions&nbsp;=&nbsp;new&nbsp;CellRangeAddressList(0,&nbsp;65535,&nbsp;0,&nbsp;0);<\/p>\n\n\n\n<p>\u7136\u540e\u5c06\u4e0b\u62c9\u9879\u4f5c\u4e3a\u4e00\u4e2a\u6570\u7ec4\u4f20\u7ed9CreateExplicitListConstraint\u4f5c\u4e3a\u53c2\u6570\u521b\u5efa\u4e00\u4e2a\u7ea6\u675f\uff0c\u6839\u636e\u8981\u63a7\u5236\u7684\u533a\u57df\u548c\u7ea6\u675f\u521b\u5efa\u6570\u636e\u6709\u6548\u6027\u5c31\u53ef\u4ee5\u4e86\u3002<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4f46\u662f\u8fd9\u6837\u4f1a\u6709\u4e00\u4e2a\u95ee\u9898\uff1aExcel\u4e2d\u5141\u8bb8\u8f93\u5165\u7684\u5e8f\u5217\u6765\u6e90\u957f\u5ea6\u6700\u5927\u4e3a255\u4e2a\u5b57\u7b26\uff0c\u4e5f\u5c31\u662f\u8bf4\u5f53\u4e0b\u62c9\u9879\u7684\u603b\u5b57\u7b26\u4e32\u957f\u5ea6\u8d85\u8fc7255\u662f\u5c06\u4f1a\u51fa\u9519\u3002\u90a3\u4e48\u5982\u679c\u4e0b\u62c9\u9879\u5f88\u591a\u7684\u60c5\u51b5\u4e0b\u5e94\u8be5\u600e\u4e48\u5904\u7406\u5462\uff1f\u7b54\u6848\u662f\u901a\u8fc7\u5f15\u7528\u7684\u65b9\u5f0f\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a<br>\u5148\u521b\u5efa\u4e00\u4e2aSheet\u4e13\u95e8\u7528\u4e8e\u5b58\u50a8\u4e0b\u62c9\u9879\u7684\u503c\uff0c\u5e76\u5c06\u5404\u4e0b\u62c9\u9879\u7684\u503c\u5199\u5165\u5176\u4e2d\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet2&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;ShtDictionary&#8221;);<br>sheet2.CreateRow(0).CreateCell(0).SetCellValue(&#8220;itemA&#8221;);<br>sheet2.CreateRow(1).CreateCell(0).SetCellValue(&#8220;itemB&#8221;);<br>sheet2.CreateRow(2).CreateCell(0).SetCellValue(&#8220;itemC&#8221;);<\/p>\n\n\n\n<p>\u7136\u540e\u5b9a\u4e49\u4e00\u4e2a\u540d\u79f0\uff0c\u6307\u5411\u521a\u624d\u521b\u5efa\u7684\u4e0b\u62c9\u9879\u7684\u533a\u57df\uff1a<\/p>\n\n\n\n<p>HSSFName&nbsp;range&nbsp;=&nbsp;hssfworkbook.CreateName();<br>range.Reference&nbsp;=&nbsp;&#8220;ShtDictionary!$A1:$A3&#8221;;<br>range.NameName&nbsp;=&nbsp;&#8220;dicRange&#8221;;<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u8bbe\u7f6e\u6570\u636e\u7ea6\u675f\u65f6\u6307\u5411\u8fd9\u4e2a\u540d\u79f0\u800c\u4e0d\u662f\u5b57\u7b26\u6570\u7ec4\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>CellRangeAddressList&nbsp;regions&nbsp;=&nbsp;new&nbsp;CellRangeAddressList(0,&nbsp;65535,&nbsp;0,&nbsp;0);<br><br>DVConstraint&nbsp;constraint&nbsp;=&nbsp;DVConstraint.CreateFormulaListConstraint(&#8220;dicRange&#8221;);<br>HSSFDataValidation&nbsp;dataValidate&nbsp;=&nbsp;new&nbsp;HSSFDataValidation(regions,&nbsp;constraint);<br>sheet1.AddValidationData(dataValidate);<\/p>\n\n\n\n<p>\u6267\u884c\u8fd9\u6bb5\u4ee3\u7801\uff0c\u751f\u6210\u7684Excel\u6548\u679c\u5982\u4e0b\uff1a<br><br>\u5728\u540d\u79f0\u7ba1\u7406\u5668\u4e2d\u4f1a\u53d1\u73b0\u6709\u4e00\u4e2a\u540d\u4e3a&#8221;dicRange&#8221;\u7684\u540d\u79f0\uff0c\u6307\u5411&#8221;ShtDictionary!$A1:$A3&#8243;\u7684\u4e0b\u62c9\u9879\u533a\u57df\uff1a<br><br>\u5728\u6570\u636e\u6709\u6548\u6027\u4e2d\u4f1a\u53d1\u73b0\u6765\u6e90\u53d8\u6210\u4e86&#8221;=dicRange&#8221;\uff0c\u6307\u5411\u4e0a\u9762\u5b9a\u4e49\u7684\u540d\u79f0\u3002\u800c\u4e0d\u662f\u4ee5\u524d\u7684&#8221;itemA,itemB,itemC&#8221;\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/08\/10\/1543242.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI 1.2\u6559\u7a0b<\/a>&nbsp;\u2013 3.1&nbsp;\u57fa\u4e8e.xls\u6a21\u677f\u751f\u6210Excel\u6587\u4ef6<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>NPOI\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com\/<\/a><\/p>\n\n\n\n<p>NPOI QQ\u4ea4\u6d41\u7fa4: 78142590&nbsp;<\/p>\n\n\n\n<p>\u5c3d\u7ba1NPOI\u80fd\u591f\u4ece\u5934\u5f00\u59cb\u751f\u6210Excel\u6587\u4ef6\uff0c\u4f46\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u6709\u5f88\u591a\u73b0\u6210\u7684\u8868\u683c\uff0c\u6211\u4eec\u4e0d\u53ef\u80fd\u6ca1\u4e8b\u5c31\u53bb\u4ece\u5934\u5f00\u59cb\u751f\u6210\u4e00\u4e2aExcel\uff0c\u66f4\u591a\u65f6\u5019\u6211\u4eec\u66f4\u613f\u610f\u9009\u62e9\u6bd4\u8f83\u5077\u61d2\u7684\u65b9\u6cd5\u2014\u2014\u90a3\u5c31\u662f\u7528\u6a21\u677f\u6587\u4ef6\u3002NPOI\u4e00\u5927\u7279\u8272\u4e4b\u4e00\u5c31\u662f\u80fd\u591f\u8f7b\u677e\u8bfb\u53d6Office Excel 97-2003\u7684\u683c\u5f0f\uff0c\u5373\u4f7f\u91cc\u9762\u6709NPOI\u4e0d\u652f\u6301\u7684VBA\u5b8f\u3001\u56fe\u8868\u4ee5\u53caPivot\u8868\u4e4b\u7c7b\u7684\u9ad8\u7ea7\u8bb0\u5f55\uff0cNPOI\u4e5f\u80fd\u591f\u4fdd\u8bc1\u4e0d\u4e22\u5931\u6570\u636e\uff08\u8bf4\u5b9e\u8bdd\uff0c\u8981\u5b8c\u5168\u80fd\u591f\u8bc6\u522b\u6240\u6709\u7684Excel\u5185\u90e8\u8bb0\u5f55\u51e0\u4e4e\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u66f4\u4f55\u51b5\u5982\u4eca\u53c8\u591a\u51fa\u4e86Office Excel 2007binary file\uff0c\u5373.xlsb\uff09\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u8f6c\u5165\u6b63\u9898\uff0c\u51fa\u4e8e\u6f14\u793a\u76ee\u7684\uff0c\u6211\u505a\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u9500\u552e\u91cf\u8868\uff0c\u91cc\u9762\u5e94\u7528\u4e86\u6587\u5b57\u989c\u8272\u3001\u80cc\u666f\u8272\u3001\u6587\u672c\u5c45\u4e2d\u3001\u516c\u5f0f\u3001\u5343\u5206\u4f4d\u5206\u9694\u7b26\u3001\u8fb9\u6846\u7b49\u6548\u679c\uff0c\u5f53\u7136\u5b9e\u9645\u7684\u751f\u4ea7\u73af\u5883\u91cc\u53ef\u80fd\u8fd8\u6709\u66f4\u52a0\u590d\u6742\u7684Excel\u6a21\u677f\u3002\u5982\u4e0b\u56fe<\/p>\n\n\n\n<p>\u6211\u4eec\u7684\u7a0b\u5e8f\u5c31\u662f\u8981\u586b\u514512\u4e2a\u6708\u7684\u9500\u552e\u91cf\uff0cTotal\u80fd\u591f\u81ea\u52a8\u6839\u636e\u586b\u5145\u7684\u503c\u8ba1\u7b97\u51fa\u603b\u91cf\u3002<\/p>\n\n\n\n<p>\uff08\u8fd9\u91cc\u8981\u63d0\u4e00\u4e0b\uff0c\u4ee5\u5f80\u5982\u679c\u6211\u4eec\u7528HTML\u65b9\u5f0f\u8f93\u51faxls\uff0c\u6211\u4eec\u5fc5\u987b\u5728\u670d\u52a1\u5668\u7aef\u505aTotal\u8ba1\u7b97\uff0c\u5e76\u4e14\u8fd9\u4e2a\u503c\u5728\u4e0b\u8f7d\u540e\u6c38\u8fdc\u90fd\u662f\u9759\u6001\u7684\uff0c\u6ca1\u6709\u516c\u5f0f\uff0c\u5373\u4f7f\u7528\u6237\u8981\u4fee\u6539\u91cc\u9762\u7684\u6570\u636e\uff0c\u603b\u503c\u4e5f\u4e0d\u4f1a\u6539\u53d8\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48NPOI\u4e00\u76f4\u63d0\u5021\u751f\u6210\u771f\u6b63\u7684Excel\u6587\u4ef6\u3002\uff09<\/p>\n\n\n\n<p>\u4ee3\u7801\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n\n\n\n<p>\/\/read thetemplate via FileStream, it is suggested to use FileAccess.Read to prevent filelock.<\/p>\n\n\n\n<p>\/\/book1.xlsis an Excel-2007-generated file, so some new unknown BIFF records are added.<\/p>\n\n\n\n<p>FileStreamfile =new&nbsp;FileStream(@&#8221;template\/book1.xls&#8221;, FileMode.Open,FileAccess.Read);<br><br>HSSFWorkbook hssfworkbook =&nbsp;new&nbsp;HSSFWorkbook(file);<br>HSSFSheet sheet1 = hssfworkbook.GetSheet(&#8220;Sheet1&#8221;);<br>sheet1.GetRow(1).GetCell(1).SetCellValue(200200);<br>sheet1.GetRow(2).GetCell(1).SetCellValue(300);<br>sheet1.GetRow(3).GetCell(1).SetCellValue(500050);<br>sheet1.GetRow(4).GetCell(1).SetCellValue(8000);<br>sheet1.GetRow(5).GetCell(1).SetCellValue(110);<br>sheet1.GetRow(6).GetCell(1).SetCellValue(100);<br>sheet1.GetRow(7).GetCell(1).SetCellValue(200);<br>sheet1.GetRow(8).GetCell(1).SetCellValue(210);<br>sheet1.GetRow(9).GetCell(1).SetCellValue(2300);<br>sheet1.GetRow(10).GetCell(1).SetCellValue(240);<br>sheet1.GetRow(11).GetCell(1).SetCellValue(180123);<br>sheet1.GetRow(12).GetCell(1).SetCellValue(150);<br><br>\/\/Force excel to recalculate all the formulawhile open<\/p>\n\n\n\n<p>sheet1.ForceFormulaRecalculation=true;<\/p>\n\n\n\n<p>FileStreamfile = new FileStream(@&#8221;test.xls&#8221;, FileMode.Create);<br>hssfworkbook.Write(file);<br>file.Close();<\/p>\n\n\n\n<p>\u9996\u5148\u6253\u5f00\u6a21\u677f\u6587\u4ef6\u65f6\u8981\u4f7f\u7528FileAccess.Read\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u8bc1\u6587\u4ef6\u4e0d\u88ab\u5360\u7528\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684ForceFormulaRecalculation\u662f\u5f3a\u5236\u8981\u6c42Excel\u5728\u6253\u5f00\u65f6\u91cd\u65b0\u8ba1\u7b97\u7684\u5c5e\u6027\uff0c\u5728\u62e5\u6709\u516c\u5f0f\u7684xls\u6587\u4ef6\u4e2d\u5341\u5206\u6709\u7528\uff0c\u5927\u5bb6\u4f7f\u7528\u65f6\u53ef\u522b\u5fd8\u4e86\u8bbe\u3002<\/p>\n\n\n\n<p>\u662f\u4e0d\u662f\u6bd4\u4f60\u60f3\u8c61\u7684\u7b80\u5355\uff1f\u4f60\u751a\u81f3\u4e0d\u7528\u53bb\u4e86\u89e3\u5b83\u662f\u5728\u4f55\u65f6\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u7684\uff0c\u5bf9\u4e8eNPOI\u7684\u4f7f\u7528\u8005\u6765\u8bf4\u57fa\u672c\u4e0a\u548c\u8bfb\u53d6\u666e\u901a\u6587\u4ef6\u6ca1\u6709\u4ec0\u4e48\u4e24\u6837\u3002<\/p>\n\n\n\n<p>\u6700\u7ec8\u751f\u6210\u7684\u6548\u679c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<p>\u53d1\u89c9\u6ca1\uff0c\u5c31\u8fde\u5343\u5206\u4f4d\u5206\u9694\u7b26\u4e5f\u90fd\u4fdd\u7559\u7740\uff0c\u4e00\u5207\u5c31\u50cf\u4eba\u5de5\u586b\u5199\u7684\u4e00\u6837\u3002<\/p>\n\n\n\n<p>\u672c\u8303\u4f8b\u5b8c\u6574\u4ee3\u7801\u8bf7\u89c1NPOI.Examples\u4e2d\u7684GenerateXlsFromXlsTemplate\u9879\u76ee\u3002<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/09\/29\/1576070.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.2\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd8\u8bb0\u5f97\u5c0f\u5b66\u65f6\u5019\u5b66\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u5417\uff1f\u8fd9\u8282\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\u5229\u7528NPOI\u901a\u8fc7C#\u4ee3\u7801\u751f\u6210\u4e00\u5f20Excel\u7684\u4e5d\u4e5d\u4e58\u6cd5\u8868\u3002\u8981\u751f\u6210\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u5faa\u73af\u80af\u5b9a\u662f\u5c11\u4e0d\u4e86\u7684\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFRow&nbsp;row;<br>HSSFCell&nbsp;cell;<br>for&nbsp;(int&nbsp;rowIndex&nbsp;=&nbsp;0;&nbsp;rowIndex&nbsp;&lt;&nbsp;9;&nbsp;rowIndex++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;colIndex&nbsp;=&nbsp;0;&nbsp;colIndex&nbsp;&lt;=&nbsp;rowIndex;&nbsp;colIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(colIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(String.Format(&#8220;{0}*{1}={2}&#8221;,&nbsp;rowIndex&nbsp;+&nbsp;1,&nbsp;colIndex&nbsp;+&nbsp;1,&nbsp;(rowIndex&nbsp;+&nbsp;1)&nbsp;*&nbsp;(colIndex&nbsp;+&nbsp;1)));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<\/p>\n\n\n\n<p><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u4ee3\u7801\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5faa\u73af\u8c03\u7528cell.SetCellValue(str)\u5199\u51659\u884c\u6570\u636e\uff0c\u6bcf\u4e00\u884c\u5199\u7684\u5355\u5143\u683c\u6570\u91cf\u968f\u884c\u6570\u9012\u589e\u3002\u6267\u884c\u5b8c\u540e\u751f\u6210\u7684Excel\u6837\u5f0f\u5982\u4e0b\uff1a<br><br><br>\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>Code<br>using&nbsp;System;<br>using&nbsp;System.Collections.Generic;<br>using&nbsp;System.Linq;<br>using&nbsp;System.Text;<br>using&nbsp;NPOI.HSSF.UserModel;<br>using&nbsp;System.IO;<br>using&nbsp;NPOI.HPSF;<br><br>namespace&nbsp;TimesTables<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;Program<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;HSSFWorkbook&nbsp;hssfworkbook;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;Main(string[]&nbsp;args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitializeWorkbook();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;row;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cell;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;rowIndex&nbsp;=&nbsp;0;&nbsp;rowIndex&nbsp;&lt;&nbsp;9;&nbsp;rowIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;colIndex&nbsp;=&nbsp;0;&nbsp;colIndex&nbsp;&lt;=&nbsp;rowIndex;&nbsp;colIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(colIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(String.Format(&#8220;{0}*{1}={2}&#8221;,&nbsp;rowIndex&nbsp;+&nbsp;1,&nbsp;colIndex&nbsp;+&nbsp;1,&nbsp;(rowIndex&nbsp;+&nbsp;1)&nbsp;*&nbsp;(colIndex&nbsp;+&nbsp;1)));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WriteToFile();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;WriteToFile()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Write&nbsp;the&nbsp;stream&nbsp;data&nbsp;of&nbsp;workbook&nbsp;to&nbsp;the&nbsp;root&nbsp;directory<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileStream&nbsp;file&nbsp;=&nbsp;new&nbsp;FileStream(@&#8221;test.xls&#8221;,&nbsp;FileMode.Create);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.Write(file);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;InitializeWorkbook()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook&nbsp;=&nbsp;new&nbsp;HSSFWorkbook();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;DocumentSummaryInformation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DocumentSummaryInformation&nbsp;dsi&nbsp;=&nbsp;PropertySetFactory.CreateDocumentSummaryInformation();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dsi.Company&nbsp;=&nbsp;&#8220;NPOI&nbsp;Team&#8221;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.DocumentSummaryInformation&nbsp;=&nbsp;dsi;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;SummaryInformation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SummaryInformation&nbsp;si&nbsp;=&nbsp;PropertySetFactory.CreateSummaryInformation();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;si.Subject&nbsp;=&nbsp;&#8220;NPOI&nbsp;SDK&nbsp;Example&#8221;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.SummaryInformation&nbsp;=&nbsp;si;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br><\/p>\n\n\n\n<p><br>using&nbsp;System;<br>using&nbsp;System.Collections.Generic;<br>using&nbsp;System.Linq;<br>using&nbsp;System.Text;<br>using&nbsp;NPOI.HSSF.UserModel;<br>using&nbsp;System.IO;<br>using&nbsp;NPOI.HPSF;<br><br>namespace&nbsp;TimesTables<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;Program<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;HSSFWorkbook&nbsp;hssfworkbook;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;Main(string[]&nbsp;args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitializeWorkbook();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;row;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cell;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;rowIndex&nbsp;=&nbsp;0;&nbsp;rowIndex&nbsp;&lt;&nbsp;9;&nbsp;rowIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;colIndex&nbsp;=&nbsp;0;&nbsp;colIndex&nbsp;&lt;=&nbsp;rowIndex;&nbsp;colIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(colIndex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(String.Format(&#8220;{0}*{1}={2}&#8221;,&nbsp;rowIndex&nbsp;+&nbsp;1,&nbsp;colIndex&nbsp;+&nbsp;1,&nbsp;(rowIndex&nbsp;+&nbsp;1)&nbsp;*&nbsp;(colIndex&nbsp;+&nbsp;1)));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WriteToFile();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;WriteToFile()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Write&nbsp;the&nbsp;stream&nbsp;data&nbsp;of&nbsp;workbook&nbsp;to&nbsp;the&nbsp;root&nbsp;directory<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileStream&nbsp;file&nbsp;=&nbsp;new&nbsp;FileStream(@&#8221;test.xls&#8221;,&nbsp;FileMode.Create);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.Write(file);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.Close();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;InitializeWorkbook()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook&nbsp;=&nbsp;new&nbsp;HSSFWorkbook();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;DocumentSummaryInformation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DocumentSummaryInformation&nbsp;dsi&nbsp;=&nbsp;PropertySetFactory.CreateDocumentSummaryInformation();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dsi.Company&nbsp;=&nbsp;&#8220;NPOI&nbsp;Team&#8221;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.DocumentSummaryInformation&nbsp;=&nbsp;dsi;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;SummaryInformation<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SummaryInformation&nbsp;si&nbsp;=&nbsp;PropertySetFactory.CreateSummaryInformation();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;si.Subject&nbsp;=&nbsp;&#8220;NPOI&nbsp;SDK&nbsp;Example&#8221;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.SummaryInformation&nbsp;=&nbsp;si;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br><br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/13\/1582832.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.3\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u751f\u6210\u4e00\u5f20\u5de5\u8d44\u5355<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u8fd9\u4e00\u8282\uff0c\u6211\u4eec\u5c06\u7efc\u5408NPOI\u7684\u5e38\u7528\u529f\u80fd\uff08\u5305\u62ec\u521b\u5efa\u548c\u586b\u5145\u5355\u5143\u683c\u3001\u5408\u5e76\u5355\u5143\u683c\u3001\u8bbe\u7f6e\u5355\u5143\u683c\u6837\u5f0f\u548c\u5229\u7528\u516c\u5f0f\uff09\uff0c\u505a\u4e00\u4e2a\u5de5\u8d44\u5355\u7684\u5b9e\u4f8b\u3002\u5148\u770b\u521b\u5efa\u6807\u9898\u884c\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>\/\/\u5199\u6807\u9898\u6587\u672c<br>HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>HSSFCell&nbsp;cellTitle&nbsp;=&nbsp;sheet1.CreateRow(0).CreateCell(0);<br>cellTitle.SetCellValue(&#8220;XXX\u516c\u53f82009\u5e7410\u6708\u5de5\u8d44\u5355&#8221;);<br><br>\/\/\u8bbe\u7f6e\u6807\u9898\u884c\u6837\u5f0f<br>HSSFCellStyle&nbsp;style&nbsp;=&nbsp;hssfworkbook.CreateCellStyle();<br>style.Alignment&nbsp;=&nbsp;HSSFCellStyle.ALIGN_CENTER;<br>HSSFFont&nbsp;font&nbsp;=&nbsp;hssfworkbook.CreateFont();<br>font.FontHeight&nbsp;=&nbsp;20&nbsp;*&nbsp;20;<br>style.SetFont(font);<br><br>cellTitle.CellStyle&nbsp;=&nbsp;style;<br><br>\/\/\u5408\u5e76\u6807\u9898\u884c<br>sheet1.AddMergedRegion(new&nbsp;Region(0,&nbsp;0,&nbsp;1,&nbsp;6));<\/p>\n\n\n\n<p><br>\u5176\u4e2d\u7528\u5230\u4e86\u6211\u4eec\u524d\u9762\u8bb2\u7684\u8bbe\u7f6e\u5355\u5143\u683c\u6837\u5f0f\u548c\u5408\u5e76\u5355\u5143\u683c\u7b49\u5185\u5bb9\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5faa\u73af\u521b\u5efa\u516c\u53f8\u6bcf\u4e2a\u5458\u5de5\u7684\u5de5\u8d44\u5355\uff1a<\/p>\n\n\n\n<p><br>DataTable&nbsp;dt=GetData();<br>HSSFRow&nbsp;row;<br>HSSFCell&nbsp;cell;<br>HSSFCellStyle&nbsp;celStyle=getCellStyle();<br><br>HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>HSSFClientAnchor&nbsp;anchor;<br>HSSFSimpleShape&nbsp;line;<br>int&nbsp;rowIndex;<br>for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;dt.Rows.Count;&nbsp;i++)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8868\u5934\u6570\u636e<br>&nbsp;&nbsp;&nbsp;&nbsp;rowIndex&nbsp;=&nbsp;3&nbsp;*&nbsp;(i&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u57fa\u672c\u5de5\u8d44&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(2);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u4f4f\u623f\u516c\u79ef\u91d1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(3);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u7ee9\u6548\u5956\u91d1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(4);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u793e\u4fdd\u6263\u6b3e&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(5);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u4ee3\u6263\u4e2a\u7a0e&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(6);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u5b9e\u53d1\u5de5\u8d44&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;DataRow&nbsp;dr&nbsp;=&nbsp;dt.Rows[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8bbe\u7f6e\u503c\u548c\u8ba1\u7b97\u516c\u5f0f<br>&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(dr[&#8220;FName&#8221;].ToString());<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FBasicSalary&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(2);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FAccumulationFund&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(3);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FBonus&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(4);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;$B{0}*0.08&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(5);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;SUM($B{0}:$D{0})*0.1&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(6);<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;SUM($B{0}:$D{0})-SUM($E{0}:$F{0})&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u7ed8\u5236\u5206\u9694\u7ebf<br>&nbsp;&nbsp;&nbsp;&nbsp;sheet1.AddMergedRegion(new&nbsp;Region(rowIndex+2,&nbsp;0,&nbsp;rowIndex+2,&nbsp;6));<br>&nbsp;&nbsp;&nbsp;&nbsp;anchor&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(0,&nbsp;125,&nbsp;1023,&nbsp;125,&nbsp;0,&nbsp;rowIndex&nbsp;+&nbsp;2,&nbsp;6,&nbsp;rowIndex&nbsp;+&nbsp;2);<br>&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;patriarch.CreateSimpleShape(anchor);<br>&nbsp;&nbsp;&nbsp;&nbsp;line.ShapeType&nbsp;=&nbsp;HSSFSimpleShape.OBJECT_TYPE_LINE;<br>&nbsp;&nbsp;&nbsp;&nbsp;line.LineStyle&nbsp;=&nbsp;HSSFShape.LINESTYLE_DASHGEL;<br><br>}<\/p>\n\n\n\n<p>\u5176\u4e2d\u4e3a\u4e86\u6587\u4ef6\u6253\u5370\u4e3a\u5355\u5143\u683c\u589e\u52a0\u4e86\u9ed1\u8272\u8fb9\u6846\u7684\u6837\u5f0f\uff08\u5982\u679c\u4e0d\u8bbe\u7f6e\u8fb9\u6846\u6837\u5f0f\uff0c\u6253\u5370\u51fa\u6765\u540e\u662f\u6ca1\u6709\u8fb9\u6846\u7684\uff09\u3002\u53e6\u5916\uff0c\u6ce8\u610f\u5faa\u73af\u8fc7\u7a0b\u4e2dexcel\u4e2d\u7684\u884c\u53f7\u968f\u6570\u636e\u6e90\u4e2d\u7684\u884c\u53f7\u53d8\u5316\u5904\u7406\u3002\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>using&nbsp;System;<br>using&nbsp;System.Collections.Generic;<br>using&nbsp;System.Linq;<br>using&nbsp;System.Text;<br>using&nbsp;NPOI.HSSF.UserModel;<br>using&nbsp;System.IO;<br>using&nbsp;NPOI.HPSF;<br>using&nbsp;NPOI.HSSF.Util;<br>using&nbsp;System.Data;<br><br>namespace&nbsp;Payroll<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;Program<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;HSSFWorkbook&nbsp;hssfworkbook;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;Main(string[]&nbsp;args)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InitializeWorkbook();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5199\u6807\u9898\u6587\u672c<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;hssfworkbook.CreateSheet(&#8220;Sheet1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cellTitle&nbsp;=&nbsp;sheet1.CreateRow(0).CreateCell(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellTitle.SetCellValue(&#8220;XXX\u516c\u53f82009\u5e7410\u6708\u5de5\u8d44\u5355&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8bbe\u7f6e\u6807\u9898\u884c\u6837\u5f0f<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCellStyle&nbsp;style&nbsp;=&nbsp;hssfworkbook.CreateCellStyle();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style.Alignment&nbsp;=&nbsp;HSSFCellStyle.ALIGN_CENTER;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFFont&nbsp;font&nbsp;=&nbsp;hssfworkbook.CreateFont();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font.FontHeight&nbsp;=&nbsp;20&nbsp;*&nbsp;20;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;style.SetFont(font);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellTitle.CellStyle&nbsp;=&nbsp;style;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5408\u5e76\u6807\u9898\u884c<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sheet1.AddMergedRegion(new&nbsp;Region(0,&nbsp;0,&nbsp;1,&nbsp;6));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;dt=GetData();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;row;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cell;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCellStyle&nbsp;celStyle=getCellStyle();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFPatriarch&nbsp;patriarch&nbsp;=&nbsp;sheet1.CreateDrawingPatriarch();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFClientAnchor&nbsp;anchor;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFSimpleShape&nbsp;line;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;rowIndex;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;dt.Rows.Count;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8868\u5934\u6570\u636e<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rowIndex&nbsp;=&nbsp;3&nbsp;*&nbsp;(i&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u59d3\u540d&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u57fa\u672c\u5de5\u8d44&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u4f4f\u623f\u516c\u79ef\u91d1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(3);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u7ee9\u6548\u5956\u91d1&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(4);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u793e\u4fdd\u6263\u6b3e&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(5);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u4ee3\u6263\u4e2a\u7a0e&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(6);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(&#8220;\u5b9e\u53d1\u5de5\u8d44&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataRow&nbsp;dr&nbsp;=&nbsp;dt.Rows[i];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u8bbe\u7f6e\u503c\u548c\u8ba1\u7b97\u516c\u5f0f<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(rowIndex&nbsp;+&nbsp;1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue(dr[&#8220;FName&#8221;].ToString());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FBasicSalary&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(2);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FAccumulationFund&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(3);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellValue((double)dr[&#8220;FBonus&#8221;]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(4);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;$B{0}*0.08&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(5);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;SUM($B{0}:$D{0})*0.1&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell&nbsp;=&nbsp;row.CreateCell(6);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.SetCellFormula(String.Format(&#8220;SUM($B{0}:$D{0})-SUM($E{0}:$F{0})&#8221;,rowIndex+2));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cell.CellStyle&nbsp;=&nbsp;celStyle;<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u7ed8\u5236\u5206\u9694\u7ebf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sheet1.AddMergedRegion(new&nbsp;Region(rowIndex+2,&nbsp;0,&nbsp;rowIndex+2,&nbsp;6));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;anchor&nbsp;=&nbsp;new&nbsp;HSSFClientAnchor(0,&nbsp;125,&nbsp;1023,&nbsp;125,&nbsp;0,&nbsp;rowIndex&nbsp;+&nbsp;2,&nbsp;6,&nbsp;rowIndex&nbsp;+&nbsp;2); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line&nbsp;=&nbsp;patriarch.CreateSimpleShape(anchor); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.ShapeType&nbsp;=&nbsp;HSSFSimpleShape.OBJECT_TYPE_LINE; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.LineStyle&nbsp;=&nbsp;HSSFShape.LINESTYLE_DASHGEL; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WriteToFile(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;DataTable&nbsp;GetData() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;dt&nbsp;=&nbsp;new&nbsp;DataTable(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#8220;FName&#8221;,typeof(System.String)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#8220;FBasicSalary&#8221;,typeof(System.Double)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#8220;FAccumulationFund&#8221;,&nbsp;typeof(System.Double)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add(&#8220;FBonus&#8221;,&nbsp;typeof(System.Double)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u4ee4\u72d0\u51b2&#8221;,&nbsp;6000,&nbsp;1000,&nbsp;2000); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u4efb\u76c8\u76c8&#8221;,&nbsp;7000,&nbsp;1000,&nbsp;2500); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u6797\u5e73\u4e4b&#8221;,&nbsp;5000,&nbsp;1000,&nbsp;1500); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u5cb3\u7075\u73ca&#8221;,&nbsp;4000,&nbsp;1000,&nbsp;900); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u4efb\u6211\u884c&#8221;,&nbsp;4000,&nbsp;1000,&nbsp;800); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(&#8220;\u98ce\u6e05\u626c&#8221;,&nbsp;9000,&nbsp;5000,&nbsp;3000); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;dt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;HSSFCellStyle&nbsp;getCellStyle() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFCellStyle&nbsp;cellStyle&nbsp;=&nbsp;hssfworkbook.CreateCellStyle(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellStyle.BorderBottom&nbsp;=&nbsp;HSSFCellStyle.BORDER_THIN; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellStyle.BorderLeft&nbsp;=&nbsp;HSSFCellStyle.BORDER_THIN; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellStyle.BorderRight&nbsp;=&nbsp;HSSFCellStyle.BORDER_THIN; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cellStyle.BorderTop&nbsp;=&nbsp;HSSFCellStyle.BORDER_THIN; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;cellStyle; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;WriteToFile() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Write&nbsp;the&nbsp;stream&nbsp;data&nbsp;of&nbsp;workbook&nbsp;to&nbsp;the&nbsp;root&nbsp;directory &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileStream&nbsp;file&nbsp;=&nbsp;new&nbsp;FileStream(@&#8221;test.xls&#8221;,&nbsp;FileMode.Create); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.Write(file); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.Close(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;void&nbsp;InitializeWorkbook() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook&nbsp;=&nbsp;new&nbsp;HSSFWorkbook(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;DocumentSummaryInformation &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DocumentSummaryInformation&nbsp;dsi&nbsp;=&nbsp;PropertySetFactory.CreateDocumentSummaryInformation(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dsi.Company&nbsp;=&nbsp;&#8220;NPOI&nbsp;Team&#8221;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.DocumentSummaryInformation&nbsp;=&nbsp;dsi; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/create&nbsp;a&nbsp;entry&nbsp;of&nbsp;SummaryInformation &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SummaryInformation&nbsp;si&nbsp;=&nbsp;PropertySetFactory.CreateSummaryInformation(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;si.Subject&nbsp;=&nbsp;&#8220;NPOI&nbsp;SDK&nbsp;Example&#8221;; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hssfworkbook.SummaryInformation&nbsp;=&nbsp;si; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} }<\/p>\n\n\n\n<p>\u751f\u6210\u7684Excel\u6587\u4ef6\u6837\u5f0f\u5982\u4e0b\uff1a<br><\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/18\/1585536.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.4\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u4eceExcel\u4e2d\u62bd\u53d6\u6587\u672c<\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u6211\u4eec\u77e5\u9053\uff0c\u641c\u7d22\u5f15\u64ce\u6700\u64c5\u957f\u5904\u7406\u7684\u5c31\u662f\u6587\u672c\uff0c\u800cExcel\u4e2d\u7684\u5185\u5bb9\u5e76\u4e0d\u662f\u4ee5\u6587\u672c\u65b9\u5f0f\u5b58\u50a8\u7684\u3002\u90a3\u4e48\u5982\u679c\u60f3\u8981\u641c\u7d22\u5f15\u64ce\u722c\u866b\u80fd\u591f\u6293\u53d6\u5230Excel\u4e2d\u7684\u5185\u5bb9\u662f\u6bd4\u8f83\u56f0\u96be\u7684\uff0c\u9664\u975e\u641c\u7d22\u5f15\u64ce\u722c\u866b\u5bf9Excel\u683c\u5f0f\u8fdb\u884c\u4e13\u95e8\u7684\u5904\u7406\u3002\u90a3\u4e48\u6709\u6ca1\u6709\u529e\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u5462\uff1f\u6709,\u901a\u8fc7NPOI\u5c06Excel\u5185\u5bb9\u6587\u672c\u5316\uff01<\/p>\n\n\n\n<p>\u3000\u3000\u5982\u4e0b\uff0c\u6709\u8fd9\u6837\u4e00\u5f20Excel\uff0c\u5982\u679c\u60f3\u8ba9\u5b83\u88ab\u641c\u7d22\u5f15\u64ce\u6536\u5f55\uff0c\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4ee5HTML\u5f62\u5f0f\u5c55\u73b0\uff0c\u4f46\u5c06\u4e00\u4e2a\u4e2a\u8fd9\u6837\u7684Excel\u624b\u5de5\u505a\u6210HTML\u9875\u9762\u663e\u7136\u6bd4\u8f83\u9ebb\u70e6\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u63d0\u4f9b\u4e00\u79cd\u65b9\u6848\uff0c\u81ea\u52a8\u5c06Excel\u4e2d\u7684\u5185\u5bb9\u4ee5HTML\u5f62\u5f0f\u5c55\u73b0\u3002<\/p>\n\n\n\n<p>\u3000\u3000\u5176\u5b9e\u57fa\u672c\u601d\u60f3\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u901a\u8fc7NPOI\u8bfb\u53d6\u6bcf\u4e2aCell\u4e2d\u7684\u5185\u5bb9\uff0c\u7136\u540e\u4ee5HTML\u7684\u5f62\u5f0f\u8f93\u51fa\u3002\u4f46\u8981\u4fdd\u8bc1\u8f93\u51fa\u7684HTML\u9875\u9762\u5e03\u5c40\u4e0eExcel\u4e2d\u7684\u4e00\u81f4\uff0c\u8fd8\u6709\u70b9\u5c0f\u6280\u5de7\u3002\u4e0b\u9762\u662f\u6784\u9020Table\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>private&nbsp;HSSFSheet&nbsp;sht;<br>protected&nbsp;String&nbsp;excelContent;<br><br>protected&nbsp;void&nbsp;Page_Load(object&nbsp;sender,&nbsp;EventArgs&nbsp;e)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFWorkbook&nbsp;wb&nbsp;=&nbsp;new&nbsp;HSSFWorkbook(new&nbsp;FileStream(Server.MapPath(&#8220;App_Data\/quotation.xls&#8221;),&nbsp;FileMode.Open));<br>&nbsp;&nbsp;&nbsp;&nbsp;sht&nbsp;=&nbsp;wb.GetSheet(&#8220;Sheet1&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u53d6\u884cExcel\u7684\u6700\u5927\u884c\u6570<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;rowsCount&nbsp;=&nbsp;sht.PhysicalNumberOfRows;<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4e3a\u4fdd\u8bc1Table\u5e03\u5c40\u4e0eExcel\u4e00\u6837\uff0c\u8fd9\u91cc\u5e94\u8be5\u53d6\u6240\u6709\u884c\u4e2d\u7684\u6700\u5927\u5217\u6570\uff08\u9700\u8981\u904d\u5386\u6574\u4e2aSheet\uff09\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u4e3a\u5c11\u4e00\u4ea4\u5168Excel\u904d\u5386\uff0c\u63d0\u9ad8\u6027\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u4eba\u4e3a\u628a\u7b2c0\u884c\u7684\u5217\u6570\u8c03\u6574\u81f3\u6240\u6709\u884c\u4e2d\u7684\u6700\u5927\u5217\u6570\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;colsCount&nbsp;=&nbsp;sht.GetRow(0).PhysicalNumberOfCells;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;colSpan;<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;rowSpan;<br>&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;isByRowMerged;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;StringBuilder&nbsp;table&nbsp;=&nbsp;new&nbsp;StringBuilder(rowsCount&nbsp;*&nbsp;32);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;table&nbsp;border=&#8217;1px&#8217;&gt;&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;rowIndex&nbsp;=&nbsp;0;&nbsp;rowIndex&nbsp;&lt;&nbsp;rowsCount;&nbsp;rowIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;tr&gt;&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;colIndex&nbsp;=&nbsp;0;&nbsp;colIndex&nbsp;&lt;&nbsp;colsCount;&nbsp;colIndex++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetTdMergedInfo(rowIndex,&nbsp;colIndex,&nbsp;out&nbsp;colSpan,&nbsp;out&nbsp;rowSpan,&nbsp;out&nbsp;isByRowMerged);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5982\u679c\u5df2\u7ecf\u88ab\u884c\u5408\u5e76\u5305\u542b\u8fdb\u53bb\u4e86\u5c31\u4e0d\u8f93\u51faTD\u4e86\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6ce8\u610f\u88ab\u5408\u5e76\u7684\u884c\u6216\u5217\u4e0d\u8f93\u51fa\u7684\u5904\u7406\u65b9\u5f0f\u4e0d\u4e00\u6837\uff0c\u89c1\u4e0b\u9762\u4e00\u5904\u7684\u6ce8\u91ca\u8bf4\u660e\u4e86\u5217\u5408\u5e76\u540e\u4e0d\u8f93\u51faTD\u7684\u5904\u7406\u65b9\u5f0f\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isByRowMerged)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;td&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(colSpan&nbsp;&gt;&nbsp;1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(string.Format(&#8221;&nbsp;colSpan={0}&#8221;,&nbsp;colSpan));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(rowSpan&nbsp;&gt;&nbsp;1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(string.Format(&#8221;&nbsp;rowSpan={0}&#8221;,&nbsp;rowSpan));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&gt;&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(sht.GetRow(rowIndex).GetCell(colIndex));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5217\u88ab\u5408\u5e76\u4e4b\u540e\u6b64\u884c\u5c06\u5c11\u8f93\u51facolSpan-1\u4e2aTD\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(colSpan&nbsp;&gt;&nbsp;1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colIndex&nbsp;+=&nbsp;colSpan&nbsp;&#8211;&nbsp;1;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;\/td&gt;&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;\/tr&gt;&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;table.Append(&#8220;&lt;\/table&gt;&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;this.excelContent&nbsp;=&nbsp;table.ToString();<br>}<\/p>\n\n\n\n<p>\u3000\u3000\u5176\u4e2d\u7528\u5230\u7684GetTdMergedInfo\u65b9\u6cd5\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\/\/\/&nbsp;&lt;summary&gt;<br>\/\/\/&nbsp;&nbsp;\u83b7\u53d6Table\u67d0\u4e2aTD\u5408\u5e76\u7684\u5217\u6570\u548c\u884c\u6570\u7b49\u4fe1\u606f\u3002\u4e0eExcel\u4e2d\u5bf9\u5e94Cell\u7684\u5408\u5e76\u884c\u6570\u548c\u5217\u6570\u4e00\u81f4\u3002<br>\/\/\/&nbsp;&lt;\/summary&gt;<br>\/\/\/&nbsp;&lt;param&nbsp;name=&#8221;rowIndex&#8221;&gt;\u884c\u53f7&lt;\/param&gt;<br>\/\/\/&nbsp;&lt;param&nbsp;name=&#8221;colIndex&#8221;&gt;\u5217\u53f7&lt;\/param&gt;<br>\/\/\/&nbsp;&lt;param&nbsp;name=&#8221;colspan&#8221;&gt;TD\u4e2d\u9700\u8981\u5408\u5e76\u7684\u884c\u6570&lt;\/param&gt;<br>\/\/\/&nbsp;&lt;param&nbsp;name=&#8221;rowspan&#8221;&gt;TD\u4e2d\u9700\u8981\u5408\u5e76\u7684\u5217\u6570&lt;\/param&gt;<br>\/\/\/&nbsp;&lt;param&nbsp;name=&#8221;rowspan&#8221;&gt;\u6b64\u5355\u5143\u683c\u662f\u5426\u88ab\u67d0\u4e2a\u884c\u5408\u5e76\u5305\u542b\u5728\u5185\u3002\u5982\u679c\u88ab\u5305\u542b\u5728\u5185\uff0c\u5c06\u4e0d\u8f93\u51faTD\u3002&lt;\/param&gt;<br>\/\/\/&nbsp;&lt;returns&gt;&lt;\/returns&gt;<br>private&nbsp;void&nbsp;GetTdMergedInfo(int&nbsp;rowIndex,&nbsp;int&nbsp;colIndex,&nbsp;out&nbsp;int&nbsp;colspan,&nbsp;out&nbsp;int&nbsp;rowspan,&nbsp;out&nbsp;bool&nbsp;isByRowMerged)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;colspan&nbsp;=&nbsp;1;<br>&nbsp;&nbsp;&nbsp;&nbsp;rowspan&nbsp;=&nbsp;1;<br>&nbsp;&nbsp;&nbsp;&nbsp;isByRowMerged&nbsp;=&nbsp;false;<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;regionsCuont&nbsp;=&nbsp;sht.NumMergedRegions;<br>&nbsp;&nbsp;&nbsp;&nbsp;Region&nbsp;region;<br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;regionsCuont;&nbsp;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;region&nbsp;=&nbsp;sht.GetMergedRegionAt(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(region.RowFrom&nbsp;==&nbsp;rowIndex&nbsp;&amp;&amp;&nbsp;region.ColumnFrom&nbsp;==&nbsp;colIndex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;colspan&nbsp;=&nbsp;region.ColumnTo&nbsp;&#8211;&nbsp;region.ColumnFrom&nbsp;+&nbsp;1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rowspan&nbsp;=&nbsp;region.RowTo&nbsp;&#8211;&nbsp;region.RowFrom&nbsp;+&nbsp;1;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;if&nbsp;(rowIndex&nbsp;&gt;&nbsp;region.RowFrom&nbsp;&amp;&amp;&nbsp;rowIndex&nbsp;&lt;=&nbsp;region.RowTo&nbsp;&amp;&amp;&nbsp;colIndex&gt;=region.ColumnFrom&nbsp;&amp;&amp;&nbsp;colIndex&lt;=region.ColumnTo)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;isByRowMerged&nbsp;=&nbsp;true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<\/p>\n\n\n\n<p>\u6700\u540e\u5728apsx\u9875\u9762\u4e2d\u8f93\u51fa\u6784\u5efa\u597d\u7684Table\uff1a<\/p>\n\n\n\n<p>&lt;%=excelContent&nbsp;%&gt;<\/p>\n\n\n\n<p>\u6267\u884c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u6211\u4eec\u53d1\u73b0\uff0c\u4e0eExcel\u4e2d\u7684\u5e03\u5c40\u5b8c\u5168\u4e00\u6837\uff08\u8fd9\u91cc\u6ca1\u6709\u5904\u7406\u5355\u5143\u683c\u7684\u6837\u5f0f\uff0c\u53ea\u5904\u7406\u4e86\u5185\u5bb9\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u4e5f\u53ef\u4ee5\u5c06Excel\u4e2d\u5355\u5143\u683c\u7684\u6837\u5f0f\u4e5f\u5e94\u7528\u5728HTML\u4e2d\uff09\u3002\u8fd9\u91cc\u4e3a\u4fdd\u8bc1\u5e03\u5c40\u4e00\u81f4\uff0c\u4e3b\u8981\u662f\u5c06Excel\u4e2d\u7684Region\u4fe1\u606f\u89e3\u6790\u6210Table\u7684colSpan\u548crowSpan\u5c5e\u6027\uff0c\u5982\u679c\u5bf9\u8fd9\u4e24\u4e2a\u5c5e\u6027\u4e0d\u592a\u4e86\u89e3\uff0c\u53ef\u4ee5\u7ed3\u5408\u4ee5\u4e0b\u4ee3\u7801\u548c\u793a\u4f8b\u52a0\u4ee5\u4e86\u89e3\uff1a<\/p>\n\n\n\n<p>&lt;table&nbsp;width=&#8221;300px&#8221;&nbsp;border=&#8221;1px&#8221;&gt;<br>&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;colspan=&#8221;2&#8243;&nbsp;rowspan=&#8221;2&#8243;&gt;0,0&lt;\/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;0,3&lt;\/td&gt;<br>&lt;\/tr&gt;<br>&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;1,3&lt;\/td&gt;<br>&lt;\/tr&gt;<br>&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;rowspan=&#8221;2&#8243;&gt;2,0&lt;\/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;colspan=&#8221;2&#8243;&gt;2,1&lt;\/td&gt;<br>&lt;\/tr&gt;<br>&lt;tr&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;3,1&lt;\/td&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;3,2&lt;\/td&gt;<br>&lt;\/tr&gt;<br>&lt;\/table&gt;<\/p>\n\n\n\n<p>&nbsp;\u4ee5\u4e0aHTML\u4ee3\u7801\u5bf9\u5e94\u7684Table\u5c55\u73b0\u4e3a\uff1a<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/atao\/archive\/2009\/10\/25\/1589606.html\" target=\"_blank\" rel=\"noreferrer noopener\">3.5\u7528<\/a>NPOI\u64cd\u4f5cEXCEL\uff0d\uff0d\u5de7\u5999\u4f7f\u7528Excel Chart<\/strong><\/p>\n\n\n\n<p>\u3000\u3000\u5728NPOI\u4e2d\uff0c\u672c\u8eab\u5e76\u4e0d\u652f\u6301Chart\u7b49\u9ad8\u7ea7\u5bf9\u8c61\u7684\u521b\u5efa\uff0c\u4f46\u901a\u8fc7l\u6a21\u677f\u7684\u65b9\u5f0f\u53ef\u4ee5\u5de7\u5999\u5730\u5229\u7528Excel\u5f3a\u5927\u7684\u900f\u89c6\u548c\u56fe\u8868\u529f\u80fd\uff0c\u8bf7\u770b\u4ee5\u4e0b\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5efa\u7acb\u6a21\u677f\u6587\u4ef6\uff0c\u5b9a\u4e49\u4e24\u5217\u4ee5\u53ca\u6307\u5411\u6b64\u533a\u57df\u7684\u540d\u79f0\u201csales\u201d\uff1a<\/p>\n\n\n\n<p>\u521b\u5efa\u6570\u636e\u8868\uff0c\u6570\u636e\u6765\u6e90\u586b\u5165\u521a\u624d\u5b9a\u4e49\u7684\u533a\u57df\uff1a<\/p>\n\n\n\n<p>\u6700\u540e\u751f\u6210\u7684\u6570\u636e\u900f\u89c6\u8868\u6240\u5728Sheet\u7684\u6837\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0c\u6a21\u677f\u5df2\u7ecf\u5efa\u597d\uff0c\u53e6\u5b58\u4e3a\u201cD:\\MyProject\\NPOIDemo\\Chart\\Book2.xls\u201d\u3002\u6211\u4eec\u53d1\u73b0\uff0c\u6a21\u677f\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u201c\u7a7a\u67b6\u5b50\u201d\uff0c\u4ec5\u4ec5\u6709\u64cd\u4f5c\u65b9\u5f0f\u6ca1\u5e76\u6ca1\u6709\u4efb\u4f55\u6570\u636e\u3002\u4e0b\u4e00\u6b65\uff0c\u6211\u4eec\u5f80\u8fd9\u4e2a\u201c\u7a7a\u67b6\u5b50\u201d\u4e2d\u586b\u5165\u6570\u636e\u3002\u6211\u4eec\u901a\u8fc7\u5982\u4e0b\u4ee3\u7801\u5f80\u8fd9\u4e2a\u201c\u7a7a\u67b6\u5b50\u201d\u4e2d\u5199\u5165\u6570\u636e\uff1a<\/p>\n\n\n\n<p>static&nbsp;void&nbsp;Main(string[]&nbsp;args)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFWorkbook&nbsp;wb&nbsp;=&nbsp;new&nbsp;HSSFWorkbook(new&nbsp;FileStream(@&#8221;D:\\MyProject\\NPOIDemo\\Chart\\Book2.xls&#8221;,&nbsp;FileMode.Open));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFSheet&nbsp;sheet1&nbsp;=&nbsp;wb.GetSheet(&#8220;Sheet1&#8221;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(0).SetCellValue(&#8220;\u4ee4\u72d0\u51b2&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(1).SetCellValue(50000);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(2);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(0).SetCellValue(&#8220;\u4efb\u76c8\u76c8&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(1).SetCellValue(30000);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(3);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(0).SetCellValue(&#8220;\u98ce\u6e05\u626c&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(1).SetCellValue(80000);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;row&nbsp;=&nbsp;sheet1.CreateRow(4);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(0).SetCellValue(&#8220;\u4efb\u6211\u884c&#8221;);<br>&nbsp;&nbsp;&nbsp;&nbsp;row.CreateCell(1).SetCellValue(20000);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/Write&nbsp;the&nbsp;stream&nbsp;data&nbsp;of&nbsp;workbook&nbsp;to&nbsp;the&nbsp;root&nbsp;directory<br>&nbsp;&nbsp;&nbsp;&nbsp;FileStream&nbsp;file&nbsp;=&nbsp;new&nbsp;FileStream(@&#8221;test.xls&#8221;,&nbsp;FileMode.Create);<br>&nbsp;&nbsp;&nbsp;&nbsp;wb.Write(file);<br>&nbsp;&nbsp;&nbsp;&nbsp;file.Close();<br>}<\/p>\n\n\n\n<p>\u6253\u5f00\u751f\u6210\u7684test.xls\u6587\u4ef6\uff0c\u53d1\u73b0\u6570\u636e\u5df2\u7ecf\u88ab\u586b\u8fdb\u53bb\u4e86\uff1a<\/p>\n\n\n\n<p>\u518d\u770b\u6570\u636e\u900f\u89c6\u8868\uff0c\u4e5f\u6709\u6570\u636e\u4e86\uff1a<\/p>\n\n\n\n<p>\u603b\u7ed3\uff1a<br>Excel\u6709\u7740\u5f3a\u5927\u7684\u62a5\u8868\u900f\u89c6\u548c\u56fe\u8868\u529f\u80fd\uff0c\u800c\u4e14\u7b80\u5355\u6613\u7528\uff0c\u5229\u7528NPOI\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u5145\u5206\u5229\u7528\u3002\u5728\u505a\u56fe\u5f62\u62a5\u8868\u3001\u900f\u89c6\u62a5\u8868\u65f6\u5c06\u975e\u5e38\u6709\u7528\uff01<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/12\/25\/1631075.html\" target=\"_blank\" rel=\"noreferrer noopener\">NPOI\u5b9e\u8df5<\/a>: .NET\u5bfc\u5165Excel\u6587\u4ef6\u7684\u53e6\u4e00\u79cd\u9009\u62e9<\/strong><\/p>\n\n\n\n<p>\u4f5c\u8005\uff1aTony Qu<\/p>\n\n\n\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/npoi.codeplex.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/npoi.codeplex.com<\/a>&nbsp;| NPOI QQ\u4ea4\u6d41\u7fa4:&nbsp; 78142590<\/p>\n\n\n\n<p>NPOI\u4e4b\u6240\u4ee5\u5f3a\u5927\uff0c\u5e76\u4e0d\u662f\u56e0\u4e3a\u5b83\u652f\u6301\u5bfc\u51faExcel\uff0c\u800c\u662f\u56e0\u4e3a\u5b83\u652f\u6301\u5bfc\u5165Excel\uff0c\u5e76\u80fd\u201c\u7406\u89e3\u201dOLE2\u6587\u6863\u7ed3\u6784\uff0c\u8fd9\u4e5f\u662f\u5176\u4ed6\u4e00\u4e9bExcel\u8bfb\u5199\u5e93\u6bd4\u8f83\u5f31\u7684\u65b9\u9762\u3002\u901a\u5e38\uff0c\u8bfb\u5165\u5e76\u7406\u89e3\u7ed3\u6784\u8fdc\u6bd4\u5bfc\u51fa\u6765\u5f97\u590d\u6742\uff0c\u56e0\u4e3a\u5bfc\u5165\u4f60\u5fc5\u987b\u5047\u8bbe\u4e00\u5207\u60c5\u51b5\u90fd\u662f\u53ef\u80fd\u7684\uff0c\u800c\u751f\u6210\u4f60\u53ea\u8981\u4fdd\u8bc1\u6ee1\u8db3\u4f60\u81ea\u5df1\u9700\u6c42\u5c31\u53ef\u4ee5\u4e86\uff0c\u5982\u679c\u628a\u5bfc\u5165\u9700\u6c42\u548c\u751f\u6210\u9700\u6c42\u6bd4\u505a\u4e24\u4e2a\u96c6\u5408\uff0c\u90a3\u4e48\u751f\u6210\u9700\u6c42\u901a\u5e38\u90fd\u662f\u5bfc\u5165\u9700\u6c42\u7684\u5b50\u96c6\uff0c\u8fd9\u4e00\u89c4\u5f8b\u4e0d\u4ec5\u4f53\u73b0\u5728Excel\u8bfb\u5199\u5e93\u4e2d\uff0c\u4e5f\u4f53\u73b0\u5728pdf\u8bfb\u5199\u5e93\u4e2d\uff0c\u76ee\u524d\u5e02\u9762\u4e0a\u5927\u90e8\u5206\u7684pdf\u5e93\u4ec5\u652f\u6301\u751f\u6210\uff0c\u4e0d\u652f\u6301\u5bfc\u5165\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u4e0d\u76f8\u4fe1NPOI\u80fd\u591f\u5f88\u597d\u7684\u7406\u89e3OLE2\u6587\u6863\u683c\u5f0f\uff0c\u90a3\u5c31\u53bb\u4e0b\u8f7d<a href=\"http:\/\/npoi.codeplex.com\/Release\/ProjectReleases.aspx?ReleaseId=23409\" target=\"_blank\" rel=\"noreferrer noopener\">POIFS Brower<\/a>\u3002\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u8fd9\u7bc7\u6587\u7ae0\u7684\u4ecb\u7ecd\uff1a<a href=\"http:\/\/www.cnblogs.com\/tonyqus\/archive\/2009\/09\/15\/office_2003_file_format.html\" target=\"_blank\" rel=\"noreferrer noopener\">Office\u6587\u4ef6\u683c\u5f0f\u89e3\u60d1<\/a>\u3002\u5f53\u7136\u5355\u5355\u7406\u89e3OLE2\u662f\u4e0d\u591f\u7684\uff0c\u56e0\u4e3aExcel\u6587\u4ef6\u683c\u5f0f\u662fBIFF\uff0c\u4f46BIFF\u662f\u4ee5OLE2\u4e3a\u57fa\u7840\u7684\uff0c\u505a\u4e2a\u5f88\u5f62\u8c61\u7684\u6bd4\u55bb\u5c31\u662f\uff1aOLE2\u76f8\u5f53\u4e8e\u78c1\u76d8\u7684FAT\u683c\u5f0f\uff0cBIFF\u76f8\u5f53\u4e8e\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u3002NPOI\u8d1f\u8d23\u7406\u89e3BIFF\u683c\u5f0f\u7684\u4ee3\u7801\u57fa\u672c\u90fd\u5728HSSF\u547d\u540d\u7a7a\u95f4\u91cc\u9762\u3002<\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u521a\u624d\u5e9f\u8bdd\u4e86\u4e00\u4f1a\u513f\uff0c\u4e3b\u8981\u662f\u7ed9\u5927\u5bb6\u6253\u6253\u57fa\u7840\uff0c\u73b0\u5728\u8fdb\u5165\u6b63\u9898\u3002<\/p>\n\n\n\n<p>\u672c\u6587\u5c06\u4ee5DataTable\u4e3a\u5bb9\u5668\u8bfb\u5165\u67d0xls\u7684\u7b2c\u4e00\u4e2a\u5de5\u4f5c\u8868\u7684\u6570\u636e\uff08\u6700\u8fd1\u7fa4\u91cc\u9762\u5f88\u591a\u4eba\u95ee\u8fd9\u4e2a\u95ee\u9898\uff09\u3002<\/p>\n\n\n\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u8865\u4e9b\u57fa\u7840\u77e5\u8bc6\u3002\u6bcf\u4e00\u4e2axls\u90fd\u5bf9\u5e94\u4e00\u4e2a\u552f\u4e00\u7684HSSFWorkbook\uff0c\u6bcf\u4e00\u4e2aHSSFWorkbook\u4f1a\u6709\u82e5\u5e72\u4e2aHSSFSheet\uff0c\u800c\u6bcf\u4e00\u4e2aHSSFSheet\u5305\u542b\u82e5\u5e72HSSFRow\uff08Excel 2003\u4e2d\u4e0d\u5f97\u8d85\u8fc765535\u884c\uff09\uff0c\u6bcf\u4e00\u4e2aHSSFRow\u53c8\u5305\u542b\u82e5\u5e72\u4e2aHSSFCell\uff08Excel 2003\u4e2d\u4e0d\u5f97\u8d85\u8fc7256\u5217\uff09\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u904d\u5386\u6240\u6709\u7684\u5355\u5143\u683c\uff0c\u6211\u4eec\u5c31\u5f97\u83b7\u5f97\u67d0\u4e00\u4e2aHSSFSheet\u7684\u6240\u6709HSSFRow\uff0c\u901a\u5e38\u53ef\u4ee5\u7528HSSFSheet.GetRowEnumerator()\u3002\u5982\u679c\u8981\u83b7\u5f97\u67d0\u4e00\u7279\u5b9a\u884c\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528HSSFSheet.GetRow(rowIndex)\u3002\u53e6\u5916\u8981\u904d\u5386\u6211\u4eec\u5c31\u5fc5\u987b\u77e5\u9053\u8fb9\u754c\uff0c\u6709\u4e00\u4e9b\u5c5e\u6027\u6211\u4eec\u662f\u53ef\u4ee5\u7528\u7684\uff0c\u6bd4\u5982HSSFSheet.FirstRowNum\uff08\u5de5\u4f5c\u8868\u4e2d\u7b2c\u4e00\u4e2a\u6709\u6570\u636e\u884c\u7684\u884c\u53f7\uff09\u3001HSSFSheet.LastRowNum\uff08\u5de5\u4f5c\u8868\u4e2d\u6700\u540e\u4e00\u4e2a\u6709\u6570\u636e\u884c\u7684\u884c\u53f7\uff09\u3001HSSFRow.FirstCellNum\uff08\u4e00\u884c\u4e2d\u7b2c\u4e00\u4e2a\u6709\u6570\u636e\u5217\u7684\u5217\u53f7\uff09\u3001HSSFRow.LastCellNum\uff08\u4e00\u884c\u4e2d\u6700\u540e\u4e00\u4e2a\u6709\u6570\u636e\u5217\u7684\u5217\u53f7\uff09\u3002<\/p>\n\n\n\n<p>\u57fa\u7840\u77e5\u8bc6\u57fa\u672c\u4e0a\u8865\u5f97\u5dee\u4e0d\u591a\u4e86\uff0c\u73b0\u5728\u5f00\u5de5\uff01<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u8981\u51c6\u5907\u4e00\u4e2a\u7528\u4e8e\u6253\u5f00\u6587\u4ef6\u6d41\u7684\u51fd\u6570InitializeWorkbook\uff0c\u7531\u4e8e\u6587\u4ef6\u8bfb\u5b8c\u540e\u5c31\u6ca1\u7528\u4e86\uff0c\u6240\u4ee5\u8fd9\u91cc\u76f4\u63a5\u7528using\uff08\u517b\u6210\u597d\u4e60\u60ef\uff0c\u5475\u5475\uff09\u3002<\/p>\n\n\n\n<p>HSSFWorkbookhssfworkbook;<\/p>\n\n\n\n<p>void&nbsp;InitializeWorkbook(string&nbsp;path)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/read the template via FileStream, it is suggested to use FileAccess.Readto prevent file lock.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\/\/book1.xlsis an Excel-2007-generated file, so some new unknown BIFF records are added.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;using&nbsp;(FileStream file =new&nbsp;FileStream(path, FileMode.Open,FileAccess.Read))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hssfworkbook =&nbsp;newHSSFWorkbook(file);<br>&nbsp;&nbsp;&nbsp; }<br>}<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u5f00\u59cb\u5199\u6700\u91cd\u8981\u7684\u51fd\u6570ConvertToDataTable\uff0c\u5373\u628aHSSF\u7684\u6570\u636e\u653e\u5230\u4e00\u4e2aDataTable\u4e2d\u3002<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.GetSheetAt(0);<br>System.Collections.IEnumerator rows = sheet.GetRowEnumerator();<br><br>while(rows.MoveNext())<br>{<br>&nbsp;&nbsp;&nbsp; HSSFRow row = (HSSFRow)rows.Current;<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/TODO::Create DataTable row&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i = 0; i &lt; row.LastCellNum; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HSSFCell cell = row.GetCell(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/TODO::set cell value to the cell of DataTables&nbsp;&nbsp;&nbsp; }<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684\u7ed3\u6784\u5927\u5bb6\u90fd\u5e94\u8be5\u80fd\u770b\u61c2\u5427\uff0c\u65e0\u975e\u5c31\u662f\u5148\u904d\u5386\u884c\uff0c\u518d\u904d\u5386\u884c\u4e2d\u7684\u6bcf\u4e00\u5217\u3002\u8fd9\u91cc\u5f15\u51fa\u4e86\u4e00\u4e2a\u96be\u70b9\uff0c\u7531\u4e8eExcel\u7684\u5355\u5143\u683c\u6709\u597d\u51e0\u79cd\u7c7b\u578b\uff0c\u7c7b\u578b\u4e0d\u540c\u663e\u793a\u7684\u4e1c\u897f\u5c31\u4e0d\u540c\uff0c\u5177\u4f53\u7684\u7c7b\u578b\u6709\u5e03\u5c14\u578b\u3001\u6570\u503c\u578b\u3001\u6587\u672c\u578b\u3001\u516c\u5f0f\u578b\u3001\u7a7a\u767d\u3001\u9519\u8bef\u3002<\/p>\n\n\n\n<p>publicenum&nbsp;HSSFCellType<br>{<br>&nbsp;&nbsp;&nbsp; Unknown = -1,<br>&nbsp;&nbsp;&nbsp; NUMERIC = 0,<br>&nbsp;&nbsp;&nbsp; STRING = 1,<br>&nbsp;&nbsp;&nbsp; FORMULA = 2,<br>&nbsp;&nbsp;&nbsp; BLANK = 3,<br>&nbsp;&nbsp;&nbsp; BOOLEAN = 4,<br>&nbsp;&nbsp;&nbsp; ERROR = 5,<br>}<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684HSSFCellType\u63cf\u8ff0\u4e86\u6240\u6709\u7684\u7c7b\u578b\uff0c\u4f46\u7ec6\u5fc3\u7684\u670b\u53cb\u53ef\u80fd\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u8fd9\u91cc\u6ca1\u6709\u65e5\u671f\u578b\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462\uff1f\u8fd9\u662f\u56e0\u4e3aExcel\u5e95\u5c42\u5e76\u6ca1\u6709\u4e00\u5b9a\u65e5\u671f\u578b\uff0c\u800c\u662f\u901a\u8fc7\u6570\u503c\u578b\u6765\u66ff\u4ee3\uff0c\u81f3\u4e8e\u5982\u4f55\u533a\u5206\u65e5\u671f\u548c\u6570\u5b57\uff0c\u90fd\u662f\u7531\u6587\u672c\u663e\u793a\u7684\u6837\u5f0f\u51b3\u5b9a\u7684\uff0c\u5728NPOI\u4e2d\u5219\u662f\u7531HSSFDataFormat\u6765\u5904\u7406\u3002\u4e3a\u4e86\u80fd\u591f\u65b9\u4fbf\u7684\u83b7\u5f97\u6240\u9700\u8981\u7684\u7c7b\u578b\u6240\u5bf9\u5e94\u7684\u6587\u672c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528HSSFCell.ToString()\u6765\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u4e8e\u662f\u521a\u624d\u7684\u4ee3\u7801\u5219\u53d8\u6210\u4e86\u8fd9\u6837\uff1a<\/p>\n\n\n\n<p>HSSFSheetsheet = hssfworkbook.GetSheetAt(0);<br>System.Collections.IEnumerator rows = sheet.GetRowEnumerator();<br><br>DataTable dt =&nbsp;new&nbsp;DataTable();<br>for&nbsp;(int&nbsp;j = 0; j &lt; 5;j++)<br>{<br>&nbsp;&nbsp;&nbsp; dt.Columns.Add(Convert.ToChar(((int)&#8217;A&#8217;)+j).ToString());<br>}<br><br>while(rows.MoveNext())<br>{<br>&nbsp;&nbsp;&nbsp; HSSFRow row = (HSSFRow)rows.Current;<br>&nbsp;&nbsp;&nbsp; DataRow dr = dt.NewRow();<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(int&nbsp;i = 0; i &lt; row.LastCellNum; i++)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HSSFCell cell = row.GetCell(i);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(cell ==&nbsp;null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =&nbsp;null;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] = cell.ToString();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; dt.Rows.Add(dr);}<\/p>\n\n\n\n<p>\u662f\u4e0d\u662f\u5f88\u7b80\u5355\uff0c\u5475\u5475\uff01<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u5982\u679c\u4f60\u8981\u5bf9\u67d0\u4e2a\u7279\u5b9a\u7684\u5355\u5143\u683c\u7c7b\u578b\u505a\u7279\u6b8a\u5904\u7406\uff0c\u53ef\u4ee5\u901a\u8fc7\u5224HSSFCell.CellType\u6765\u89e3\u51b3\uff0c\u6bd4\u5982\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch(cell.CellType)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.BLANK:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =&nbsp;&#8220;[null]&#8221;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.BOOLEAN:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =cell.BooleanCellValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.NUMERIC:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =cell.ToString();&nbsp;&nbsp;&nbsp;&nbsp;\/\/This is a trick to get the correct value of the cell.NumericCellValue will return a numeric value no matter the cell value is a dateor a number.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.STRING:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =cell.StringCellValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.ERROR:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr[i] = cell.ErrorCellValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;HSSFCellType.FORMULA:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr[i] =&nbsp;&#8220;=&#8221;+cell.CellFormula;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n\n\n\n<p>\u8fd9\u91cc\u53ea\u662f\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<p>\u5b8c\u6574\u4ee3\u7801\u4e0b\u8f7d\uff1a<a href=\"http:\/\/files.cnblogs.com\/tonyqus\/ImportXlsToDataTable.zip\" target=\"_blank\" rel=\"noreferrer noopener\">http:\/\/files.cnblogs.com\/tonyqus\/ImportXlsToDataTable.zip<\/a><\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u6b64\u4ee3\u7801\u4e2d\u4e0d\u5305\u62ecNPOI\u7684assembly\uff0c\u5426\u5219\u6587\u4ef6\u4f1a\u5f88\u5927\uff0c\u6240\u4ee5\u5efa\u8bae\u53bbnpoi.codeplex.com\u4e0b\u8f7d\u3002<\/p>\n\n\n\n<p>\u6587\u7ae0\u6765\u6e90\uff1a <a href=\"https:\/\/www.cnblogs.com\/joean\/p\/4661056.html\">https:\/\/www.cnblogs.com\/joean\/p\/4661056.html<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 1.\u8ba4\u8bc6NPOI 2.&nbsp;\u4f7f\u7528NPOI\u751f\u6210xls\u6587\u4ef6 2.1&nbsp;\u521b\u5efa\u57fa\u672c\u5185\u5bb9 2.1.1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,3],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/posts\/45"}],"collection":[{"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":2,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":47,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions\/47"}],"wp:attachment":[{"href":"http:\/\/www.zkjia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zkjia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}