这是会发生什么:颜色的非连续细胞在Excel片
xlValues
被设定为Excel.Range
对象。
我曾尝试以下为好,全部给我同样的错误:
//xlValueRange = xlSheet...
.get_Range("A1:A5,A15:A25,A50:A65");
.UsedRange.Range["A1:A5,A15:A25,A50:A65"];
.Range["A1:A5,A15:A25,A50:A65"];
xlApp.ActiveWorkbook.ActiveSheet.Range["A1:A5,A15:A25,A50:A65"];
//I have also tried these alternatives with ".Select()" after the brackets and
//", Type.Missing" inside the brackets
//This works though...
xlSheet.Range["A1:A5"];
我试图重新着色特定的细胞在Excel工作表,我已经通过使用两个找到了解决办法循环,但它太慢了。通过30 000个单元格的列需要几分钟时间。
我从来没有做过这样的事情,我用this教程让我开始。
该解决方案使用布尔型数组,其单元格的颜色设置为true。 (recolored)
//using Excel = Microsoft.Office.Interop.Excel;
xlApp = new Excel.Application();
xlApp.Visible = true;
xlBook = xlApp.Workbooks.Add(Type.Missing);
xlSheet = (Excel.Worksheet)xlBook.Sheets[1];
for (int i = 1; i < columns + 1; i++)
{
for (int j = 1; j < rows + 1; j++)
{
if (recolored[j, i])
xlSheet.Cells[j+1, i+1].Interior.Color = Excel.XlRgbColor.rgbRed;
}
}
}
我想什么做的是这样的:
Excel.XlRgbColor[,] color;
//Loop to fill color with Excel.XlRgbColor.rgbRed at desired cells.
var startCell = (Excel.Range)xlSheet.Cells[1, 1];
var endCell = (Excel.Range)xlSheet.Cells[rows, columns];
var xlRange = xlSheet.Range[startCell, endCell];
xlRange.Interior.Color = color;
这一次让我在最后一行的错误,虽然;
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
我的第一个猜测将是使一个Excel.Range
对象覆盖我想有红色和使用该对象到位xlRange的,像这样的细胞:
RangeObject.Interior.Color = Excel.XlRgbColor.rgbRed;
我不知道是否可以制作一个Excel.Range
这样的空白对象,但我可以在这个上使用一些帮助。
终于开始尝试这个解决方案。对不起,迟到接受,这是最后的解决方案:) – 2016-05-16 08:11:13