将数据框出到R中的多个Excel工作簿中,并完整有条件格式
我有一个数据集,我想将其导出到有条件格式的多个Excel工作簿中。我无法发布实际数据,但是示例在下面。本质上,我有一个数据集显示个人或一个人是否有资格参加调查,他们所在的部门中的部门和团队:
调查状态 | 部队 | 团队 |
---|---|---|
1 | 1预算使徒行传 | 销售 |
1 | 6 | 销售 |
本地 | 1 | 个 |
公共 | 社交 | 我 |
想要要执行以下操作:
- 有条件地格式化数据,以使1个调查状态为1的行以大胆,黑色文本和订阅状态为0的行中,以不折叠,红色文本为例,以易于阅读。
- 导出到Excel时保持这种格式。
- 为每个部门/团队分组创建一个单独的工作簿。
我可以在R中格式化数据,并且可以为每个部门/团队分组创建一个单独的工作簿,而不会出现问题。
问题是格式丢失了。我尝试了一些不同的软件包,包括XLSX,OpenXLSX,Forgatable和Condformat,但似乎无法弥合差距,以便在Excel文件中应用格式。
我以前能够做到这一点是SAS没有问题。我们正在过渡到R,这就是为什么我重新创建这些文档的原因。但是,我想知道R是否是此过程的最佳选择。也许Python会更好?
事先感谢您的所有帮助。 SO社区是我学习编码的生命线,并且一直是宝贵的资源。
I have a dataset that I'd like to export to multiple Excel workbooks with conditional formatting. I can't post the actual data, but a sample is below. Essentially, I've got a dataset showing whether or an individual qualifies for a survey, what department and team within the department they are in:
Survey Status | Department | Team |
---|---|---|
1 | Budget Off | Acts |
0 | Budget Off | Acts |
1 | Sales | Local |
1 | Public Rel | Social |
I want to do the following:
- Conditionally format the data so that rows with a survey status of 1 are in bold, black text and rows with a survey status of 0 are in non-bold, red text for easier reading.
- Maintain this formatting when exporting to Excel.
- Creating an individual workbook for each Department/Team grouping.
I can format the data how I'd like within R, and I can create an individual workbook for each Department/Team grouping without a problem.
The issue is that the formatting gets lost. I've tried a few different packages, including xlsx, openxlsx, formattable, and condformat, but can't seem to bridge the gap so that the formatting is applied within the Excel files.
I was previously able to do this is SAS with no problems. We're transitioning to R, which is why I'm recreating these documents. However, I'm wondering if R is the best choice for this procedure. Perhaps Python would be better?
Thanks in advance for all your help. The SO community is my lifeline in learning to code, and has been an invaluable resource.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终在YouTuber Cradletograver的帮助下发现了这个问题。用户错误!它是在conditionalformatting()中的“规则”公式中使用的,
我一直在使用openxlsx文档中的格式示例(例如,rule =“ $ colname = 1”,但将其应用于字符串(例如,rule =” $ colname = yes”),这就是为什么Excel无法识别它。
单引号(例如,rule ='$ colname =“ yes”
有条件地格式化字符串时,请使用围绕该值的双引号围绕规则的 展示如何在此视频中为文本值格式化, https://wwww.youtube.com/watch.com/watch.com/watch ?v = acdcquqjxhu
Finally discovered the problem with the help of YouTuber CradleToGraveR. User error! It was in the formula for the "rule" within conditionalFormatting()
I had been using the formatting examples in the documentation for openxlsx (e.g., rule = "$colname=1", but applying it to a string (e.g., rule = "$colname=YES"), which is why Excel didn't recognize it.
When conditionally formatting strings, use single quotes around the rule with double quotes around the value (e.g., rule = '$colname="YES"').
CradleToGraveR shows how to format for text values in this video, https://www.youtube.com/watch?v=ACdCQuQJxhU