Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

excel interop c#: changing row color

I am trying to change the color in Row mod 2 = 0 in a Range between B4 to F500 which it is a list of values. I want alternate the background color of entire Row.

I am executing this:

Range c1 = worksheet.Range["B4"];
Range c2 = (Range) worksheet.Range[F500];

Range range = worksheet.get_Range(c1, c2);
range.Value = arr;

var formatCell = (FormatCondition)range.Rows.FormatConditions.Add(XlFormatConditionType.xlExpression, XlFormatConditionOperator.xlEqual, "=MOD(ROW(),2) = 0");
formatCell.Interior.Color =  Color.FromArgb(243, 243, 243);

until value = arr the code it is working ok but when I want to change the color it is giving me this error:

enter image description here

THE PARAMETER IS INCORRECT

What is wrong?

could you please help me?

I don't want to make a loop because it is too slow

I am using c# and Excel 365.

question from:https://stackoverflow.com/questions/65902070/excel-interop-c-changing-row-color

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got the solution:

Workbook wkb = GetApp().Workbooks.Open(excelLocation);
wkb.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF, outputLocation);

wkb.Close();
GetApp().Quit();

The problem was ExportAsFixedFormat which wasn't recognized as instruction. I had a conflict with the libraries and I decided to delete all.

Only to work with Microsoft.Office.Interop.Excel;

and after it I had to install Microsoft.CSSharp as requeriment of interop.

now it is working


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...