Hi,
I'm trying to write out matrices within a loop to different worksheets
in the same Excel spreadsheet. I was trying to do this with the
openData (using the pageNumber argument to specify the worksheet) and
writeNextDataRows functions. When I do this, it only writes to one
worksheet and overwrites the data as the loop increments. I am able to
read from multiple worksheets ok. See examples below:
### Creates 3 dataframes from 3 worksheets in Excel file
for(i in 1:3) {
out.file <- openData("test.xls", type="Excel", openType="read",
pageNumber = i)
if(i==1) test.df1<-readNextDataRows(out.file)
if(i==2) test.df2<-readNextDataRows(out.file)
if(i==3) test.df3<-readNextDataRows(out.file)
closeData(out.file)
}
#### Does not write to multiple sheets; overwrites 1st sheet
for(i in 1:3) {
out.file <- openData("test2.xls", type="Excel", openType="write",
pageNumber = i)
x <- matrix(rnorm(50), ncol=5)
writeNextDataRows(out.file, x)
closeData(out.file)
}
Does the pageNumber argument only work for openType="read"? Is there
any other way to export to multiple worksheets?
Thanks for any advice. I am using Splus 6.1 on MS Windows 2000.
-Trevor
|