Click here to Skip to main content
14,836,641 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys, I have below code to generate excel sheet, its working fine in my local system and when im hosted in server its saying Object reference error, Can ny helpme out




C#
if (ds.Tables[0].Rows.Count > 0)
            {
                CreateExcelDoc exceldoc = new CreateExcelDoc();
                #region creates the main header

                exceldoc.createHeaders(2, 6, "NAME OF THE INST", "F1", "I1", 0, "", true, 15, "");
                exceldoc.createHeaders(3, 6, "LOCATION, LOCATION-521165,LOCATION District", "F2", "I2", 0, "", true, 10, "");

                
                   
                    exceldoc.addData(6, 6, ds.Tables[0].Rows[0]["1"].ToString(), "A" + 6 + "", "A" + 6 + "", "");
                    exceldoc.addData(6, 7, ds.Tables[0].Rows[0]["2"].ToString(), "A" + 6 + "", "A" + 6 + "", "");
                    exceldoc.addData(6, 8, ds.Tables[0].Rows[0]["3"].ToString(), "A" + 6 + "", "A" + 6 + "", "");
                    exceldoc.addData(6, 9, ds.Tables[0].Rows[0]["4"].ToString(), "A" + 6 + "", "A" + 6 + "", "");

                    exceldoc.addData(10, 6, "Name", "A" + 6 + "", "A" + 6 + "", "");
                    exceldoc.addData(10, 7, "Marks", "A" + 6 + "", "A" + 6 + "", "");
                    
                    if (ds.Tables[0].Rows.Count > 0)
                               {
                                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                   {
                                       exceldoc.addData(i + 11, 6, ds.Tables[0].Rows[i]["5"].ToString(), "A" + (i + 11), "A" + (i + 11), "");
                                       exceldoc.addData(i + 11, 7, ds.Tables[0].Rows[i]["6"].ToString(), "A" + (i + 11), "A" + (i + 11), "");
                                       

                                   }
                               }
              
                exceldoc.app.Visible = true;

                #endregion
            }
Posted
Updated 22-Apr-13 22:24pm
v2
Comments
   
Sorry, this is not a question.
—SA
arindamrudra 23-Apr-13 2:49am
   
Can you please check in your server there is proper link for CreateExcelDoc is available or not?
Shashi226 23-Apr-13 3:00am
   
where to check
AmitGajjar 23-Apr-13 4:35am
   
on which line you got object reference exception ?
Shashi226 23-Apr-13 4:37am
   
hey itz cmg on local
i think on client system with the below line im getting error

exceldoc.app.Visible = true;
AmitGajjar 23-Apr-13 4:40am
   
it means that exceldoc.app is null. add if condition before your code to check if it is null or not.
Shashi226 23-Apr-13 4:42am
   
no itz not null why because both my local and client system parameters are same
AmitGajjar 23-Apr-13 4:45am
   
i think on server you do not have excel installed. that is why you are not able to create instance of the excel object.
Shashi226 23-Apr-13 4:47am
   
no office is installed on my server
AmitGajjar 23-Apr-13 4:48am
   
you need to create logging to check exact error location and root cause.
AmitGajjar 23-Apr-13 4:50am
   
check if exceldoc is null on that line ?
Shashi226 23-Apr-13 4:56am
   
is it possible to save excel file on server after that i have to show it to the end user
can u help me out in this way
AmitGajjar 23-Apr-13 4:59am
   
You can display your data in datagrid and you can also export it into excel sheet. check http://www.c-sharpcorner.com/UploadFile/DipalChoksi/ExportASPNetDataGridToExcel11222005041447AM/ExportASPNetDataGridToExcel.aspx article.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900