Change MS Excel Row Colour in Excel using C# -
i creating small program allow user input data windows form. once data has been input form added excel document using oledb.
i have no problems above section , can input data no bother problem comes when try change colour of excel row.
i looking change colour of row red if row has no fill.
the code using:
excel.application application = new excel.application(); excel.workbook workbook = application.workbooks.open(@"c:\users\jhughes\desktop\screenupdate.xls"); excel.worksheet worksheet = (excel.worksheet)workbook.sheets["dailywork"]; excel.range usedrange = worksheet.usedrange; excel.range rows = usedrange.rows; try { foreach (excel.range row in rows) { if (row.cells.entirerow.interior.colorindex = 0) { row.interior.color = system.drawing.color.red; } } } catch(exception ex) { messagebox.show(ex.tostring()); }
i getting error "cannot implicitly convert type int bool" @ line "if(row.cells.entirerow....)"
i think not added saving workbook , change in if condition. somehow default colorindex coming -4142. tested able change change color
excel.application application = new excel.application(); excel.workbook workbook = application.workbooks.open(@"c:\users\mypath\desktop\colorbook.xls"); excel.worksheet worksheet = (excel.worksheet)workbook.sheets["dailywork"]; excel.range usedrange = worksheet.usedrange; excel.range rows = usedrange.rows; try { foreach (excel.range row in rows) { if (row.cells.entirerow.interior.colorindex == -4142) { row.interior.color = system.drawing.color.red; } } workbook.save(); workbook.close(); } catch (exception ex) { messagebox.show(ex.tostring()); }
Comments
Post a Comment