更改表格中特定单元格的字体颜色

时间:2020-06-26 15:58:59

标签: excel vba formatting

我有一个VBA过程,该过程遍历Excel表的行并更新单元格值:

SystemPropertiesDTO

我想增强代码,以便除了更新单元格值之外,还可以更改单元格字体的颜色。

我可以在整个专栏中做到这一点:

    @override
  Widget build(BuildContext context) {
    return Dismissible(
      key: UniqueKey(),
      direction: DismissDirection.endToStart,
      confirmDismiss: (direction) {
        return showDialog(
          context: context,
          builder: (context) => AlertDialog(
            title: Text('Are you sure?'),
            content: Text(
              'Dou you want to remove the item from the cart?',
            ),
            actions: [
              FlatButton(
                onPressed: () {
                  Navigator.of(context).pop(false);
                },
                child: Text('No'),
              ),
              FlatButton(
                onPressed: () {
                  Navigator.of(context).pop(true);
                },
                child: Text('Yes'),
              ),
            ],
          ),
        );
      },
      onDismissed: (direction) {
          Provider.of<Cart>(context, listen: false)
              .removeItem(productId);
      },
      background: Container(
        color: Theme.of(context).errorColor,
        child: Icon(
          Icons.delete,
          color: Colors.white,
          size: 40,
        ),
        alignment: Alignment.centerRight,
        padding: EdgeInsets.only(right: 20),
        margin: EdgeInsets.symmetric(
          horizontal: 15,
          vertical: 4,
        ),
      ),
      child: Container(
        child: Padding(
          padding: EdgeInsets.all(8),
          child: ListTile(
            leading: CircleAvatar(
              child: Padding(
                padding: EdgeInsets.all(5),
                child: FittedBox(
                  child: Text('\₹${(price * quantity)}'),
                ),
              ),
            ),
            title: Text(title),
            subtitle: Text(laundryName.toUpperCase()),
            trailing: Text('$quantity x'),
          ),
        ),
      ),
    );
  }
}

但是,我不知道如何从循环中更改特定单元格/行的字体颜色。

1 个答案:

答案 0 :(得分:2)

您已经很近了。 .ListColumns(colNameMessage).DataBodyRange(n)是单个单元格,因此:

.ListColumns(colNameMessage).DataBodyRange(n).Value = response 
.ListColumns(colNameMessage).DataBodyRange(n).Font.ColorIndex = 48

如(现在已删除的)注释中所述,最好使用.Font.Color代替.Font.ColorIndex,因为后者只是当前调色板中的索引,而不是绝对的颜色。