私は現在POIを使用してExcelファイルを読み取っていますが、これを解決するために古い形式(BIFF5/office 95)のxlsファイルを読み取れないことを除いて、うまく機能していますjxlを使用したファイル。私が達成したいのは、例外をキャッチせずに同じコードを書くことです。現在の作業コードは次のとおりです。
public void translate() throws IOException, CmpException
{
ArrayList<String> row = null;
try
{
// create a new org.apache.poi.poifs.filesystem.Filesystem
POIFSFileSystem poifs = new POIFSFileSystem(fin);
w = new HSSFWorkbook(poifs);
}
catch (OldExcelFormatException e) // OldExcelFormatException
{
w = null;
System.out.println("OldExcelFormatException");
translateBIFF5();
}
catch (Exception e) // Any Exception
{
w = null;
}
if (w != null)
{
// read the excel file using POI
}
}
private void translateBIFF5() throws IOException, CmpException
{
ArrayList<String> row = null;
try
{
jxl_w = Workbook.getWorkbook(excelFile);
}
catch (Exception e) // Any Exception
{
jxl_w = null;
}
if (jxl_w != null)
{
// read the excel file using jxl
}
}