Skip to content

Commit 6ae43ce

Browse files
committed
v1.3 fixed repeater bug
1 parent b34d93a commit 6ae43ce

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

R/readODS.R

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ library(XML)
66
#
77
#TODO: test gnummeric and koffice generated ODS files
88
#TODO: check if emtpy rows are the only ones with "number-rows-repeated"...
9-
# ALSO number-columns-repeated
9+
# ALSO number-columns-repeated -- FIXED
1010
#
1111
# the thing i should have probably read (AKA the ODS standard :P):
1212
# http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1420324_253892949
@@ -49,14 +49,13 @@ read.ods=function(file=NULL, sheet=NULL, formulaAsFormula=F){
4949
for(sheeti in sheets[names(sheets)=="table"]){
5050
sheetIndex=sheetIndex+1
5151
#sheeti=sheets[[3]]
52-
52+
5353
d=list()
5454
d[1]="" # avoid bug later on if no rows
5555
# fill it
5656
rowIndex=0
5757
for(row in sheeti[names(sheeti)=="table-row"]){
5858
rowIndex=rowIndex+1
59-
# print(rowIndex)
6059
if(!is.na(xmlAttrs(row)["number-rows-repeated"])){
6160
# only on empty rows???
6261
rowIndex=rowIndex+as.integer(xmlAttrs(row)[["number-rows-repeated"]])-1
@@ -69,17 +68,12 @@ read.ods=function(file=NULL, sheet=NULL, formulaAsFormula=F){
6968
if(is.null(xmlAttrs(cell))){ # silly liblre office has: <table:table-cell/>
7069
next
7170
}
72-
# print(colIndex)
73-
print(paste("row:",rowIndex," col:",colIndex,sep=""))
71+
# print(paste("row:",rowIndex," col:",colIndex,sep=""))
7472
#<table:table-cell table:number-columns-repeated="3"/>
75-
# colsRepeated=1
76-
# print(names(cell))
77-
# print(length((names(cell))))
7873
if(!is.na(xmlAttrs(cell)["number-columns-repeated"]) && length((names(cell)))==0 ){
7974
# print(as.integer(xmlAttrs(cell)[["number-columns-repeated"]]))
8075
# repeat empty columns
8176
colIndex=colIndex+as.integer(xmlAttrs(cell)[["number-columns-repeated"]])-1
82-
# colsRepeated=as.integer(xmlAttrs(cell)[["number-columns-repeated"]]
8377
next
8478
}
8579
# display the formula instead of its result
@@ -265,6 +259,8 @@ lettersToNumber=function( listOfStrings=NULL){
265259
#' libre office can do crap like this:
266260
#' <text:p>></text:p>
267261
#' which is not valid xml... and the XML package doesn't like that..
262+
#' OK NM NOW IT DOES! leaving the code here in case of changes...
263+
#'
268264
#' also to not make the code fulgy as all hell, the content.xml file is first scanned for these XML violations, and then fixed!
269265
#' <text:p>></text:p> --> <text:p>&gt</text:p>
270266
#' @param file - the xml file to be parsed...

notes.R

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ read.ods(file,formulaAsFormula = T)
3333
read.ods(file ,sheet=1)
3434

3535

36+
3637
read.ods(file,usePreParser = F)
3738

3839
odsPreParser(file)

tests/testthat/test_readODS.R

+26
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,33 @@ test_that("read.ods", {
4444
stringsAsFactors = F)
4545
expect_equal(read.ods(file, sheet=1),df)
4646

47+
file=paste("../testdata/layout_test.ods",sep="")
48+
sheet1=read.ods(file, sheet=1)
49+
expect_equal(sheet1[8,"F"],"empty") # this is a repeated element
4750

51+
sheet2=read.ods(file, sheet=2)
52+
expect_equal(dim(sheet2),c(22,13))
53+
expect_true(all(sheet1[21,]==sheet2[22,]))
54+
55+
file=paste("../testdata/multisheet.ods",sep="")
56+
df=data.frame(matrix("",14,7),stringsAsFactors = F)
57+
df[1,1]="COOKIES"
58+
df[4,2]="1"
59+
df[6,3]="2"
60+
df[8,3]="3"
61+
df[14,4]="3"
62+
df[7,5]="3"
63+
df[9,5]="1"
64+
df[10,7]="1"
65+
sheet2=read.ods(file, sheet=2)
66+
expect_true(all(sheet2==df))
67+
68+
69+
70+
# this test will fail on windows!!!
71+
# file=paste("../testdata/test.ods",sep="")
72+
# sheet1=read.ods(file, sheet=1)
73+
# expect_equal(sheet1[3,"E"],'lalala lalala,,””,,')
4874

4975
})
5076

0 commit comments

Comments
 (0)