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