MCPcopy Index your code
hub / github.com/benfry/processing4 / odsParseSheet

Method odsParseSheet

core/src/processing/data/Table.java:905–1016  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

odsParseMethod · 0.95

Calls 15

getChildrenMethod · 0.95
getContentMethod · 0.95
odsAppendNotNullMethod · 0.95
setStringMethod · 0.95
removeTitleRowMethod · 0.95
getStringRowMethod · 0.95
addRowMethod · 0.95
getIntMethod · 0.65
getStringMethod · 0.65
getChildCountMethod · 0.45
printlnMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected