Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So the xlsx package actually interfaces with a java library in order to pull in and modify the workbooks. The read.xlsx and write.xlsx functions are convenience wrappers to read and write data frames within R without having to manually write code to parse the individual cells and rows yourself using the java objects. The loadWorkbook and getRows functions give you access to the actual java objects, which you can then use to modify things such as cell styles.</p> <p>However, if all you want to do is add a blank row to your spreadsheet before you output it, the easiest way is to add a blank row to your data frame before you export it (as Chris mentioned). You can accomplish this with the following variant on your code:</p> <pre><code>library("xlsx") fn1 &lt;- 'test1.xlsx' fn2 &lt;- 'test2.xlsx' # I have added row.names=FALSE because the read.xlsx function # does not have a parameter to include row names write.xlsx(matrix(rnorm(25),5),fn1,row.names=FALSE) # If you read your data back in using the read.xlsx function # you will have a data frame rather than a series of java object references wb &lt;- read.xlsx(fn1,1) # Now that we have a data frame we can add a blank row at the top wb&lt;-rbind.data.frame(rep("",5),wb) # Then we write to the file using the same function as before write.xlsx(wb,fn2,row.names=FALSE) </code></pre> <p>If you desire to use the advanced functionality in the java libraries, some of it is not currently implemented in the R package, and thus you will have to call it directly using .jcall. If you decide to pursue this line of action, I definitely recommend using .jmethods on the objects produced (i.e. .jmethods(rows[[1]]) which will list the available functions which you can use on the object (at the cellular level these are quite extensive).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload