G.Maubach at weinwolf.de
2016-Nov-15 12:48 UTC
[R] openxlsx Error: length of rows and cols must be
Hi All, when using -- cut -- number_style <- openxlsx::createStyle( numFmt = "COMMA" ) openxlsx::addStyle( wb = xlsx_workbook, sheet = "Kundenliste", style = number_style, rows = 2:nrow(customer_list), cols = 4:5 ) --cut -- I get the error Error in openxlsx::addStyle(wb = xlsx_workbook, sheet = "Kundenliste", : Length of rows and cols must be equal. The customer_list can be of any arbritrary length due to subgroup definitons. I do not see why the argument "rows" and "cols" should be of the same length. This would mean that number formatting can only be done for rectangular areas. What do I need to change to format my numbers in the given area correctly? Kind regards Georg
This behavior is a basic limitation of spreadsheets. This R API is (inappropriately) more flexible than the underlying Java API is. You have to apply your formatting with multiple calls to the addStyle function, just as you would interactively in a spreadsheet. -- Sent from my phone. Please excuse my brevity. On November 15, 2016 4:48:50 AM PST, G.Maubach at weinwolf.de wrote:>Hi All, > >when using > >-- cut -- > > number_style <- openxlsx::createStyle( > numFmt = "COMMA" > ) > > openxlsx::addStyle( > wb = xlsx_workbook, > sheet = "Kundenliste", > style = number_style, > rows = 2:nrow(customer_list), > cols = 4:5 > ) >--cut -- > >I get the error > >Error in openxlsx::addStyle(wb = xlsx_workbook, sheet = "Kundenliste", >: > Length of rows and cols must be equal. > >The customer_list can be of any arbritrary length due to subgroup >definitons. I do not see why the argument "rows" and "cols" should be >of >the same length. This would mean that number formatting can only be >done >for rectangular areas. > >What do I need to change to format my numbers in the given area >correctly? > >Kind regards > >Georg > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.