awalker89 / openxlsx

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

writeDataTable converts table name in locase #491

Open theclue opened 4 years ago

theclue commented 4 years ago

This is painful, as I've a lot of pivot tables on my read-only excel template which rely on a table called "Table1" while I get "table1" instead on my data file generated using the package.

> tier1 <- readWorkbook(wb, sheet = "tier1")
> getTables(wb, "tier1")
 A1:M21387 
"Tabelle1" 
attr(,"refs")
[1] "A1:M21387"
> removeTable(wb,
+             sheet = which(wb$sheet_names == "tier1"),
+             table = "Tabelle1")
> writeDataTable(wb,
 +                sheet = which(wb$sheet_names == "tier1"),
 +                tier1,
 +                withFilter = TRUE,
 +                rowNames = FALSE,
 +                colNames = TRUE,
 +                startRow = 1,
 +                tableName = "Tabelle1")
> getTables(wb, "tier1")
"tabelle1"  
attr(,"refs")
 [1] "A1:M18256"
>

what do u think? is somewhat the intended behaviour? Shall I have my excel template to be updated?

tnx!

amlestin commented 4 years ago

You have to change your Excel template because Excel requires table names to be lowercase.

Check out this logic:

Workbook$methods(validate_table_name = function(tableName){

  tableName <- tolower(tableName) ## Excel forces named regions to lowercase

https://github.com/awalker89/openxlsx/blob/ead0038c59a227faa5c03f13aa7c6211f63dc9e0/R/WorkbookClass.R