简体   繁体   English

R:从 dataframe 导出多个 Excel 工作簿

[英]R: Export Multiple Excel Workbooks from dataframe

I have a dataframe of deals by person.我有一个 dataframe 的个人交易。 I have multiple people (30+) and I want to send them a report of just their deals.我有多个人(30 岁以上),我想向他们发送一份关于他们的交易的报告。 Rather than manually creating 30+ individual excel workbooks, is there a package in R that can do this?而不是手动创建 30 多个单独的 excel 工作簿,R 中是否有 package 可以做到这一点?

Below is my dummy data下面是我的虚拟数据

df <- tibble(
  Deal = c("Deal A", "Deal B", "Deal C", "Deal D", "Deal E", "Deal F", "Deal G", "Deal H"),
  Person = c("john", "henry", "max", "felix", "henry", "john", "max", "max")
)

The expected result of the dummy data is to have 4 (by person) separate excel workbooks with deal data so I can send it to the people via email.虚拟数据的预期结果是有 4 个(按人)单独的 excel 工作簿和交易数据,所以我可以通过 email 将其发送给人们。

Bonus points if I can format workbooks to all have bold header and format table with $ for numbers and dates for dates!如果我可以将工作簿格式化为所有具有粗体 header 的工作簿并使用 $ 为数字和日期的日期格式化表格,则可以获得奖励积分!

To expand on my comment above:要扩展我上面的评论:

library(tidyverse)
# Other packages for handling xlsx files are available
library(xlsx)
df %>% 
  group_by(Person) %>% 
  group_walk(
    function(.x, .y) {
      write.xlsx(.x, paste0(.y$Person, ".xlsx"), sheet="Sheet1")
    }
  )

After running this code, I see the following files in my current working directory运行此代码后,我在当前工作目录中看到以下文件

在此处输入图像描述

暂无
暂无

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

相关问题 将数据框导出到 R 中的多个 excel 工作簿,条件格式完好无损 - Export dataframe to multiple excel workbooks in R with conditional formatting intact 将来自多个 Excel 工作簿的数据与多个 Excel 工作表合并到 R Z6A8064553DF47945555704 - Merging data from multiple Excel workbooks with multiple Excel worksheets into an R dataframe 从R中的多个Excel工作簿中读取第二个Excel选项卡 - Reading the second excel tabs from multiple Excel workbooks in R 从 R 中的单个 Excel 工作表创建多个工作簿 - Creating multiple workbooks from a single Excel worksheet in R 读取同一目录中的所有 Excel 工作簿,每个工作簿都有多个工作表,并将每个工作表导出为 R 中的 a.csv - Read all Excel workbooks in the same directory each with multiple sheets and export each sheet as a .csv in R 通过将多个 excel 工作簿中的多个工作表组合到一个工作簿中。 R - Combining multiple worksheets from multiple excel workbooks into a single workbook via. R 只读选择性 Excel 工作簿到 R 并将它们保存为 dataframe - Read only selective Excel workbooks into R and save them as dataframe 导入多个 excel 工作簿,每个工作簿包含 R 中的多个工作表 - Import multiple excel workbooks each containing multiple sheets in R R:通过变量从数据集中导出多个工作簿excel - R: export multiple workbook excel from a dataset by a variable R 使用文本列将数据框导出到 Excel - R Export dataframe to Excel with text columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM