Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textWrap gives corrupted sheet #17

Closed
SHAESEN2 opened this issue Nov 25, 2019 · 4 comments
Closed

textWrap gives corrupted sheet #17

SHAESEN2 opened this issue Nov 25, 2019 · 4 comments

Comments

@SHAESEN2
Copy link
Contributor

@SHAESEN2 SHAESEN2 commented Nov 25, 2019

Hey,

When I use wrapText=TRUE I obtain a corrupted file:

wb <- createWorkbook()

addWorksheet(wb, "Expenditure", gridLines = FALSE) 

writeData(wb, sheet = 1, USPersonalExpenditure, rowNames = TRUE)

bodyStyle <- createStyle(fontSize=10, border="TopBottomLeftRight", borderColour = "black" , wrapText=TRUE)
headerStyle <- createStyle(fontSize=14, border="TopBottomLeftRight", borderColour = "black", textDecoration="bold")

addStyle(wb, sheet = 1, bodyStyle, rows = 2:6, cols = 1:6, gridExpand = TRUE)
addStyle(wb, sheet = 1, headerStyle, rows = 1, cols = 1:6, gridExpand = TRUE)

setColWidths(wb, 1, cols=1, widths = 21) ## set column width for row names column

saveWorkbook(wb, "addStyleExample.xlsx", overwrite = TRUE)

I attached a file with and without text wrapping for your convenience.

addStyleExample_wrapF.xlsx

addStyleExample_wrapT.xlsx

@ycphs
Copy link
Owner

@ycphs ycphs commented Nov 26, 2019

Could you please provide a functional example.
USPersonalExpenditure has no assigned values.

@SHAESEN2
Copy link
Contributor Author

@SHAESEN2 SHAESEN2 commented Nov 26, 2019

USPersonalExpenditure <- data.frame(
  `1940` = c(22.2, 10.5, 3.53, 1.04, 0.341),
  `1945` = c(44.5, 15.5, 5.76, 1.98, 0.974),
  `1950` = c(59.6, 29, 9.71, 2.45, 1.8),
  `1955` = c(73.2, 36.5, 14, 3.4, 2.6),
  `1960` = c(86.8, 46.2, 21.1, 5.4, 3.64),
  stringsAsFactors = FALSE,
  check.names = FALSE)
@JoshuaSturm
Copy link
Contributor

@JoshuaSturm JoshuaSturm commented Nov 26, 2019

I've been having the same issue. Excel has always been able to repair the file automatically, but it's become a nuisance, so I've been trying to fix it.

The error log pointed to /xl/styles.xml as the culprit. I renamed my corrupted xyz.xlsx to xyz.zip, opened the styles file, and found this.

Capture

In the center, there should be a space before "wrapText"; I believe this is what's causing the issue.

I'm trying to determine how that style is generated, and I'll submit a pull request if/when I find it.

@SHAESEN2
Copy link
Contributor Author

@SHAESEN2 SHAESEN2 commented Nov 26, 2019

Hey JoshuaSturm,

I checked and tested your fix. It solved the issue.

Thank you for the help. Very much appreciated !!!

@ycphs ycphs closed this in a85dfc3 Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.