tablesaw icon indicating copy to clipboard operation
tablesaw copied to clipboard

Could you support .xls file?

Open zo-zero-one opened this issue 4 years ago • 4 comments

zo-zero-one avatar Jun 28 '21 04:06 zo-zero-one

Did you look at the Excel importing feature? I'm not sure if it does .xls since that's an older file format.

lwhite1 avatar Aug 20 '21 22:08 lwhite1

Late to the party but may be of use to others...

To support "xls", the HSSFWorkbook, HSSFSheet, HSSFRow and HSSFCell classes should be used. Code in:

https://github.com/jtablesaw/tablesaw/blob/1841f041e9d517a332542e1042c2ea261ae83f88/excel/src/main/java/tech/tablesaw/io/xlsx/XlsxReader.java#L119

shows the use of XSSFWorkbook. That and the XSSFSheet, XSSFRow and XSSFCell classes that support xlsx. See https://www.baeldung.com/java-microsoft-excel.

So, not supported. Also may not be so trivial to support it.

HTHs

hmf avatar Aug 11 '22 16:08 hmf

Found this article that shows that maybe with one simple change it can be supported:

private Workbook getWorkbook(FileInputStream inputStream, String excelFilePath)
        throws IOException {
    Workbook workbook = null;
 
    if (excelFilePath.endsWith("xlsx")) {
        workbook = new XSSFWorkbook(inputStream);
    } else if (excelFilePath.endsWith("xls")) {
        workbook = new HSSFWorkbook(inputStream);
    } else {
        throw new IllegalArgumentException("The specified file is not Excel file");
    }
 
    return workbook;
}

One small issue though, POI does not support the raw XML format prior 2003.

hmf avatar Aug 11 '22 17:08 hmf

Thanks!

---Original--- From: @.> Date: Fri, Aug 12, 2022 01:23 AM To: @.>; Cc: @.@.>; Subject: Re: [jtablesaw/tablesaw] Could you support .xls file? (#956)

Found this article that shows that maybe with one simple change it can be supported: private Workbook getWorkbook(FileInputStream inputStream, String excelFilePath) throws IOException { Workbook workbook = null; if (excelFilePath.endsWith("xlsx")) { workbook = new XSSFWorkbook(inputStream); } else if (excelFilePath.endsWith("xls")) { workbook = new HSSFWorkbook(inputStream); } else { throw new IllegalArgumentException("The specified file is not Excel file"); } return workbook; }

One small issue though, POI does not support the raw XML format prior 2003.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zo-zero-one avatar Aug 12 '22 00:08 zo-zero-one