设值单元格字体和背景色的颜色-实例

Sub main()
   Dim i,n As Integer
   Dim d, e As String
   Dim c As String 
   For i = 1 To 10
     'get cell's value in 输入sheet. 
       d = Trim(Range("D" & i).Value)
       e = Trim(Range("E" & i).Value)
     'set cell'value
        For n = 5 To 20000 
         c = Trim(Sheets("更新sheet").Range("C" & n).Value)
        'd is 输入key's value
         If c <> "" And c = d Then 
           Sheets("更新sheet").Range("D" & n).Value = e 
           Sheets("更新sheet").Range("D" & n).Interior.ColorIndex = 3  'set color to red
           Sheets("更新sheet").Range("D" & n).Font.ColorIndex = 2     'set fond to white   
         End If 
       Next
   Next
End Sub

Sheets("更新sheet").Range("D" & n).Value

这里的"D" & n是一个动态的cell,即为更新sheet的单元格值.

cells.Interior.ColorIndex = 3   '设值cell的背景色;

cells(1,1).Interior.Color = RGB(0,255,0) '设置为绿色

cells.Font.ColorIndex = 2      '设值cell的字体颜色;

cells(1,1).Font.Color = RGB(0,0,255) '设置为绿色

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Qt中,置QTableView的表头字体颜色背景颜色可以通过继承自`QStyledItemDelegate`并重写其相关方法来实现。这里是一个简单的示例: 首先,你需要创建一个自定义的样式委托(CustomDelegate),例如`MyDelegate`: ```cpp class MyDelegate : public QStyledItemDelegate { public: explicit MyDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {} // 重写 paintSection() 方法背景颜色 void paintSection(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override { if (index.column() == 0) { // 假你想要改变第一列的样式 painter->fillRect(option.rect, QColor(Qt::lightGray)); // 背景 } // 重写 paintText() 方法置文本颜色 QStyledItemDelegate::paintText(painter, option, index); } // 可选:如果想置特定文字的颜色,可以在paintText()中进行修改 void paintText(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int column, int row) const override { if (column == 0) painter->setPen(Qt::red); // 字体颜色为红 QStyledItemDelegate::paintText(painter, option, text, column, row); } }; ``` 然后,在你的`QMainWindow`或`QWidget`的实例中使用这个自定义委托: ```cpp QTableView *tableView = new QTableView(this); MyDelegate *delegate = new MyDelegate(this); tableView->setItemDelegate(delegate); // 如果你想改变所有表头单元的样式 tableView->horizontalHeader()->setDefaultSectionSize(100); // 置宽度 tableView->horizontalHeader()->setFont(QFont("Arial", 12)); // 字体 tableView->horizontalHeader()->setStyleSheet("background-color: lightgray; color: red;"); // 直接置样式 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值