First we should add the Excel object library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
Create application object
Microsoft.Office.Interop.Excel.Application obj = new Microsoft.Office.Interop.Excel.Application();
Create object for workbook
Microsoft.Office.Interop.Excel.Workbook book;
Visibility should be true to view the Excel application
obj.Visible = true;
Create worksheet
Microsoft.Office.Interop.Excel.Worksheet hi = new Microsoft.Office.Interop.Excel.Worksheet();
Adding workbook to excel application
book = obj.Workbooks.Add(1);
hi = (Microsoft.Office.Interop.Excel.Worksheet)book.Sheets[1];
create a range object which will be used later
Microsoft.Office.Interop.Excel.Range range;
Get the current worksheet in worksheet object shee
Microsoft.Office.Interop.Excel.Worksheet shee =(Microsoft.Office.Interop.Excel.Worksheet)obj.ActiveSheet;
shee.Name = "hi";
Set some cell value
shee.Cells[1, 1] = "hello";
shee.Cells[2, 2] = "hi";
shee.Cells[3, 3] = "Welcome";
Here is the main picture
Here i am selecting rows 1 to 3 to format.
For that
1.Select the range of rows 1 to 3 to range object
range = shee.Rows.get_Range("1:3","1:3");
2.Select the range object ,wthis will select the region of rows 1 to 3
range.Select();
3.format the region properties
range.Font.Bold = true;
range.Font.Italic = true;
4.Save the book
book.Save();
}
}
}