- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在尝试为数据透视表添加一些代码颜色。它可以很好地为单元格着色,但如果我刷新表格,所有颜色都会消失,就好像这些颜色没有正确附加到数据透视表一样。
我有以下代码(这是从一个更大的代码中截取的):
myPivotTable.PivotSelect("'" + item["Name"].ToString() + "'[All;Total]", XlPTSelectionMode.xlDataAndLabel, true);
((Range)Globals.ThisWorkbook.Application.Selection).Interior.Color = 15962653;
我试过在 VB 的 Excel 中做一个宏,当它运行时,它工作得很好,所以我不明白为什么 C# VSTO 不能工作...
ActiveSheet.PivotTables("PivotTable1").PivotSelect "'ItemName'[All;Total]", xlDataAndLabel, True
Selection.Interior.Color = 15962653
非常感谢您的帮助:)
编辑
这里有更多的代码。BaseVars.GlobalWB 是一个引用事件工作簿 (Globals.ThisWorkBook) 的变量。这使得同时使用 2 个 Excel 成为可能,而 VSTO 不会在错误的工作簿上运行代码。
foreach (DataRow item in myPivotTableFields.Tables[0].Rows)
{
// Field name from data sheet
myPivotField = (PivotField)myPivotFields.Item(item["Name"].ToString());
// Field name in the pivot table
myPivotField.Caption = item["Caption"].ToString();
// Their subtotal value
myPivotField.set_Subtotals(Type.Missing, GenerateSubTotalArray(item["SubTotal"].ToString()));
#region Attribs
//Include new items in manual filter
if (item["Attrib01"].ToString() == "True")
{
myPivotField.IncludeNewItemsInFilter = true;
}
else
{
myPivotField.IncludeNewItemsInFilter = false;
}
// Show items labels in outline form
if (item["Attrib02"].ToString() == "Outline")
{
myPivotField.LayoutForm = XlLayoutFormType.xlOutline;
}
else
{
myPivotField.LayoutForm = XlLayoutFormType.xlTabular;
}
// Display labels from the next field in the same column
if (item["Attrib03"].ToString() == "True")
{
myPivotField.LayoutCompactRow = true;
}
else
{
myPivotField.LayoutCompactRow = false;
}
// Display subtotals at the top of each group
if (item["Attrib04"].ToString() == "AtBottom")
{
myPivotField.LayoutSubtotalLocation = XlSubtototalLocationType.xlAtBottom;
}
else
{
myPivotField.LayoutSubtotalLocation = XlSubtototalLocationType.xlAtTop;
}
// Insert blank line after each item label
if (item["Attrib05"].ToString() == "True")
{
myPivotField.LayoutBlankLine = true;
}
else
{
myPivotField.LayoutBlankLine = false;
}
// Show items with no data
if (item["Attrib06"].ToString() == "True")
{
myPivotField.ShowAllItems = true;
}
else
{
myPivotField.ShowAllItems = false;
}
// Insert page break after each item
if (item["Attrib07"].ToString() == "True")
{
myPivotField.LayoutPageBreak = true;
}
else
{
myPivotField.LayoutPageBreak = false;
}
#endregion
// Set up the pivot table selection
if (item["Selection"].ToString() != "(blank)")
{
myItems = new List<string>();
myItems = GlobalFunc.Explode(item["Selection"].ToString());
SetUpPivotTableSelection(myPivotTable, item["Name"].ToString(), myItems);
}
else if (item["Selection"].ToString() == "(blank)" && item["Orientation"].ToString() == "Filter")
{
myPivotField.ClearAllFilters();
myPivotField.CurrentPage = "(All)";
}
try
{
myPivotField.ClearValueFilters();
myPivotField.ShowDetail = true;
}
catch (Exception ex)
{
GlobalFunc.DebugWriter("Error during Pivot Table Reset: " + ex.Message);
}
try
{
myPivotTable.PivotSelect("'" + item["Name"].ToString() + "'[All;Total]", XlPTSelectionMode.xlDataAndLabel, true);
// Set up the fields borders if it has any
myRange = BaseVars.GlobalWB.Application.get_Range(BaseVars.GlobalWB.Application.Selection, BaseVars.GlobalWB.Application.Selection);
myRange.Borders[XlBordersIndex.xlEdgeBottom].LineStyle = (XlLineStyle)InsertLineStyle(item["Attrib12"].ToString());
myRange.Borders[XlBordersIndex.xlEdgeLeft].LineStyle = (XlLineStyle)InsertLineStyle(item["Attrib13"].ToString());
myRange.Borders[XlBordersIndex.xlEdgeRight].LineStyle = (XlLineStyle)InsertLineStyle(item["Attrib14"].ToString());
myRange.Borders[XlBordersIndex.xlEdgeTop].LineStyle = (XlLineStyle)InsertLineStyle(item["Attrib15"].ToString());
}
catch (Exception ex)
{
GlobalFunc.DebugWriter("<LI>Error occured: " + ex.Message + "</LI>");
}
// Insert the colors of the field, gradient or solid
if (item["Color_Total2"].ToString() != null && item["Color_Total2"].ToString() != "")
{
Base.InsertGradient(myRange, int.Parse(item["Color_Total1"].ToString().Replace("0x", ""), System.Globalization.NumberStyles.HexNumber), int.Parse(item["Color_Total2"].ToString().Replace("0x", ""), System.Globalization.NumberStyles.HexNumber), false);
}
else if (item["Color_Total1"].ToString() != null && item["Color_Total1"].ToString() != "")
{
BaseVars.GlobalWB.Application.get_Range(BaseVars.GlobalWB.Application.Selection, BaseVars.GlobalWB.Application.Selection).Interior.Color = int.Parse(item["Color_Total1"].ToString().Replace("0x", ""), System.Globalization.NumberStyles.HexNumber);
}
}
最佳答案
如果您使用的是 C# VSTO,请不要使用 Selection.Interior.Color。请改用 Selection.Interior.ColorIndex。 Excel 使用 56 色调色板,您在 C# 中指定的任何颜色都将“转换”为其中一种调色板颜色。有效的 ColorIndex 值介于 1 和 56 之间。另请查看有关调色板和 Excel 的有用引用。
关于C#VSTO : Coloring pivottable cells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2864047/
假设我有一个颜色数组(具有整个色谱,从红色到红色。)。较短的版本如下所示: public Color[] ColorArray = new Color[360] { Color.FromArgb(25
当我通过 http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.gamefriction.com%2FCoded&prof
我需要帮助来解决验证 CSS。在这里,我在 W3 验证中遇到了 20 个相同的错误。我不明白。如果您能解决此问题,我将不胜感激。 错误:两种上下文中 color 和 background-color
我正在尝试覆盖 bootstrap4 样式。 我没有使用 Sass 的经验,但这看起来像是 bootstrap SCSS 文件中的错误。 我的自定义文件是: /* custom.scss */
我是 sass 的新手,我写了一些 sass 代码,但它没有编译。 $classes : primary secondary success warning danger; $colors
我想制作一个散点图,其中每个点都有一个球体。点及其球体都根据某些列值着色。 一个显示我想要的最小示例: library(ggplot2) library(vcd) # only needed for
我正在尝试添加一个选项来更改网站颜色。所以,我有一个工作正常的色域,但问题是当鼠标悬停时我需要将颜色更改为深 10%。函数 darken 表示第一个参数必须是颜色。 Error: argument `
我正在尝试从下拉菜单中更改主题颜色,但出现此错误:“预期类型为'List>'的值,但类型为之一 'MappedListIterable>' Color selected ; MaterialApp(
有没有办法将 Inno Setup 底部面板的背景颜色更改为白色? 谢谢你的帮助! 最佳答案 您描述的底部面板实际上是向导表单的区域,因此您只需设置 Color WizardForm 的属性(prop
sublime text包Color Highlighter看起来很有用。但是,它的行为似乎并不像文档中描述的那样。 根据文档: Usage : Just click or move the curs
我有一个由 Excel 2007 创建的文档: ... 在 xl/styles.xml 的字体定义中包含以下颜色: 我从ECMA标准了解到这个颜色索引指的是收藏于 xl/styles.xml如果有
简单问题: (如何)是否可以设置 的值在 Chrome 中选择此类输入时,要在颜色选择器中清空吗? 编辑:我想将输入的值更改为 "" 最佳答案 我认为它不能设置为透明,但您可以使用value="#c
我正在尝试截屏,检查屏幕截图中的某种颜色,如果找到该颜色,则单击它。 我遇到的问题是颜色的 RGB 值必须准确。 我想知道是否可以将图像转换为颜色很少的图像。 抱歉打扰了。我没有受过适当的训练。我现在
有谁知道为什么 CSS 为文本提供了 color,但没有 font-color 或 text-color? 看起来很反直觉,有点像text-decoration: underline 而不是font-
我想弄清楚为什么 mix-blend-mode: color; css 选择器和值会影响除白色以外的所有颜色,而不是影响除白色和黑色以外的所有颜色。有人可以向我解释为什么会这样吗? 最佳答案 来自 t
我正在尝试创建 Angular 2 主题,我按照网站上提到的教程进行操作。这是我的主题文件。 @import '~@angular/material/theming'; @include mat-co
我正在尝试更改 ProgressBar 中栏的颜色 pBar.setStyle("-fx-accent: green"); 但我遇到了一个问题:这似乎不适合我! (或者我只是不明白一些事情) 这是代码
给定最大迭代次数 = 1000 给我一些关于如何着色(红色、绿色、蓝色)的想法。我现在能想到的只有蹩脚的 2 种颜色渐变:( 真的有可能想出像这样美丽的东西吗? 最佳答案 该死的,他们不会让我一个新手
要将 url 参数解码为颜色,我使用此 HttpMessageConverter: public class ColorHttpMessageConverter implements HttpMess
我创建了一个显示色谱的自定义控件。我正在覆盖 OnRender() 方法以使用颜色绘制控件。由于某种原因,“计算”的颜色(R G B 值)具有一定的透明度,即使我将 Alpha 值 (A) 设置为最大
我是一名优秀的程序员,十分优秀!