awalker89 / openxlsx

R package for .xlsx file reading and writing.
Other
364 stars 79 forks source link

loadWorkbook cannot read comments #365

Open Jakobhenningjensen opened 6 years ago

Jakobhenningjensen commented 6 years ago

Expected Behavior

I have an excelfile where there is a textbox and comments

wb<-loadWorkbook("test.xlsx")

Actual Behavior

wb<-loadWorkbook("test.xlsx")

Error in grepl(target, commentsXML) : invalid 'pattern' argument

Comment: Changing line 545 in loadWorbook hasComment <-sapply(commentXMLrelationship, length) makes it work, but then saveWorkbook corrupts the excelfile

 `drawXMLrelationship <- lapply(xml, function(x) x[grepl("drawings/vmlDrawing[0-9]+\\.vml", 
    x)])

  hasDrawing <- sapply(drawXMLrelationship, length) > 
    0

  commentXMLrelationship <- lapply(xml, function(x) x[grepl("comments[0-9]+\\.xml", 
    x)])

  hasComment <- sapply(drawXMLrelationship, length) > 
    0`

Steps to Reproduce the Problem

(please attach an example xlsx file if possible)

1.

2.

3.

sessionInfo()

kainhofer commented 6 years ago

@Jakobhenningjensen Can you provide an example file where we can test this issue? Thank you...

laubwolf commented 5 years ago

I can reproduce this error. It seems that it has something to do with the Header/Footer in the page setup. Steps to reproduce:

  1. Create new excel workbook
  2. On Sheet1 in the Page Setup create a custom header and insert a picture
  3. Create a second sheet and add a comment (or "note" as it seems here on Excel 365)
  4. Save and try to load the file with loadWorkbook().

Book_new_1.xlsx