tags:

views:

29

answers:

0

Hi,

I am using windowsforms Application and i exported my datatable to excel file successfully...

now i want to format that excel sheet like column Name should be bold and display that datatable values as a table format and give background color to Columns and give different color to data rows...... How shall i format like this?

plz anyone help me for this problem.....

Thanks In Advance

Here is my code for export datatable toexcel:

        private void btnExportexcel_Click(object sender, EventArgs e)
        {
        oxl = new Excel.Application();
        oxl.Visible = true;
        oxl.DisplayAlerts = false;


        wbook = oxl.Workbooks.Add(Missing.Value);

        wsheet = (Excel.Worksheet)wbook.ActiveSheet;
        wsheet.Name = "Customers";

           DataTable dt = clsobj.convert_datagrid_orderlist_to_datatable(dvgorderlist);

        int rowCount = 1;
        foreach (DataRow dr in dt.Rows)
        {
            rowCount += 1;
            for (int i = 1; i < dt.Columns.Count + 1; i++)
            {
                // Add the header the first time through
                if (rowCount == 2)
                {
                    wsheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
                }
                wsheet.Cells[rowCount, i] = dr[i - 1].ToString();
            }
        }

        range = wsheet.get_Range(wsheet.Cells[1, 1],
                      wsheet.Cells[rowCount, dt.Columns.Count]);
        range.EntireColumn.AutoFit();


        wsheet = null;
        range = null;

}

now how can i change the colors of columns text,and rows background,and display as a table format.....