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

<channel>
	<title>jxl &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/jxl/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Fri, 11 Mar 2022 06:10:56 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>jxl &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Java 寫入 Excel 文件(xls, xlsx) – 使用 Apache POI</title>
		<link>https://noter.tw/6723/java-%e5%af%ab%e5%85%a5-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/</link>
					<comments>https://noter.tw/6723/java-%e5%af%ab%e5%85%a5-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Fri, 29 Nov 2019 05:34:06 +0000</pubDate>
				<category><![CDATA[一般程式]]></category>
		<category><![CDATA[寫入 xls]]></category>
		<category><![CDATA[2020]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[jxl]]></category>
		<category><![CDATA[xls]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[xlsx]]></category>
		<category><![CDATA[Apache POI]]></category>
		<category><![CDATA[讀取 xlsx]]></category>
		<category><![CDATA[寫入 excel]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=6723</guid>

					<description><![CDATA[<p>之前寫過一篇 Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI，記錄用 POI 讀取 Excel 的教學，這篇要補足「寫入」的教學。 小蛙會切割成幾個步驟來講（還&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/6723/java-%e5%af%ab%e5%85%a5-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 寫入 Excel 文件(xls, xlsx) – 使用 Apache POI</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>之前寫過一篇 <a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI</a>，記錄用 POI 讀取 Excel 的教學，這篇要補足「寫入」的教學。</p>



<span id="more-6723"></span>



<p>小蛙會切割成幾個步驟來講（還沒有下載跟導入 POI 的話，請先看<a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">前一篇</a>）</p>



<ul class="my-li bg-darkblue wp-block-list"><li>開啟 Excel：<a href="#exist">讀入既有的</a>、<a href="#new">建立新的</a></li><li><a href="#data">設定儲存格資料</a></li><li><a href="#writeout">寫出 Excel</a></li></ul>



<p>小蛙最近要用到，之前都是這樣子寫，但是後來發現當要寫的資料大到一定程度的時候，這樣的寫法會出問題，所以最後面會加映<a href="#mass">寫出大量資料</a>時候的作法，不過其實也可以直接用最後面的那種做法就好了！</p>



<h2 class="para wp-block-heading" id="exist">開啟 Excel &#8211; 讀入既有的</h2>



<p>程式碼如下，直接看應該不難看懂，多寫 .xls 跟 .xlsx 的判斷，如果自己使用的狀況有固定，就不需要多做這一步驟，直接去建立 xls 對應的 <code>HSSFWorkbook</code> 或 xlsx 對應的 <code>XSSFWorkbook</code>。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 讀取既有的
String path = "要匯出的檔案 e.g. C:\\測試.xlsx";
Workbook wb = null;
String extString = path.substring(path.lastIndexOf("."));
InputStream is = new FileInputStream(path);
if(".xls".equals(extString)){
   wb = new HSSFWorkbook(is);
}else if(".xlsx".equals(extString)){
   wb = new XSSFWorkbook(is);
}</pre>



<h2 class="para wp-block-heading" id="new">開啟 Excel &#8211; 建立新的</h2>



<p>如果本來沒有這個檔案就要用這段，先直接 new 出對應的 Workbook，在後面的步驟再把 Excel 寫出。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 開新檔案
String path = "要匯出的檔案 e.g. C:\\測試.xlsx";
Workbook wb = null;
String extString = path.substring(path.lastIndexOf("."));
if(".xls".equals(extString)){
    wb = new HSSFWorkbook();
}else if(".xlsx".equals(extString)){
    wb = new XSSFWorkbook();
}else{
    System.out.println("無效檔案");
    return;
}</pre>



<h2 class="para wp-block-heading" id="data">設定儲存格資料</h2>



<p>POI 對 Excel 的處理脈絡是這樣，先有一個 Workbook，把他看成是一個 Excel，下一層是頁籤 Sheet，再下一層是橫的 Row，最後就是儲存格 Cell，前面的步驟我們建立(取得)了 Workbook，下一步就是要建立 Sheet &gt; Row &gt; Cell，只要記住這個順序很快就可以把自己要寫的資料設定好了，下面的程式碼是把九九乘法表輸出到 Excel 裡。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 設定儲存格資料
Sheet sheet = wb.createSheet(); 
Row row = null;
Cell cell = null;
for(int r = 0; r &lt; 9; r++){
    row = sheet.createRow(r);
    for(int c = 0; c &lt; 9; c++){
        cell = row.createCell(c);
	cell.setCellValue(
            (c + 1) + " x " + (r + 1) + " = " + ((r + 1) * (c + 1))
        );
    }
}</pre>



<h2 class="writeout wp-block-heading">寫出 Excel</h2>



<p>內容都設置好之後，最後一個步驟就是把這些變動寫到 Excel 檔案上啦！</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 寫出 Excel
try {
    FileOutputStream fos = new FileOutputStream(new File(path));
    wb.write(fos);
    fos.flush();
    fos.close();
} catch (IOException e) {
    e.printStackTrace();
}</pre>



<p>到這邊就結束了！很簡單吧！上面全部組合起來應該就可以動了。</p>



<h2 class="para wp-block-heading" id="mass">處理大量資料</h2>



<p>如果資料量非常大的話，以小蛙的狀況來說要寫的資料量超過 3000 筆的時候，就會一直噴 <code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space</code> 的錯誤，Google 查了一些資料發現除了上面提到的 <code>HSSFWorkbook</code> 跟 <code>XSSFWorkbook</code> 之外，還有一個叫做 <code>SXSSFWorkbook</code> 的類別。</p>



<p><code>SXSSFWorkbook</code> 的運作方式跟 <code>HSSFWorkbook</code> 及 <code>XSSFWorkbook</code> 不同，<code>SXSSFWorkbook</code> 會先以「暫存檔」的方式寫回硬碟，最後輸出的時候再把他們存回 Excel 裡面，這樣一來就不會出現 Out Of Memory 的問題啦！不過如果內容處理沒弄好也還是會 OOM 就是～附上相關程式碼。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 大量資料用 SXSSFWorkbook
String path      = "要匯出的檔案 e.g. C:\\測試.xlsx";
// 設定幾筆之後，就先寫到硬碟的暫存檔
SXSSFWorkbook wb = new SXSSFWorkbook(100);
Sheet sheet      = wb.createSheet();
FileOutputStream fileOut = new FileOutputStream(path);	
Row row   = null;
Cell cell = null;
for(int r = 0; r &lt; 9; r++){
    row = sheet.createRow(r);
    for(int c = 0; c &lt; 9; c++){
        cell = row.createCell(c);
        cell.setCellValue(
            (c + 1) + " x " + (r + 1) + " = " + ((r + 1) * (c + 1)));
    }
}
wb.write(fileOut);
fileOut.flush();
fileOut.close();
wb.dispose();</pre>



<p><strong>Excel 相關文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/9117/excel-filter-and-validation/" data-wpel-link="internal">加入篩選器及下拉選單 (資料驗證)</a></li><li><a href="https://noter.tw/9063/excel-auto-search-and-fill-data-by-vlookup-index-match/" data-wpel-link="internal">搜尋表格 填入資料 強大的 VLOOKUP, INDEX, MATCH</a></li><li><a href="https://noter.tw/9061/split-a-excel-to-files/" data-wpel-link="internal">分拆 Excel 成多個檔案 ( Split A Excel to Files)</a></li><li><a href="https://noter.tw/6550/excel-%e4%bd%bf%e7%94%a8-poi-%e8%ae%80%e5%8f%96%e6%96%87%e5%ad%97%e6%a0%bc%e5%bc%8f%e6%97%a5%e6%9c%9f%e5%8d%bb%e8%ae%8a%e6%88%90%e6%95%b8%e5%ad%97%e7%9a%84%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">Excel 使用 POI 讀取文字格式日期卻變成數字的問題</a></li><li><a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI</a></li><li><a href="https://noter.tw/2711/oracle-%e5%8c%af%e5%85%a5%e5%8c%af%e5%87%ba-excel-%e9%80%8f%e9%81%8e-sql-developer/" data-wpel-link="internal">Oracle 匯入/匯出 Excel (透過 SQL Developer)</a></li><li><a href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a></li><li><a href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a></li><li><a href="https://noter.tw/119/ncr-%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f%ef%bc%9ajava-vba/" data-wpel-link="internal">NCR &amp;#xxxxx; 處理方式：Java &amp; VBA</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/6723/java-%e5%af%ab%e5%85%a5-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 寫入 Excel 文件(xls, xlsx) – 使用 Apache POI</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/6723/java-%e5%af%ab%e5%85%a5-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Java 讀取 Excel 文件(xls, xlsx) &#8211; 使用 Apache POI</title>
		<link>https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/</link>
					<comments>https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Sun, 01 Sep 2019 14:08:37 +0000</pubDate>
				<category><![CDATA[一般程式]]></category>
		<category><![CDATA[讀取 xlsx]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[jxl]]></category>
		<category><![CDATA[xls]]></category>
		<category><![CDATA[2019]]></category>
		<category><![CDATA[xlsx]]></category>
		<category><![CDATA[Apache POI]]></category>
		<category><![CDATA[讀取 excel]]></category>
		<category><![CDATA[讀取 xls]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=4300</guid>

					<description><![CDATA[<p>小蛙很久很久以前發過一篇 Java + Excel = JXL，主要講解怎麼用 Java 處理 Excel，當時使用的是 jxl 這個套件，不過這個套件有一個很大的問題，就是只能處理 xls 的檔案，&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) &#8211; 使用 Apache POI</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>小蛙很久很久以前發過一篇 <a href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a>，主要講解怎麼用 Java 處理 Excel，當時使用的是 jxl 這個套件，不過這個套件有一個很大的問題，就是只能處理 xls 的檔案，xlsx 沒有辦法處理，這篇要介紹的 Apache POI 則可以用來處理 xls 跟 xlsx。</p>



<span id="more-4300"></span>



<h2 class="para wp-block-heading">使用套件</h2>



<p>小蛙這邊說明自己下載 jar 的方式，首先到這邊下載 Apache POI，下載回來解壓縮之後，會得到一堆 jar，最簡單最簡單就是先把下面這些 jar 通通引入</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://lh3.googleusercontent.com/WRuQRobKQHsBNDNGAu-ZQAPuFxdxMafOhWD24n5RRGr8Rleyevn7uBeNq_V0hiv2S7a_x0Ep3rLAzcTUoVK2aMzWHIpedbNVtCc_8n_X2Xn6fWAitA2vgpLLGF7Eagd9LQLFJ0mS13_3P8iCkWis6jZYUEwqmoUtlxOWTFpPhMlD84paCnn0MqdNaJOIvJETCySq9jHmK00L70TurnGhEXL1xBWXDJtgzaVWBpHqCaAW4CWmqs4C6rjfx409vYqrWrsbLNU5pJhZVk0_GyQJF1IG_JVeJ9nbV4GHX22fWY-2xRZngywqKBxpOl5be6uHnSAUMaYH0k3PSvPuMguKR86XaZS6E5r4AY5exf6TfhnTV3SMOgqfBJJpEdciSjPpUL8YbHmubVOJRRXjt7MSYDinLjjlwp953vNuW4s4zeDAzD4hqYw-IhJvniAfSTf2T2dqiEyFBXfFEE3BrlPBLeTFUsArgN2PEpTu30DZeBdLbEmzHVSJBn0INxd7B73Mmhhxa_IR3SSqKS-gM0zd_HsEWNwdrWSNF34yHJh0Yw9b89h_LqA-YBuUDGEfVqlvrFuDVu8-TqEOC8ANNKxllJSm0gJM8vEwQnhHRKdmL3GfI5L3LNClcJE7MkZmCCrNxk2ZmPWPV2pDdtBfRCg4WKsg-8HhEbkFbYtFUdQoislhgWDaphAIg5p9ewVldyfLh3rdpE0Yar9rHKbtIyBGcj6m3bT-hg3jz8_OzedgEyfRDimy=w401-h282-no" alt="WRuQRobKQHsBNDNGAu ZQAPuFxdxMafOhWD24n5RRGr8Rleyevn7uBeNq V0hiv2S7a x0Ep3rLAzcTUoVK2aMzWHIpedbNVtCc 8n X2Xn6fWAitA2vgpLLGF7Eagd9LQLFJ0mS13 3P8iCkWis6jZYUEwqmoUtlxOWTFpPhMlD84paCnn0MqdNaJOIvJETCySq9jHmK00L70TurnGhEXL1xBWXDJtgzaVWBpHqCaAW4CWmqs4C6rjfx409vYqrWrsbLNU5pJhZVk0 GyQJF1IG JVeJ9nbV4GHX22fWY 2xRZngywqKBxpOl5be6uHnSAUMaYH0k3PSvPuMguKR86XaZS6E5r4AY5exf6TfhnTV3SMOgqfBJJpEdciSjPpUL8YbHmubVOJRRXjt7MSYDinLjjlwp953vNuW4s4zeDAzD4hqYw IhJvniAfSTf2T2dqiEyFBXfFEE3BrlPBLeTFUsArgN2PEpTu30DZeBdLbEmzHVSJBn0INxd7B73Mmhhxa IR3SSqKS gM0zd HsEWNwdrWSNF34yHJh0Yw9b89h LqA YBuUDGEfVqlvrFuDVu8 TqEOC8ANNKxllJSm0gJM8vEwQnhHRKdmL3GfI5L3LNClcJE7MkZmCCrNxk2ZmPWPV2pDdtBfRCg4WKsg 8HhEbkFbYtFUdQoislhgWDaphAIg5p9ewVldyfLh3rdpE0Yar9rHKbtIyBGcj6m3bT hg3jz8 OzedgEyfRDimy=w401 h282 no Java 讀取 Excel 文件(xls, xlsx) - 使用 Apache POI" title="Java 讀取 Excel 文件(xls, xlsx) - 使用 Apache POI"></figure></div>



<p>通通引入之後，小蛙放上參考網路上資料後，改成自己適用的功能片段，主要作法是先讀取 Excel 裡的所有資料丟到 List&lt;List&lt;String&gt;&gt; 裡面，再透過操作 List&lt;List&lt;String&gt;&gt; 的資料達到目的，當然也可以改成最直觀的方式，直接讀取特定欄位直接做處理。（不一定要用這種全部讀出來再去處理的方式，也可以直接一格一格讀出來處理），下面只是列出一些 function，把它改成自己需要的方式就可以了。</p>



<p>操作流程大概是這樣 </p>



<ul class="wp-block-list"><li><a href="#read">讀取 xls / xlsx 檔案</a></li><li><a href="#sheet">讀取 sheet</a></li><li><a href="#rowcol">遍尋 rows（橫的）遍尋 columns（直的）</a></li><li><a href="#conv">讀取儲存格資料並根據類型做轉換</a></li></ul>



<h3 class="para wp-block-heading" id="read">讀取 xls / xlsx 檔案</h3>



<p>第一步就是讀取 excel 檔案，這邊多做了一件事情就是區分出 xls 跟 xlsx，用一個 if 判斷是分別 new 出 HSSFWorkbook / XSSFWorkbook 物件。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 從路徑中讀取 Excel
default Workbook getWorkbook(String path) throws FileNotFoundException, IOException {
	Workbook wb = null;
	if(path == null) return null;
	String extString = path.substring(path.lastIndexOf("."));
	InputStream is = new FileInputStream(path);
	if(XLS.equals(extString)){
	    wb = new HSSFWorkbook(is);
	}else if(XLSX.equals(extString)){
	    wb = new XSSFWorkbook(is);
	}
	return wb;
}</pre>



<h3 class="para wp-block-heading" id="sheet">讀取 sheet</h3>



<p>從上面取得的 workbook 中，讀取特定頁籤，這個 sheetNo 從 0 開始計算，也就是說第一個頁籤的話要傳入 0，第二個頁籤傳入 1，以此類推。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 讀取要用的 Sheet
default Sheet getSheet(Workbook workbook, int sheetNo){
	return workbook.getSheetAt(sheetNo);
}</pre>



<h3 class="para wp-block-heading" id="rowcol">遍尋 rows（橫的）遍尋 columns（直的）</h3>



<p>這邊跟 jxl 比較不同的地方在於，必須先把 row 取出來，然後取得最後一個 row 跟最後一個 column，要注意的是取得 colnum 的時候，要先判斷取出的 row 是不是 null，不然會噴錯喔！（小蛙這邊懶得改了，自己要記得加上判斷喔），以及 index 都是從 0 開始計算，然後每一格儲存格取出的資料都放在 List&lt;List&lt;String&gt;&gt;。中間 readCell 部份內容請往下看。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 把所有欄位讀出成 List&lt;List&lt;String&gt;&gt;
default List&lt;List&lt;String&gt;&gt; readFields(Workbook workbook, int sheetNo, int firstRow, int firstCol) throws Exception {
	Sheet sheet = workbook.getSheetAt(sheetNo);
	Row row = sheet.getRow(0); 
	int rownum = sheet.getPhysicalNumberOfRows();
	int colnum = row.getPhysicalNumberOfCells();
	List&lt;List&lt;String&gt;&gt; list = new ArrayList&lt;&gt;();
	List&lt;String&gt; _inner;
	for(int i = firstRow; i &lt; rownum; i++){
		row = sheet.getRow(i);
		 _inner = new ArrayList&lt;&gt;();
		if(row != null){
			for(int j = firstCol; j &lt; colnum; j++){
				_inner.add(readCell(row.getCell(j)));
			}
			list.add(_inner);
		}else{
			break;
		}
	}
	return list;
}</pre>



<h3 class="para wp-block-heading" id="conv">轉換型態</h3>



<p>跟 jxl 不一樣的部份是，jxl 可以直接取得字串型態的資料，但是 poi 必須根據不同的形態來呼叫不同的方法取得內容，下面是參考網路上看到的程式碼做的修改，原始來源不太記得了，大致上符合小蛙的需求，可以直接複製回去，再依自己的需求修改。</p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 小蛙自己要吐出的格式
default String readCell(Cell cell){
	return (String) getCellFormatValue(cell);
}
default Object getCellFormatValue(Cell cell){
	Object cellValue = null;
        if(cell!=null){
            switch(cell.getCellType()){
	            case NUMERIC:
	            	cellValue 	= df.format(cell.getNumericCellValue());  
	                break;
	            case FORMULA:
	                if(DateUtil.isCellDateFormatted(cell)){
	                    cellValue = cell.getDateCellValue();
	                }else{
	                    cellValue = String.valueOf(cell.getNumericCellValue());
	                }
	                break;
	            case STRING:
	                cellValue = cell.getRichStringCellValue().getString();
	                break;
	            default:
	                cellValue = "";
            }
	    }else{
            cellValue = "";
        }
	return cellValue;
}</pre>



<p>打完收工，把這些 code 改成自己需求之後組合起來應該就可以順利動囉！</p>



<p><strong>Excel 相關文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/9117/excel-filter-and-validation/" data-wpel-link="internal">加入篩選器及下拉選單 (資料驗證)</a></li><li><a href="https://noter.tw/9063/excel-auto-search-and-fill-data-by-vlookup-index-match/" data-wpel-link="internal">搜尋表格 填入資料 強大的 VLOOKUP, INDEX, MATCH</a></li><li><a href="https://noter.tw/9061/split-a-excel-to-files/" data-wpel-link="internal">分拆 Excel 成多個檔案 ( Split A Excel to Files)</a></li><li><a href="https://noter.tw/6550/excel-%e4%bd%bf%e7%94%a8-poi-%e8%ae%80%e5%8f%96%e6%96%87%e5%ad%97%e6%a0%bc%e5%bc%8f%e6%97%a5%e6%9c%9f%e5%8d%bb%e8%ae%8a%e6%88%90%e6%95%b8%e5%ad%97%e7%9a%84%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">Excel 使用 POI 讀取文字格式日期卻變成數字的問題</a></li><li><a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI</a></li><li><a href="https://noter.tw/2711/oracle-%e5%8c%af%e5%85%a5%e5%8c%af%e5%87%ba-excel-%e9%80%8f%e9%81%8e-sql-developer/" data-wpel-link="internal">Oracle 匯入/匯出 Excel (透過 SQL Developer)</a></li><li><a href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a></li><li><a href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a></li><li><a href="https://noter.tw/119/ncr-%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f%ef%bc%9ajava-vba/" data-wpel-link="internal">NCR &amp;#xxxxx; 處理方式：Java &amp; VBA</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) &#8211; 使用 Apache POI</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</title>
		<link>https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/</link>
					<comments>https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Wed, 28 Dec 2011 15:42:01 +0000</pubDate>
				<category><![CDATA[網頁後端]]></category>
		<category><![CDATA[html to excel]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[JExcelApi]]></category>
		<category><![CDATA[jxl]]></category>
		<category><![CDATA[excel下載]]></category>
		<guid isPermaLink="false">http://wazai.net/?p=1732</guid>

					<description><![CDATA[<p>這篇文章小蛙要記錄如何在JSP中使用JExcelApi(jxl)操作Excel並且提供下載的功能，例如查詢完的列表讓使用者可以直接下載存成Excel。小蛙原本寫了一種透過File的方法產生，不過缺點就&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>這篇文章小蛙要記錄如何在JSP中使用JExcelApi(jxl)操作Excel並且提供下載的功能，例如查詢完的列表讓使用者可以直接下載存成Excel。小蛙原本寫了一種透過File的方法產生，不過缺點就是時間久了會有很多廢棄的檔案(因為每次下載都會存成一個xls)，必須透過crontab或是手動定期清理。之後在<a rel="noreferrer noopener nofollow external" href="http://blog.xuite.net/syang.phon/photobox/19700170" target="_blank" data-wpel-link="external" class="wpel-icon-right"><strong>Jsp利用jxl匯出資料至Excel並下載 @ Ken™ KM</strong><span class="wpel-icon wpel-image wpel-icon-6"></span></a>看到更好的方法，可以動態產生並且直接提供下載，也就不會有上述的問題了。</p>



<span id="more-1732"></span>



<p><a rel="noreferrer noopener nofollow external" href="http://wazai.net/1569/java-excel-jxl" target="_blank" data-wpel-link="external" class="wpel-icon-right">Java + Excel = JXL<span class="wpel-icon wpel-image wpel-icon-6"></span></a>小蛙在這篇文章中記錄了在Java中如何透過jxl讀取Excel檔案，這篇文章則是記錄如何寫入Excel檔案。會出現這篇文章完全是一個意外，原本這個工作是由另一位同事負責，結果那位同事連續請假兩天，而恰好小蛙是他的組長，另一個原因是，晚上快六點的時候，小蛙的組長才跟小蛙說隔天中午前要處理好，下午對方要做驗收的動作，所以小蛙只好回到家繼續趕工。累了，不囉嗦直接進正題，老規矩只記錄用到的部份，對jxl有興趣的網友們，請見諒，可能要自行查找jxl document喔！</p>



<h2 class="para wp-block-heading">操作寫入Excel檔案(不含直接下載)</h2>



<p>這邊必須先有一個 WritableWorkbook 物件公我們操作(讀取的時候我們使用的是 Workbook 物件)，接著是 WritableSheet(讀取的時候是 Sheet)，建立完 WritableWorkbook 及 WritableSheet 之後就開始一個 cell 一個 cell 塞資料，這邊小蛙只有用到字串類型的文字，所以只採用 Label 即可。</p>


<pre>&lt;%@ page language="java" contentType="text/html; charset=utf-8" %&gt;
&lt;%@ page import="java.util.*" %&gt;
&lt;%@ page import="java.io.*" %&gt;
&lt;%@ page import="java.text.*" %&gt;
&lt;%@ page import="jxl.*" %&gt;
&lt;%@ page import="jxl.write.*" %&gt;
&lt;%@ page import="jxl.write.biff.RowsExceededException" %&gt;
&lt;%!
// 參考資料 http://www.blogjava.net/chenlb/archive/2007/10/29/156613.html
private void putRow(WritableSheet ws, int rowNum, ArrayList cells) throws RowsExceededException, WriteException {
    for(int j=0; j &lt; cells.size(); j++) {
      // 建立每個cell物件，這邊只用了Label
      Label cell = new Label(j, rowNum, ""+cells.get(j));
        // 塞入Cell中
        ws.addCell(cell);
      }
}
%&gt;
&lt;%
File f = null;
try{
    // 只是用來產生檔名
    long sysTime = System.currentTimeMillis();
    java.util.Date date = new java.util.Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    String dateString = sdf.format(date) + sysTime + ".xls";
    String path = application.getRealPath("");
    f = new File(path + "/upload/" + dateString);
    if(!f.exists()){
        // 建立excel檔案(空檔案，供jxl操作)
        f.createNewFile();
    }
    WritableWorkbook workbook = Workbook.createWorkbook(f);
    WritableSheet sheet = workbook.createSheet("Sheet1", 0);
    int rowNum = 0;
    // ... 資料庫讀取部份略過 ...
    while(rs.next()){
        // 建立一個ArrayList儲存每個Record的資料
        ArrayList list = new ArrayList();
        list.add(rs.getString("name");
        ...
        // 實際塞資料
        putRow(sheet, rowNum, list);
        // 用來控制行數
        rowNum++;
    }
    // 這兩行一定不能少，不然寫的資料會消失
    workbook.write();
    workbook.close();
}catch(Exception e){
  out.print(e);
}
%&gt;</pre>
<p> </p>
<ul>
<li><span style="color: #ff0000;"><strong>操作寫入Excel並直接下載</strong></span></li>
</ul>
<p style="padding-left: 30px;">這邊是透過將Excel直接輸出到OutputStream，再透過response.setHeader達到下載的目的，直接看code。</p>
<pre>&lt;%@ page language="java" contentType="text/html; charset=utf-8" %&gt;
&lt;%@ page import="java.util.*" %&gt;
&lt;%@ page import="java.io.*" %&gt;
&lt;%@ page import="jxl.*" %&gt;
&lt;%@ page import="jxl.write.*" %&gt;
&lt;%@ page import="jxl.write.biff.RowsExceededException" %&gt;
&lt;%!
    private void putRow(WritableSheet ws, int rowNum, ArrayList cells) throws RowsExceededException, WriteException {
        for(int j=0; j&amp;lt;cells.size(); j++) {
            Label cell = new Label(j, rowNum, ""+cells.get(j));
            ws.addCell(cell);
        }
    }
%&gt;
&lt;%
try{
    // 直接下載最重要的兩行
    response.reset();     
    response.setHeader("Content-disposition","attachment; filename=fileName.xls");
    OutputStream os = response.getOutputStream();
    WritableWorkbook workbook = Workbook.createWorkbook(os);
    WritableSheet sheet = workbook.createSheet("Sheet1", 0);
    // ... 資料庫操作省略 ...
    int rowNum = 0;
    while(rs.next()){
        ArrayList list = new ArrayList();
        list.add(rs.getString("name"));
        ....
        putRow(sheet, rowNum, list);
        rowNum++;
    }
    workbook.write();
    workbook.close();
    os.flush();
    os.close();
}catch(Exception e){
    out.print(e);
}
%&gt;</pre>


<p><strong>Excel 相關文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/9117/excel-filter-and-validation/" data-wpel-link="internal">加入篩選器及下拉選單 (資料驗證)</a></li><li><a href="https://noter.tw/9063/excel-auto-search-and-fill-data-by-vlookup-index-match/" data-wpel-link="internal">搜尋表格 填入資料 強大的 VLOOKUP, INDEX, MATCH</a></li><li><a href="https://noter.tw/9061/split-a-excel-to-files/" data-wpel-link="internal">分拆 Excel 成多個檔案 ( Split A Excel to Files)</a></li><li><a href="https://noter.tw/6550/excel-%e4%bd%bf%e7%94%a8-poi-%e8%ae%80%e5%8f%96%e6%96%87%e5%ad%97%e6%a0%bc%e5%bc%8f%e6%97%a5%e6%9c%9f%e5%8d%bb%e8%ae%8a%e6%88%90%e6%95%b8%e5%ad%97%e7%9a%84%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">Excel 使用 POI 讀取文字格式日期卻變成數字的問題</a></li><li><a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI</a></li><li><a href="https://noter.tw/2711/oracle-%e5%8c%af%e5%85%a5%e5%8c%af%e5%87%ba-excel-%e9%80%8f%e9%81%8e-sql-developer/" data-wpel-link="internal">Oracle 匯入/匯出 Excel (透過 SQL Developer)</a></li><li><a href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a></li><li><a href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a></li><li><a href="https://noter.tw/119/ncr-%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f%ef%bc%9ajava-vba/" data-wpel-link="internal">NCR &amp;#xxxxx; 處理方式：Java &amp; VBA</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Java + Excel = JXL</title>
		<link>https://noter.tw/1569/java-excel-jxl/</link>
					<comments>https://noter.tw/1569/java-excel-jxl/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Mon, 19 Dec 2011 14:12:31 +0000</pubDate>
				<category><![CDATA[一般程式]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[JExcelApi]]></category>
		<category><![CDATA[jxl]]></category>
		<category><![CDATA[Java]]></category>
		<guid isPermaLink="false">http://wazai.co.cc/?p=1569</guid>

					<description><![CDATA[<p>講到試算表，大家最熟悉的應該就是 Microsoft Office Excel 了吧！但其實大部分的人都只會基本的 Excel 操作及運算，Excel 其實有很多非常強大的功能，這篇文章其實不是教大家&#46;&#46;&#46;</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>講到試算表，大家最熟悉的應該就是 Microsoft Office Excel 了吧！但其實大部分的人都只會基本的 Excel 操作及運算，Excel 其實有很多非常強大的功能，這篇文章其實不是教大家怎麼使用 Excel，小蛙也只會基本的操作，由於 Excel 所包含的強大功能，以致於現在有很多資料都是採用 Excel 儲存，像小蛙的其中一項工作就是把某些單位中的資料匯入到資料庫中，而某些單位提供給小蛙的資料就是 Excel，小蛙要做的事情就是必須先從 Excel 中把資料截取出來，才能做後續的操作以利於塞入特定資料庫中。這篇文章要介紹怎麼使用 Java 讀取 Excel 內容。 </p>



<span id="more-1569"></span>



<p>要在 Java 中操作 Excel 必須先下載<a rel="noreferrer noopener nofollow external" href="http://www.andykhan.com/jexcelapi/download.html" target="_blank" data-wpel-link="external" class="wpel-icon-right">Java Excel API<span class="wpel-icon wpel-image wpel-icon-6"></span></a>。這邊小蛙下載最新版的 JExecelApi v2.6.12。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-1.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-1.png" alt="jxl 1 Java + Excel = JXL" class="wp-image-1570" title="Java + Excel = JXL"></a></figure></div>



<p>下載到桌面後，我們只需要壓縮檔中的 jxl.jar 檔案，可以透過 WinRAR (WinZip or 7zip &#8230;等)解壓縮軟體取得 jxl.jar。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-2.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-2.png" alt="jxl 2 Java + Excel = JXL" class="wp-image-1571" title="Java + Excel = JXL"></a></figure></div>



<p>解壓縮後可以得到 jexcelapi，而我們要的 jxl.jar 在 jexcelapi 資料夾內。如果你的使用方式跟小蛙一樣，直接點兩下開啟 WinRAR 介面的話，就可以直接拖曳著 jxl.jar到桌面，而不用解壓縮整個檔案。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-3.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-3.png" alt="jxl 3 Java + Excel = JXL" class="wp-image-1572" title="Java + Excel = JXL"></a></figure></div>



<p>接下來要把這個 jar 檔放進專案中讓我們可以透過 Eclipse 使用，之前小蛙會將所有使用到的 Library 都放置在一個資料夾，讓不同專案可以去 include，但後來工讀生盛哥(組內最強)建議可以每個專案中都建立一個lib資料夾，裡面專門放置這個專案會用到的函式庫，雖然可能會造成空間浪費(同一個套件複製好幾份在不同專案中)，但到時候要維護或是打包之類的會方便許多。下圖是在專案中建立一個 Folder 的操作，在專案上按右鍵 -&gt; New -&gt; Folder。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-4.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-4.png" alt="jxl 4 Java + Excel = JXL" class="wp-image-1573" title="Java + Excel = JXL"></a></figure></div>



<p>輸入 Folder 名稱。</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-5.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-5.png" alt="jxl 5 Java + Excel = JXL" class="wp-image-1574" title="Java + Excel = JXL"></a></figure></div>



<p>就會出現在 Eclipse 介面中的專案裡了。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-6.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-6.png" alt="jxl 6 Java + Excel = JXL" class="wp-image-1575" title="Java + Excel = JXL"></a></figure></div>



<p>光是這樣 Eclipse 還沒辦法使用這個Jar的功能喔！接著我們要讓 Eclipse 可以&#8221;認得&#8221;這個 Jar。在剛剛的 jar 上面點選滑鼠右鍵，選擇 Build Path -&gt; Add to Build Path。</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-7.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-7.png" alt="jxl 7 Java + Excel = JXL" class="wp-image-1576" title="Java + Excel = JXL"></a></figure></div>



<p>上圖的 jxl.jar 變成下圖這個樣子，並且在 Referenced Libraries 中出現了一個 jxl.jar。</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-8.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-8.png" alt="jxl 8 Java + Excel = JXL" class="wp-image-1577" title="Java + Excel = JXL"></a></figure></div>



<p>接下來介紹 JXL 的使用方法。 </p>



<pre class="wp-block-preformatted wp-block-syntaxhighlighter-code">// 要注意如果檔案路徑中有「\」必須用「\\」或「/」取代掉
// 使用JXL必須先建立一個Workbook，讀取方法如下。
// 小蛙測試的時候 xlsx 的檔案會發生錯誤
Workbook workbook = Workbook.getWorkbook(new File("E:\\鄉鎮區中英文.xls"));
// 接著建立 Sheet，Workbook可以看成是一個excel檔案，Sheet顧名思義就是一個頁籤。
// 可以直接 getSheet(0) 表示第一個頁籤(從0開始算)
// 也可以透過 getSheet("頁籤名稱") 來取得頁籤
Sheet sheet = workbook.getSheet(0);
// 讀取儲存格(Cell)的方法，getCell(Columns, Rows)，也是一樣從0開始(直,橫)
Cell c = sheet.getCell(j, i); 
// 要一列一列往下讀的方式，印出每一行的內容
for(int i = 0; i &lt; sheet.getRows(); i++){
    for(int j = 0; j &lt; sheet.getColumns(); j++){
        Cell c = sheet.getCell(j, i);
        String s = c.getContents();
        System.out.println(s);
    }
    System.out.println("-------");
}</pre>



<p>這邊小蛙介紹一個 Eclipse 小技巧。把上面的程式貼在 Eclipse 裡面卻發現有紅色的底線，是 Eclipse 告訴開發者你這行程式有錯誤喔！並且提供貼心小建議，左邊有一個叉叉，點選滑鼠左鍵可以看到 Eclipse 給了幾個貼心的小建議，例如下圖 Eclipse 就告訴開發者可能是少 import java.io.File; &#8230; 等等，雖然不一定每次都會正確，這個便利的設計可以讓開發者少打一些字，也可以更快找出錯誤的原因。</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-9.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-9-580x223.png" alt="jxl 9 Java + Excel = JXL" title="Java + Excel = JXL"></a></figure></div>



<p>下圖是必須做Exception判斷。 </p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://noter.tw/wp-content/uploads/2011/12/jxl-11.png" data-wpel-link="internal"><img decoding="async" src="https://noter.tw/wp-content/uploads/2011/12/jxl-11-580x250.png" alt="jxl 11 Java + Excel = JXL" class="wp-image-1580" title="Java + Excel = JXL"></a></figure></div>



<p><strong>Excel 相關文章：</strong></p>



<ul class="my-li bg-darkblue wp-block-list"><li><a href="https://noter.tw/9117/excel-filter-and-validation/" data-wpel-link="internal">加入篩選器及下拉選單 (資料驗證)</a></li><li><a href="https://noter.tw/9063/excel-auto-search-and-fill-data-by-vlookup-index-match/" data-wpel-link="internal">搜尋表格 填入資料 強大的 VLOOKUP, INDEX, MATCH</a></li><li><a href="https://noter.tw/9061/split-a-excel-to-files/" data-wpel-link="internal">分拆 Excel 成多個檔案 ( Split A Excel to Files)</a></li><li><a href="https://noter.tw/6550/excel-%e4%bd%bf%e7%94%a8-poi-%e8%ae%80%e5%8f%96%e6%96%87%e5%ad%97%e6%a0%bc%e5%bc%8f%e6%97%a5%e6%9c%9f%e5%8d%bb%e8%ae%8a%e6%88%90%e6%95%b8%e5%ad%97%e7%9a%84%e5%95%8f%e9%a1%8c/" data-wpel-link="internal">Excel 使用 POI 讀取文字格式日期卻變成數字的問題</a></li><li><a href="https://noter.tw/4300/java-%e8%ae%80%e5%8f%96-excel-%e6%96%87%e4%bb%b6xls-xlsx-%e4%bd%bf%e7%94%a8-apache-poi/" data-wpel-link="internal">Java 讀取 Excel 文件(xls, xlsx) – 使用 Apache POI</a></li><li><a href="https://noter.tw/2711/oracle-%e5%8c%af%e5%85%a5%e5%8c%af%e5%87%ba-excel-%e9%80%8f%e9%81%8e-sql-developer/" data-wpel-link="internal">Oracle 匯入/匯出 Excel (透過 SQL Developer)</a></li><li><a href="https://noter.tw/1732/jsp%e5%b0%87%e8%b3%87%e6%96%99%e5%8c%af%e5%87%ba%e6%88%90excel%e7%9b%b4%e6%8e%a5%e4%b8%8b%e8%bc%89-by-jexcelapi-jxl/" data-wpel-link="internal">JSP將資料匯出成Excel直接下載 by JExcelApi (jxl)</a></li><li><a href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a></li><li><a href="https://noter.tw/119/ncr-%e8%99%95%e7%90%86%e6%96%b9%e5%bc%8f%ef%bc%9ajava-vba/" data-wpel-link="internal">NCR &amp;#xxxxx; 處理方式：Java &amp; VBA</a></li></ul>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/1569/java-excel-jxl/" data-wpel-link="internal">Java + Excel = JXL</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/1569/java-excel-jxl/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
