Parses a single sheet of XML from this file. @param The XML object for a single worksheet from the ODS file
(XML sheet, boolean header)
| 889 | * @param The XML object for a single worksheet from the ODS file |
| 890 | */ |
| 891 | private void odsParseSheet(XML sheet, boolean header) { |
| 892 | // Extra <p> or <a> tags inside the text tag for the cell will be stripped. |
| 893 | // Different from showing formulas, and not quite the same as 'save as |
| 894 | // displayed' option when saving from inside OpenOffice. Only time we |
| 895 | // wouldn't want this would be so that we could parse hyperlinks and |
| 896 | // styling information intact, but that's out of scope for the p5 version. |
| 897 | final boolean ignoreTags = true; |
| 898 | |
| 899 | XML[] rows = sheet.getChildren("table:table-row"); |
| 900 | //xml.getChildren("office:body/office:spreadsheet/table:table/table:table-row"); |
| 901 | |
| 902 | int rowIndex = 0; |
| 903 | for (XML row : rows) { |
| 904 | int rowRepeat = row.getInt("table:number-rows-repeated", 1); |
| 905 | // if (rowRepeat != 1) { |
| 906 | // System.out.println(rowRepeat + " " + rowCount + " " + (rowCount + rowRepeat)); |
| 907 | // } |
| 908 | boolean rowNotNull = false; |
| 909 | XML[] cells = row.getChildren(); |
| 910 | int columnIndex = 0; |
| 911 | |
| 912 | for (XML cell : cells) { |
| 913 | int cellRepeat = cell.getInt("table:number-columns-repeated", 1); |
| 914 | |
| 915 | // <table:table-cell table:formula="of:=SUM([.E7:.E8])" office:value-type="float" office:value="4150"> |
| 916 | // <text:p>4150.00</text:p> |
| 917 | // </table:table-cell> |
| 918 | |
| 919 | String cellData = ignoreTags ? cell.getString("office:value") : null; |
| 920 | |
| 921 | // if there's an office:value in the cell, just roll with that |
| 922 | if (cellData == null) { |
| 923 | int cellKids = cell.getChildCount(); |
| 924 | if (cellKids != 0) { |
| 925 | XML[] paragraphElements = cell.getChildren("text:p"); |
| 926 | if (paragraphElements.length != 1) { |
| 927 | for (XML el : paragraphElements) { |
| 928 | System.err.println(el.toString()); |
| 929 | } |
| 930 | throw new RuntimeException("found more than one text:p element"); |
| 931 | } |
| 932 | XML textp = paragraphElements[0]; |
| 933 | String textpContent = textp.getContent(); |
| 934 | // if there are sub-elements, the content shows up as a child element |
| 935 | // (for which getName() returns null.. which seems wrong) |
| 936 | if (textpContent != null) { |
| 937 | cellData = textpContent; // nothing fancy, the text is in the text:p element |
| 938 | } else { |
| 939 | XML[] textpKids = textp.getChildren(); |
| 940 | StringBuilder cellBuffer = new StringBuilder(); |
| 941 | for (XML kid : textpKids) { |
| 942 | String kidName = kid.getName(); |
| 943 | if (kidName == null) { |
| 944 | odsAppendNotNull(kid, cellBuffer); |
| 945 | |
| 946 | } else if (kidName.equals("text:s")) { |
| 947 | int spaceCount = kid.getInt("text:c", 1); |
| 948 | for (int space = 0; space < spaceCount; space++) { |
no test coverage detected