formatting - 将字母数字数据导出到 Excel
问题描述
将数据框导出到 Excel 后,我遇到了格式化问题。我计算数据,然后使用掩码公式,如果样本太低,则隐藏一些数据(使用 -- 符号):
ValStat <- function(d,a,i,df){
o <- count(d)
per25 <- round(quantile(d$b, probs = 0.25,type = 6),digits = 0)
per50 <- round(quantile(d$b, probs = 0.5,type = 6),digits = 0)
per75 <- round(quantile(d$b, probs = 0.75,type = 6),digits = 0)
df1 <- InitDf(2)
df <- rbind(df, df1, stringsAsFactors = FALSE)
if(o<22){
df <- FillDf(df,2,i,a,o,"--","--","--")
}
else{
df <- FillDf(df,2,i,a,o,per25,per50,per75)
}
return(df)
}
但是我导出到 excel 的内容如下所示: https ://i.stack.imgur.com/r8zhP.png
所以“--”左对齐(作为文本),数字右对齐。看起来 excel 忽略了我在 R 代码中使用的输出格式:
CellStyle(wb, dataFormat=NULL, alignment=NULL, border=NULL, fill=NULL, font=NULL)
TITLE_STYLE <- CellStyle(wb)+ Font(wb, heightInPoints=16, isBold=TRUE, underline=1)
SUB_TITLE_STYLE <- CellStyle(wb) + Font(wb, heightInPoints=11, isItalic=FALSE, isBold=TRUE)
TABLE_COLNAMES_STYLE <- CellStyle(wb) + Font(wb, isBold=TRUE) +Alignment(wrapText=TRUE, horizontal="ALIGN_CENTER") +
Border(color="black", position=c("TOP", "BOTTOM"), pen=c("BORDER_THIN", "BORDER_THICK"))
COL_STYLE <- CellStyle(wb) + Alignment(wrapText=FALSE, horizontal="ALIGN_RIGHT")
有没有办法让“--”和数字以相同的方式格式化?向右会很棒。
解决方案
推荐阅读
- c# - Fluent Validation - 如何确保集合 Count 在不为空时大于零,但可以为空
- pandas - 为连接多个数据集编写相同条件的更好方法是什么?
- python - 如果你有时间,请告诉我一个我在 Python 中遇到过的计算
- sql - 用 Sql Server 中的列数据替换行
- azure-data-explorer - Kusto 中的 format_datetime() 用于日期时间,分钟和秒为 00
- ios - 如何在 iOS Swift 5 中弹出到根视图控制器后更改 UITabViewController 索引
- angular - 如何将 Ionic Page 上的元素移动到中心?
- php - 如何从 Laminas 的 url 参数中获取 $id?
- python - 识别 Linux passwd 文件
- javascript - 用等效的javascript替换样式标签