openxlsx2 icon indicating copy to clipboard operation
openxlsx2 copied to clipboard

Write uninitalized row to output

Open JanMarvin opened this issue 2 years ago • 1 comments

Currently, when writing output, we force a cell <c/> node on every row <row/> we write. Working on #475 I created the attached file that breaks this logic. I assume our logic checks rows against cells because I ran into some other issues when developing xml writing logic or creating, copying or updating cells.

The issue is quite minor, but affects all uninitialized rows (open a worksheet in Excel, hide a row. Save the file, load it in openxlsx2 and the hidden row is back, because it was never written to our output in the first place). To fix this, someone, i.e. me, would have to rework the write logic, and (a) I don't want to do that right now and (b) something else might break in the process. For now this is a known defect, but nothing I'm actively working on.

The example file below: In Excel two rows are available, but no cells at all. All other rows are hidden (using <sheetFormatPr zeroHeight=\"1\" />).

library(openxlsx2)

wb <- wb_load("/tmp/xlsx.xlsx")

wb$worksheets[[1]]$sheet_data$row_attr
#>   collapsed customFormat customHeight hidden ht outlineLevel ph r s spans
#> 0                                                               1        
#> 1                                                               2        
#>   thickBot thickTop x14ac:dyDescent
#> 0                               0.2
#> 1                               0.2
wb$worksheets[[1]]$sheet_data$cc
#>  [1] r     row_r c_r   c_s   c_t   c_cm  c_ph  c_vm  v     f     f_t   f_ref
#> [13] f_ca  f_si  is   
#> <0 rows> (or 0-length row.names)

wb$save("/tmp/test.xlsx")

wb <- wb_load("/tmp/test.xlsx")

wb$worksheets[[1]]$sheet_data$row_attr
#>  [1] collapsed       customFormat    customHeight    hidden         
#>  [5] ht              outlineLevel    ph              r              
#>  [9] s               spans           thickBot        thickTop       
#> [13] x14ac:dyDescent
#> <0 rows> (or 0-length row.names)
wb$worksheets[[1]]$sheet_data$cc
#>  [1] r     row_r c_r   c_s   c_t   c_cm  c_ph  c_vm  v     f     f_t   f_ref
#> [13] f_ca  f_si  is   
#> <0 rows> (or 0-length row.names)

xlsx.xlsx

JanMarvin avatar Dec 15 '22 08:12 JanMarvin

Maybe a cheap workaround: initialize a cell for all imported rows even if they are not available in the input. The result should be identical from the users point of view. All it needs is a check at the end of wb_load() and a call to initializeCell().

JanMarvin avatar Dec 15 '22 08:12 JanMarvin