This is a migrated thread and some comments may be shown as answers.

[Solved] Export to excel not working

1 Answer 153 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Binod
Top achievements
Rank 1
Binod asked on 15 Jun 2009, 02:40 PM
Hi Telerik
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 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Jun 2009, 02:51 PM
Hello Binod,

Please visit the following links:
How to: Use COM Interop to Create an Excel Spreadsheet (C# Programming Guide)
Installing and Using the Office 2003 Primary Interop Assemblies

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Binod
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or