org.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x213C0A0D0A0D0A0D, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document
package main;
import java.awt.EventQueue;
import java.io.FileInputStream;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class frame_test extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@SuppressWarnings("deprecation")
public void run() {
try {
frame_test frame = new frame_test();
frame.setVisible(true);
FileInputStream fis=new FileInputStream("C:\\Users\\phobi\\Desktop\\산불위험지수 전체DB\\2013\\10월\\2013년 10월 울산.xls");
HSSFWorkbook workbook=new HSSFWorkbook(fis);
int rowindex=0;
int columnindex=0;
//시트 수 (첫번째에만 존재하므로 0을 준다)
//만약 각 시트를 읽기위해서는 FOR문을 한번더 돌려준다
HSSFSheet sheet=workbook.getSheetAt(0);
//행의 수
int rows=sheet.getPhysicalNumberOfRows();
for(rowindex=1;rowindex<rows;rowindex++){
//행을 읽는다
HSSFRow row=sheet.getRow(rowindex);
if(row !=null){
if(rows < 10) continue;
//셀의 수
int cells=row.getPhysicalNumberOfCells();
for(columnindex=0;columnindex<=cells;columnindex++){
//셀값을 읽는다
HSSFCell cell=row.getCell(columnindex);
String value="";
//셀이 빈값일경우를 위한 널체크
if(cell==null){
continue;
}else{
//타입별로 내용 읽기
switch (cell.getCellType()){
case HSSFCell.CELL_TYPE_FORMULA:
value=cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
value=cell.getNumericCellValue()+"";
break;
case HSSFCell.CELL_TYPE_STRING:
value=cell.getStringCellValue()+"";
break;
case HSSFCell.CELL_TYPE_BLANK:
value=cell.getBooleanCellValue()+"";
break;
case HSSFCell.CELL_TYPE_ERROR:
value=cell.getErrorCellValue()+"";
break;
}
}
System.out.println("각 셀 내용 :"+value);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public frame_test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 318, 195);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("\uD30C\uC77C \uCC3E\uAE30");
btnNewButton.setBounds(12, 27, 97, 23);
contentPane.add(btnNewButton);
}
}