简体   繁体   English

如何为所有相关的行和列着色,而不仅仅是它们的一部分(Aspose Cells)?

[英]How can I color all the related rows and columns, rather than just a subset of them (Aspose Cells)?

I had a related question heretofore , and the answer there that (pretty much) works for me is to use: 到目前为止,我有一个相关的问题,在那里(相当) 可行的答案是使用:

pt.ShowInCompactForm();

In a spreadsheet I generate, there are blocks of items that span 5 rows - the first row is a Description, and the four rows below it are "subrows" with detail data for that item (namely, "Total Packages", "Total Purchases", "Sum of Average Price", and "Percentage of Total"). 在我生成的电子表格中,有许多项目块跨越5行-第一行是说明,下面的四行是“子行”,其中包含该项目的详细数据(即“总包装”,“总购买量” ”,“平均价格总和”和“总计百分比”)。

In certain cases, I need to colorize the cells in that region and am able to do this, for the most part, with the following code: 在某些情况下,我需要为该区域中的单元着色,并且能够在大多数情况下使用以下代码来做到这一点:

private void ColorizeContractItemBlocks(List<string> contractItemDescs)
{
    int FIRST_DESCRIPTION_ROW = 7;
    int DESCRIPTION_COL = 0;
    int ROWS_BETWEEN_DESCRIPTIONS = 5; 
    var pivot = pivotTableSheet.PivotTables[0];
    var dataBodyRange = pivot.DataBodyRange;
    int currentRowBeingExamined = FIRST_DESCRIPTION_ROW;
    int rowsUsed = dataBodyRange.EndRow;

    pivot.RefreshData();
    pivot.CalculateData();

    PivotTable pt = pivotTableSheet.PivotTables[0];
    var style = workBook.CreateStyle();

    // Loop through PivotTable data, colorizing contract items
    while (currentRowBeingExamined < rowsUsed)
    {
        Cell descriptionCell = pivotTableSheet.Cells[currentRowBeingExamined, DESCRIPTION_COL];
        String desc = descriptionCell.Value.ToString();

        if (contractItemDescs.Contains(desc))
        {
            style.BackgroundColor = CONTRACT_ITEM_COLOR;
            style.Pattern = BackgroundType.Solid;

            CellArea columnRange = pt.ColumnRange;
            // Using StartColumn-1 instead of StartColumn-1 gives me the "Percentage of Total" data field subrow (but not the others - "Total Packages", "Total Purchases", and "Sum of Average Price")
            for (int c = columnRange.StartColumn-1; c <= columnRange.EndColumn; c++)
            {
                //pt.Format(currentRowBeingExamined-1, c, style); <= Instead of adding the "Description" row, this colors up some unrelated final ("Percentage of Total") data rows
                pt.Format(currentRowBeingExamined, c, style);
                pt.Format(currentRowBeingExamined + 1, c, style);
                pt.Format(currentRowBeingExamined + 2, c, style);
                pt.Format(currentRowBeingExamined + 3, c, style);
            }

        }
        currentRowBeingExamined = currentRowBeingExamined + ROWS_BETWEEN_DESCRIPTIONS;
    }
}

But it only works "for the most part," because I am unable to colorize the "Description" row (such as, "AVOCADOS, HASS 70 CT #2") or any but the last row of column 0/A, - the "Percentage of Total" subrow, as can be seen here: 但这只能“大部分”起作用,因为我无法为“说明”行(例如“ AVOCADOS,HASS 70 CT#2”)或除第0 / A列的最后一行以外的其他任何颜色上色- “总计百分比”子行,如下所示:

在此处输入图片说明

It may be that the Description row is better left untainted/unpainted, but I think the subrows beneath would be better off colorized, and I don't understand why they are not. 可能最好将“描述”行保留为未污染/未上漆,但我认为下面的子行最好采用彩色,但我不明白为什么它们没有。

I can prevent ALL of those subrows from being colored by using this: 我可以使用以下方法防止所有这些子行着色:

for (int c = columnRange.StartColumn; c <= columnRange.EndColumn; c++)

(that is to say, starting the loop with "StartColumn" instead of "StartColumn-1" prevents anything in column 0/A from being colorized), but it seems bizarre to me that only that last subrow colors up when I start from one column back (at 0/A). (也就是说,使用“ StartColumn”而不是“ StartColumn-1”启动循环可防止对第0 / A列中的任何内容进行着色),但对我来说,奇怪的是,当我从一个开始时,只有最后一个子行才着色列后退(0 / A)。

We will look into your issue in this Aspose.Cells Forum Thread created by you. 我们将在您创建的Aspose.Cells论坛线程中调查您的问题。

Note: I am working as Developer Evangelist at Aspose 注意: 我在Aspose担任开发人员布道者

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在EPPlus中过滤列(而不是行)? - How can I filter columns (rather than rows) in EPPlus? 如何确定数据透视表生成多少行(Aspose Cells)? - How can I determine how many rows a PivotTable generates (Aspose Cells)? 如何将我的数据字段放在 Excel 数据透视表(Aspose Cells)的 COLUMNS 中 - How can I place my data fields in COLUMNS in my Excel Pivot Table (Aspose Cells) 如何在计算出的像元(Aspose Cells)中防止“#Div / 0!”? - How can I prevent “#Div/0!” in calculated cells (Aspose Cells)? 如何在电子表格范围(Aspose Cells)周围添加边框? - How can I add borders around a spreadsheet range (Aspose Cells)? 我如何改进此代码以不删除空单元格,而是忽略它们? - How can I improve this code to not delete empty cells, but just ignore them? 如何覆盖数据透视表(设置单元格)上的列标签文本? - How can I override the column label text on a Pivot Table (Aspose Cells)? 将图像放在电子表格(Aspose Cells)上时,如何防止图像尺寸改变? - How can I prevent my image from changing size when placing it on a spreadsheet (Aspose Cells)? 如何将电子表格中的列宽设置为特定的像素数(Aspose Cells)? - How can I set the column width in a spreadsheet to a specific pixel count (Aspose Cells)? 如何用不同的值代替自动生成的总计值(Aspose Cells)? - How can I replace automatically-generated grand total values with different ones (Aspose Cells)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM