【发布时间】:2012-06-25 23:05:56
【问题描述】:
我正在尝试使用 ClosedXml 读取 Excel 中单元格的填充背景颜色。我在this sample code 工作,能够毫无问题地读取 Excel 文档的内容,但无法将单元格的 Fill BackgroundColor 读取为十六进制值。我能够看到在 BackgroundColor 下定义的 ThemeColor 和 ThemeTint 属性,但还没有找到将它们转换为任一 System.颜色 或十六进制值。这是我的代码:
// Get all categories
while (!categoryRow.Cell(coCategoryId).IsEmpty())
{
IXLCell categoryName = categoryRow.Cell(coCategoryName);
categories.Add(categoryName.GetString() + " " + XLColor.FromTheme(categoryName.Style.Fill.BackgroundColor.ThemeColor, categoryName.Style.Fill.BackgroundColor.ThemeTint).Color.ToHex());
categoryRow = categoryRow.RowBelow();
}
似乎方法 XLColor.FromTheme 总是抛出异常“无法将主题颜色转换为颜色”。有谁知道从 ThemeColor 和 ThemeTint 值获取 System.Color 的另一种方法?
更新:
我没有提到我已经尝试过使用 BackgroundColor 的 Color 属性,不幸的是,它没有正确填充,如果您在调试器中查看它,那么您将看到这个属性抛出了与方法 XLColor.FromTheme 相同的异常。所以这绝对看起来像 ClosedXml 中的一个错误。有人知道解决方法吗?
【问题讨论】: