使用xlsx的Excel单元格着色 [英] Excel Cell Coloring using xlsx

查看:172
本文介绍了使用xlsx的Excel单元格着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们使用此命令创建虚拟数据:

Lets assume we're using this command to create the dummy data:

Data <- data.frame(
    X = paste(c(sample(1:10),sample(1:10)), collapse=";"),
    Y = sample(c("yes", "no"), 10, replace = TRUE)
)



输出:



Output:

                                           X   Y
1  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes
2  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7  no
3  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7  no
4  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes
5  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7  no
6  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes
7  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7  no
8  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes
9  10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes
10 10;7;4;3;8;6;5;2;9;1;3;5;10;2;9;6;8;4;1;7 yes



问题:



使用 xlsx 包可以将 X 列数据输出到彩色的excel文件。

Question:

Using xlsx package I can output the X column data to an excel file colored.

有没有一种我可以使用颜色的方法,让值大于 5 红色 strong> 5 到蓝色,并放在相同的单元格中。基本上我只是把这个表写成一个excel,但有些值是有色的。

Is there a way where I can color lets say the values bigger then 5 to red and lesser then 5 to blue and put in the same cell everything. Basically I just write this table to an excel but some values are colored.

提前谢谢,

推荐答案

我怀疑是否可以直接从 R 更改Excel的条件格式。因此,首先打开Excel工作簿,并为X列设置条件格式,将进入所需的任何颜色与值条件。那么当你从R写入工作簿时,着色就会发生。

I doubt it's possible to change Excel's conditional formatting directly from R. So, first open the Excel workbook and set the conditional formatting for the column "X" is going into to whatever color vs value conditions you want. Then when you write from R into the workbook, the coloring will happen.

这篇关于使用xlsx的Excel单元格着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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