I am using RadGrid but due to pre-design excel template i am doing export to excel function using below code. It is working fine. but when i deployed it on relience server then it is not working. even not generating any error also.
code :
public
void ExcelExport(System.Data.DataTable tblExportData, string TempFilePath,string userInfo,bool headerStatus)
{
try
{
Microsoft.Office.Interop.Excel.
Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(TempFilePath,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Writing Header in Excel
if (headerStatus == true)
{
for (int i = 0; i < tblExportData.Columns.Count; i++)
{
excelApp.Cells[7, i + 1] = tblExportData.Columns[i].ColumnName;
}
}
//Writing Data in Excel
for (int i = 1; i <= tblExportData.Rows.Count; i++)
{
for (int j = 0; j < tblExportData.Columns.Count; j++)
{
string colName = tblExportData.Columns[j].ColumnName;
excelApp.Cells[i + 7, j+1] = tblExportData.Rows[i-1][colName];
}
}
//Create a worksheet object
Microsoft.Office.Interop.Excel.
Sheets sheets = excelApp.Worksheets;
//from the collection of worksheet select one worksheet
Microsoft.Office.Interop.Excel.
Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
//select the cell in the worksheet
Microsoft.Office.Interop.Excel.
Range myCell1 = (Microsoft.Office.Interop.Excel.Range)mySheet.get_Range("A6", "A6");
myCell1.Value2 = userInfo;
myCell1.Font.Color = System.Drawing.Color.Black.ToArgb();
excelApp.Visible = true;
}
catch (Exception ex)
{
}
}
since export to excel button is grid command item so i am handling postback operation using this code.
if
(e.Item is GridCommandItem)
{
GridCommandItem item = (GridCommandItem)e.Item;
ImageButton ibtn = item.FindControl("imgbtnExport") as ImageButton;
ibtn.OnClientClick =
String.Format("{0}.__doPostBack(\"{1}\",\"{2}\");return false;", RadAjaxManager1.ClientID, ibtn.UniqueID, ibtn.CommandArgument);
}
and now in exporttoexcel button click event i am calling above function.
in case of local server it's working fine in all system. but once it deployed in another server (e.g. Reliance Server) it's not working.
please help me to achieve my result.
thanks a lot in advance.
binod