'customer_details.xls' cannot be accessed. The file may be corrupted, location on a server that is not responsing, or read-only. <blockquote class="FQ"><div class="FQA">Quote:</div>
protected void btnExort_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = false; Microsoft.Office.Interop.Excel.Workbook workbook = app.Workbooks.Add(1); Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1]; Microsoft.Office.Interop.Excel.Workbook objSheet = null; Microsoft.Office.Interop.Excel._Workbook objBook = null; for (int gridRow = 0; gridRow < gridView.Rows.Count; gridRow++) { GridViewRow row = gridView.Rows[gridRow]; string name = ((Label)row.FindControl("Label1")).ToString(); worksheet.Cells[gridRow + 3, 3] = ((Label)row.FindControl("Label1")).Text; worksheet.Cells[gridRow + 3, 2] = ((Label)row.FindControl("Label2")).Text; worksheet.Cells[gridRow + 3, 4] = ((Label)row.FindControl("Label3")).Text; worksheet.Cells[gridRow + 3, 5] = ((Label)row.FindControl("Label4")).Text; worksheet.Cells[gridRow + 3, 6] = ((Label)row.FindControl("Label7")).Text; worksheet.Cells[gridRow + 3, 7] = ((Label)row.FindControl("Label8")).Text; } worksheet.Cells[2, 2] = "Customer Name"; worksheet.Cells[2, 3] = "Customer ID"; worksheet.Cells[2, 4] = "Customer Display Name"; worksheet.Cells[2, 5] = "Customer Email"; worksheet.Cells[2, 6] = "Service ID"; worksheet.Cells[2, 7] = "Service Name"; //excel.Range cells = worksheet.Cells["B2", "D2"]; DateTime currentTime; currentTime = DateTime.Now; string fileName = "customer_details.xls"; //+currentTime; try { app.SaveWorkspace("D:\\ExcelWork\\ExportToExcel\\" + fileName); app.Workbooks.Close(); } catch (Exception ex) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)