将数据写入特定的工作簿表 [英] Write data into a specific workbook sheet

查看:44
本文介绍了将数据写入特定的工作簿表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,例如

a=1:10 
b=31:40
c=data.frame(a=a,b=b)

,我将需要将此数据帧写入特定的Excel工作表("Sheet1").

and I will need to write this data frame into a specific Excel sheet ("Sheet1").

我现在正在使用WriteXLS,但是此功能始终会覆盖整个excel文件,从而删除其他工作表.如何在不覆盖以前的条目的情况下追加到工作表中?

I am using WriteXLS now but this function always overrides the entire excel file and thus deletes other sheets. How can I append to the sheet without overwriting previous entries?

推荐答案

这将向现有Excel工作簿中添加一个新的命名工作表,而不会更改现有工作表:

This will add a new named sheet to an existing Excel workbook without altering existing sheets:

# create data in R
a = 1:10 
b = 31:40
c0 = data.frame(a=a,b=b)

#  write data object 'c0' to existing Excel file 
# 'Book1.xlsx' into a new sheet called 'Sheet1'
library(XLConnect)
writeWorksheetToFile(file = "C:/.../Book1.xlsx", data = c0, sheet = "Sheet1")

请注意,如果工作簿已具有 Sheet1 ,则此函数将以静默方式覆盖它.因此,您需要确保工作表名称唯一.

Note that if the workbook already has a Sheet1 then this function would silently overwrite it. So you'll need to make sure your sheet names are unique.

这篇关于将数据写入特定的工作簿表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆