gpt4 book ai didi

c# - 更改 MS Excel 2003 的背景

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:30 25 4
gpt4 key购买 nike

我是一名 C# 编码员,到目前为止,这是我所知道的表达我想要的东西的最佳方式。我正在考虑在 Microsoft Excel 2003 工作表上执行下面的代码。这可能吗?

第一步

if(CellA1 == "Sunday" || CellA1== "Saturday"){
// code to set background color of
// CellB1 to CellF1 to background color red
}

第二步

// Execute this process from CellA1 until CellA10    
for(CellA1 up to CellA10){
// do first step
}

所以我想在 MSExcel 2003 上执行的代码如下所示

for(int CellCount = 1;CellCount<10;CellCount++){

if("CellA"+CellCount.ToString() == "Sunday" ||
"CellA"+CellCount.ToString() == "Sunday"){

// set ["CellB"+CellCount.ToString()].CellBackgroundColor="#FF0000";
// set ["CellC"+CellCount.ToString()].CellBackgroundColor="#FF0000";
// set ["CellD"+CellCount.ToString()].CellBackgroundColor="#FF0000";
// set ["CellE"+CellCount.ToString()].CellBackgroundColor="#FF0000";
// set ["CellF"+CellCount.ToString()].CellBackgroundColor="#FF0000";
}

}

我不确定这是否可行。或者,如果还有其他与我想做的事情相同的方法,你能帮帮我吗? :) 谢谢!

最佳答案

如果您只想根据单元格的值更改单元格的颜色,只需在 excel 中使用条件格式,无需任何编程。

关于c# - 更改 MS Excel 2003 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6225918/

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