Skip to content

Commit e3e7a48

Browse files
committed
support "header" option with ODS files
1 parent 959c8c9 commit e3e7a48

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

core/src/processing/data/Table.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ protected void parse(InputStream input, String options) throws IOException {
362362
loadBinary(input);
363363

364364
} else if (extension.equals("ods")) {
365-
odsParse(input, worksheet);
365+
odsParse(input, worksheet, header);
366366

367367
} else {
368368
BufferedReader reader = PApplet.createReader(input);
@@ -617,7 +617,7 @@ private InputStream odsFindContentXML(InputStream input) {
617617
}
618618

619619

620-
protected void odsParse(InputStream input, String worksheet) {
620+
protected void odsParse(InputStream input, String worksheet, boolean header) {
621621
try {
622622
InputStream contentStream = odsFindContentXML(input);
623623
XML xml = new XML(contentStream);
@@ -633,7 +633,7 @@ protected void odsParse(InputStream input, String worksheet) {
633633
for (XML sheet : sheets) {
634634
// System.out.println(sheet.getAttribute("table:name"));
635635
if (worksheet == null || worksheet.equals(sheet.getString("table:name"))) {
636-
odsParseSheet(sheet);
636+
odsParseSheet(sheet, header);
637637
found = true;
638638
if (worksheet == null) {
639639
break; // only read the first sheet
@@ -664,7 +664,7 @@ protected void odsParse(InputStream input, String worksheet) {
664664
* Parses a single sheet of XML from this file.
665665
* @param The XML object for a single worksheet from the ODS file
666666
*/
667-
private void odsParseSheet(XML sheet) {
667+
private void odsParseSheet(XML sheet, boolean header) {
668668
// Extra <p> or <a> tags inside the text tag for the cell will be stripped.
669669
// Different from showing formulas, and not quite the same as 'save as
670670
// displayed' option when saving from inside OpenOffice. Only time we
@@ -761,13 +761,19 @@ private void odsParseSheet(XML sheet) {
761761
}
762762
}
763763
}
764-
if (rowNotNull && rowRepeat > 1) {
765-
String[] rowStrings = getStringRow(rowIndex);
766-
for (int r = 1; r < rowRepeat; r++) {
767-
addRow(rowStrings);
764+
if (header) {
765+
removeTitleRow(); // efficient enough on the first row
766+
header = false; // avoid infinite loop
767+
768+
} else {
769+
if (rowNotNull && rowRepeat > 1) {
770+
String[] rowStrings = getStringRow(rowIndex);
771+
for (int r = 1; r < rowRepeat; r++) {
772+
addRow(rowStrings);
773+
}
768774
}
775+
rowIndex += rowRepeat;
769776
}
770-
rowIndex += rowRepeat;
771777
}
772778
}
773779

0 commit comments

Comments
 (0)