Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:32:05+00:00 2026-06-02T21:32:05+00:00

I am preparing a report that I will need to re-run on a more

  • 0

I am preparing a report that I will need to re-run on a more or less weekly basis. It needs to go to the client in Excel and I’ve been using the XLConnect package for R with great success but I’ve got one problem I can’t seem to over come on my own.

Given the following code:

simple <- data.frame(a = c(1,2,3,,4,5), b = c(1,2,3,4,5))

library(XLConnect)
prcntg <- createCellStyle(wb)
setDataFormat(prcntg, format = "0.0")

wb <- loadWorkbook("foo.xlsx", create = FALSE)

sheet <- "bar"
createSheet(wb, sheet)

writeWorksheet(wb, simple, sheet = sheet)
rows <- 1:5
cols <- 1:2
setCellStyle(wb, sheet = sheet, row = rows, col = cols, cellstyle = prcntg)

I want the values to be printed as:

a   | b
1.0 | 1.0
2.0 | 2.0
3.0 | 3.0
etc.

But, they are coming into the worksheet as:

a | b
1 | 1
2 | 2
3 | 3
etc.

How do I get the former and not the latter. Based on the documentation and the post I saw here: https://miraisolutions.wordpress.com/2011/08/31/xlconnect-a-platform-independent-interface-to-excel/

I feel like I am doing everything right, but obviously I’m not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:32:06+00:00Added an answer on June 2, 2026 at 9:32 pm

    The following appears to work for me:

    wb <- loadWorkbook("~/Desktop/foo.xlsx", create = TRUE)
    prcntg <- createCellStyle(wb)
    setDataFormat(prcntg, format = "0.0")
    
    sheet <- "bar"
    createSheet(wb, sheet)
    
    writeWorksheet(wb, simple, sheet = sheet)
    rows <- 2:6
    cols <- 1:2
    setCellStyle(wb, sheet = sheet, row = rep(2:6,times = 2), col = rep(1:2,times = 6), cellstyle = prcntg)
    saveWorkbook(wb)
    

    This runs with (with a warning). Note the specification of the row and col arguments in setCellStyle. I am, however, reluctant to assume that this will work for you as well, as XLConnect has been acting a little wonky for me lately (I’m on OS X and had to build it from source on 2.15.0, as it failed the CRAN checks so there’s no binary).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am preparing a web page with more data that can possibly be shown
I'm preparing to embark on a web app development that will make little to
I'm preparing a string that will be eval 'ed. The string will contain a
I am preparing an interactive PDF document that will be read in an iPad.I
I am preparing to develop a web application that will (hopefully) be used by
I am preparing to start on a new short-term contract (1-2 months) that involves
I am preparing for my interview and came across this question: Consider that i
I am preparing an Excel sheet in which I have to maintain the version
I am preparing an offer for a customer. They proide weekly data to different
CONTEXT: I am preparing a big C# merge using visual studio 2008 and TFS.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.