Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
dynamically rows colour changing into using excel.range in C#
Posted
Comments
Sinisa Hajnal 19-Nov-14 2:12am    
Describe your requirement in more details. And show us what you have done before asking the question.
Nishant.Chauhan80 19-Nov-14 2:15am    
i want to row color changing one by one using for loop in my Export Excel File my code following :


Microsoft.Office.Interop.Excel.Application excelApplication = new Microsoft.Office.Interop.Excel.Application();


Microsoft.Office.Interop.Excel.Workbook workbook = excelApplication.Workbooks.Open(filename,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);






foreach (Excel.Worksheet wrkst1 in workbook.Worksheets)
{

Excel.Range usedrange = wrkst1.UsedRange;
usedrange.Columns.AutoFit();
wrkst1.Tab.Color = 279;



//Excel.Range formatRange;
//formatRange = wrkst1.get_Range("b1", "k6");
//formatRange.Interior.Color = System.Drawing.
//ColorTranslator.ToOle(System.Drawing.Color.YellowGreen);


//formatRange = wrkst1.get_Range("b7", "k20");
//formatRange.Interior.Color = System.Drawing.
//ColorTranslator.ToOle(System.Drawing.Color.Yellow);

Excel.Range rng = (Excel.Range)wrkst1.Cells[1, 1];
Excel.Range row = rng.EntireRow;
row.Insert(Excel.XlInsertShiftDirection.xlShiftDown, false);

//wrkst1.get_Range("E1", "F1").Merge(false);
Excel.Range chartRange;
chartRange = wrkst1.get_Range("E1");
chartRange.FormulaR1C1 = objModule.Title;
chartRange.HorizontalAlignment = 3;
chartRange.VerticalAlignment = 3;
//chartRange.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
chartRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Green);
chartRange.Font.Size = 20;

//ColorConverter cc = new ColorConverter();
//wrkst1.Cells[1, 10].Interior.Color = ColorTranslator.ToOle((Color)cc.ConvertFromString("#F1DCDB"));


}


excelApplication.DisplayAlerts = false;
((Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]).Delete();
workbook.Close(true, filename, null);
excelApplication.DisplayAlerts = true;


}

catch (Exception ex)
{
}


//return File(filename, "application/msexcel");
return File(filename, "application/x-excel", DateTime.Now.Ticks + "_Report.xlsx");
}
Sinisa Hajnal 19-Nov-14 2:26am    
Now take your comment and add it to the question proper. Use Improve question link. Thank you.

Oh, and describe which part of the code doesn't work, you have plenty of it commented out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900