(InputStream input, String worksheet, boolean header)
| 856 | |
| 857 | |
| 858 | protected void odsParse(InputStream input, String worksheet, boolean header) { |
| 859 | try { |
| 860 | InputStream contentStream = odsFindContentXML(input); |
| 861 | XML xml = new XML(contentStream); |
| 862 | |
| 863 | // table files will have multiple sheets.. |
| 864 | // <table:table table:name="Sheet1" table:style-name="ta1" table:print="false"> |
| 865 | // <table:table table:name="Sheet2" table:style-name="ta1" table:print="false"> |
| 866 | // <table:table table:name="Sheet3" table:style-name="ta1" table:print="false"> |
| 867 | XML[] sheets = |
| 868 | xml.getChildren("office:body/office:spreadsheet/table:table"); |
| 869 | |
| 870 | boolean found = false; |
| 871 | for (XML sheet : sheets) { |
| 872 | // System.out.println(sheet.getAttribute("table:name")); |
| 873 | if (worksheet == null || worksheet.equals(sheet.getString("table:name"))) { |
| 874 | odsParseSheet(sheet, header); |
| 875 | found = true; |
| 876 | if (worksheet == null) { |
| 877 | break; // only read the first sheet |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | if (!found) { |
| 882 | if (worksheet == null) { |
| 883 | throw new RuntimeException("No worksheets found in the ODS file."); |
| 884 | } else { |
| 885 | throw new RuntimeException("No worksheet named " + worksheet + |
| 886 | " found in the ODS file."); |
| 887 | } |
| 888 | } |
| 889 | } catch (UnsupportedEncodingException e) { |
| 890 | e.printStackTrace(); |
| 891 | } catch (IOException e) { |
| 892 | e.printStackTrace(); |
| 893 | } catch (ParserConfigurationException e) { |
| 894 | e.printStackTrace(); |
| 895 | } catch (SAXException e) { |
| 896 | e.printStackTrace(); |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | |
| 901 | /** |
no test coverage detected