gpt4 book ai didi

r - 使用 RDCOMClient 编辑 excel 属性

转载 作者:行者123 更新时间:2023-12-04 20:10:35 56 4
gpt4 key购买 nike

我找不到 RDComClient 包的任何文档。我找不到合适的参数来更改单元格的背景填充。

library(RDCOMClient)
xlApp <- COMCreate("Excel.Application")
book = xlApp$Workbooks()$Open("C:/Users/koyeli.majumder/Desktop/Dashboard/National Level Dashboard.xlsb")

sheet = book$Worksheets()$Item(1)
xlApp[["Visible"]] = TRUE

cell <- sheet$Cells(6,6)
cell[["Value"]] <- 3.1
cell[["NumberFormat"]] = "[Red]" # till this it was fine

cell[["Style"]] = 1

这给出了错误
<checkErrorInfo> 8002000E 
Error: Invalid number of parameters.

最佳答案

RDCOMClient 是一个通用的 COM 接口(interface)。它不是特定于 Excel。您需要引用一般 Excel 文档,该文档通常指的是 Basic 或 javascript,并将其翻译为 R。

内部颜色设置如下所示。颜色索引号可在此处找到:https://msdn.microsoft.com/en-us/library/cc296089(v=office.12).aspx

library(RDCOMClient)

xl <- COMCreate("Excel.Application")
xl[["Visible"]] <- TRUE
wkbk <- xl$Workbooks()$Add()
sheet <- xl$ActiveSheet()

x12 <- sheet$Cells(1,2)
x12[["Value"]] <- 123
x12[["Interior"]][["ColorIndex"]] <- 3 # Red

screenshot

关于r - 使用 RDCOMClient 编辑 excel 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50154012/

56 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com