简体   繁体   English

将R中的图形另存为Excel中的可编辑图形

[英]Save graph from R as editable graphic in Excel

I am writing a GUI in R, and one of the functions I must implement is a button to save graphical output to an Excel sheet, ideally the graphic should be editable in Excel. 我正在用R编写GUI,我必须实现的功能之一是将图形输出保存到Excel工作表的按钮,理想情况下,图形应可在Excel中编辑。 I am trying to do this the following way: 我正在尝试通过以下方式做到这一点:

  1. Save data used for graph to an .xlsx file 将用于图形的数据保存到.xlsx文件
  2. Call a VBA scrip from R to recreate the graph in the .xlsx file. 从R调用VBA脚本,以在.xlsx文件中重新创建图形。

I am stuck with step two, as I dont know how to execute a vba scrip from R. Any help is greatly appreciated. 我陷入了第二步,因为我不知道如何从R执行vba脚本。任何帮助将不胜感激。

I'd suggest setting up the sheet as a template and then create the graph and linking it to a specific area on the sheet or another sheet. 我建议将工作表设置为模板,然后创建图形并将其链接到工作表或另一工作表上的特定区域。 Then when you need to create a new file, copy the template and add the data from R to Excel and then the graph will update with the new data. 然后,当您需要创建新文件时,复制模板并将R中的数据添加到Excel,然后图形将使用新数据进行更新。

If you want to use VBA then the method I generally use is StatconnDCOM + RCOM and just address Excel as a COM object. 如果要使用VBA,那么我通常使用的方法是StatconnDCOM + RCOM,只需将Excel作为COM对象即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM