How to set height, width, background color, font color of excel using Microsoft.Office.Interop.Excel library in C#

Last Reply on Oct 22, 2016 03:45 AM By santosh86

Posted on Oct 22, 2016 01:33 AM

 

 
xlWorkSheetToExport.Cells[3, 3] = "Karishma Marine Solutions Pvt Ltd.";

 

Posted on Oct 22, 2016 03:05 AM Modified on on Oct 22, 2016 03:06 AM

Hi santosh86,

Refer the below code.

// Assigning value to cell.
xlWorkSheetToExport.Cells[3, 3] = "Karishma Marine Solutions Pvt Ltd.";
// Get the range from excel.
Excel.Range range = xlAppToExport.ActiveCell.Worksheet.Cells[3, 3] as Excel.Range;
// Auto resize cell width and height.
//range.Columns.AutoFit();
// Set background color.
range.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
// Set font color.
range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
// Set Row Height.
range.EntireRow.RowHeight = 50.0;
// Set Column Width.
range.ColumnWidth = 50.0;