im exporting a gridview table to Microsoft Excel using this code :
private void button5_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = Excel.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)Excel.ActiveSheet;
Excel.Visible= true;
ws.Cells[1, 1] = "VehiclePlateNumber";
ws.Cells[1, 2] = "VehicleDescription";
ws.Cells[1, 3] = "Distance";
for (int j = 2; j <= datagridview1.Rows.Count; j++)
{
for (int i = 2; i <= 3; i++)
{
ws.Cells[j, i] = datagridview1.Rows[j - 2].Cells[i - 1].Value;
}
}
its working, but the first column is showing only the header text without data, i dont know what is the problem, and i tried to do some changes to the code but i couldn't reach the solution, any help please ?