import java.io.File;<br />import java.io.FileInputStream;<br />import java.io.FileNotFoundException;<br />import java.io.IOException;<br />import java.text.SimpleDateFormat;<br />import java.util.Date;</p><p>import org.apache.poi.hssf.usermodel.HSSFCell;<br />import org.apache.poi.hssf.usermodel.HSSFRow;<br />import org.apache.poi.hssf.usermodel.HSSFSheet;<br />import org.apache.poi.hssf.usermodel.HSSFWorkbook;</p><p>public class ImportExcel {</p><p>public static void main(String[] args) {<br />String filePath = "E://kemu.xls";<br />File myFile = new File(filePath);<br />String strAdd = "";<br />try {</p><p>FileInputStream fis = new FileInputStream(myFile);<br />HSSFWorkbook workbook;<br />workbook = new HSSFWorkbook(fis);<br />HSSFSheet sheet = null;<br />HSSFRow row = null;<br />HSSFCell cell = null;<br />SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");<br />String strPrefix = sdf1.format(new Date());<br />if (workbook != null) {<br />sheet = workbook.getSheetAt(0);<br />}<br />if (sheet == null) {<br />System.out.println("不能匯入空的Excel檔案!");<br />}<br />if (sheet != null) {<br />row = sheet.getRow(5);// 從第五行開始讀取<br />}<br />for (int j = 5; row != null; j++, row = sheet.getRow(j)) {<br />strAdd = "";<br />for (int index = 1; index <= 10; index++) {<br />cell = row.getCell((short) (index - 1));<br />if (cell != null) {<br />if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {<br />strAdd = cell.getStringCellValue();<br />}<br />else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {<br />strAdd = String.valueOf(cell.getNumericCellValue());<br />}else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {<br />strAdd = "";<br />}<br />}</p><p>System.out.println(strAdd);<br />}<br />}<br />} catch (FileNotFoundException e) {<br />e.printStackTrace();<br />}catch( IOException ie ){<br />ie.printStackTrace();<br />}</p><p>}</p><p>}<br />