Hi ,
I am exporting a datatable to an excel sheet successfully... In that excel sheet i have to display the columns(customerid,Productname,referenceno) of the data table except the last column.... now how can i display the data table in excel without display the last column(referenceno)...
anyone tell me the solution of this problem.. Thanks in Advance..
here is my code for export datatable to excel:
System.Data.DataTable dt = clsobj.convert_datagrid_orderlist_to_datatable(dvgorderlist, txtreferenceno);
oxl = new Excel.Application();
oxl.Visible = true;
oxl.DisplayAlerts = false;
wbook = oxl.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
oxl.ActiveCell.set_Item(2, 4, "Alfa Aesar");
wsheet = (Excel.Worksheet)wbook.ActiveSheet;
wsheet.Name = "Customers";
Excel.Range range = wsheet.get_Range("A6", "H6");
wsheet.get_Range("A6", "H6").Font.Name = "Times new Roman";
wsheet.get_Range("A6", "H6").Font.Size = 12;
wsheet.get_Range("A6", "H6").Interior.Color = ConvertColour(Color.SkyBlue);
oxl.ActiveWindow.DisplayGridlines = false;
int rowCount = 5;
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 == 7)
{
wsheet.Cells[6, i] = dt.Columns[i - 1].ColumnName;
}
wsheet.Cells[rowCount, i] = dr[i - 1].ToString();
Excel.Range cellRange = (Range)wsheet.Cells[rowCount, i];
//cellRange.Interior.Color = 200;
//cellRange.Interior.Color = ConvertColour(Color.LightBlue);
cellRange.Cells.Borders.LineStyle = BorderStyle.FixedSingle;
}
}
cells = wsheet.get_Range(wsheet.Cells[2, 2],
wsheet.Cells[rowCount, dt.Columns.Count]);
cells.EntireColumn.AutoFit();
wsheet = null;
cells = null;