awalker89 / openxlsx

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

Corrupt image, shows at wrong position #471

Closed cesargil closed 5 years ago

cesargil commented 5 years ago

Expected Behavior

As many images as needed inserted, without margins, at specified rows/columns.

Actual Behavior

Excel issues a warning of corrupt file when opening, but lets you recover. Image shows at cell (1,1).

Steps to Reproduce the Problem

Note: I am trying to add spark lines after each row of data, so I set all margins of the plot to 0 for a very small image.

library(openxlsx)

wb <- createWorkbook()

addWorksheet(wb, "sheet")

y <- sample(1:10)
x <- seq_along(y)
op <- par(mar = c(0, 0, 0, 0))
plot(x, y, axes=F, type="l", xlab=NA, ylab=NA)
insertPlot(wb, "sheet", width = 100, height = 20, xy = NULL, 
           startRow = 80, startCol = 10, fileType = "png", units = "px", dpi = 100)
par(op)

saveWorkbook(wb, file="test.xlsx", overwrite = T)

sessionInfo()

R version 3.6.0 (2019-04-26) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding

locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 LC_MONETARY=Portuguese_Brazil.1252 [4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] tidyr_0.8.3 lubridate_1.7.4 openxlsx_4.1.0 dplyr_0.8.1 odbc_1.1.6

loaded via a namespace (and not attached): [1] Rcpp_1.0.1 magrittr_1.5 hms_0.4.2 tidyselect_0.2.5 bit_1.1-14 R6_2.4.0
[7] rlang_0.3.4 stringr_1.4.0 blob_1.1.1 tools_3.6.0 DBI_1.0.0 bit64_0.9-7
[13] assertthat_0.2.1 tibble_2.1.1 crayon_1.3.4 zip_2.0.2 purrr_0.3.2 glue_1.3.1
[19] stringi_1.4.3 compiler_3.6.0 pillar_1.4.0 pkgconfig_2.0.2

cesargil commented 5 years ago

Please ignore the issue, I was passing startCol=NULL in the main source. It is working perfectly now. A validation of the argument with some warning would be a nice addition though.