Excel sheet accessing(edit/update) in asp.net
Excel Version Dll 11.o
name space :
using Microsoft.Office.Interop;
using Office;
#region Code for Access the excelsheet
public void GetExcel_Method()
{
Microsoft.Office.Interop.Excel.Application oExcel = null;
Microsoft.Office.Interop.Excel.Workbook oBook = null;
Microsoft.Office.Interop.Excel.Worksheet oSheet = null;
Microsoft.Office.Interop.Excel.Range oRng;
object missing = Type.Missing;
try
{
oExcel = new Microsoft.Office.Interop.Excel.Application();
oBook = oExcel.Workbooks.Open(@"C:\\inetpub\\wwwroot\\Test Excel\\NMDS.xls",missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
oExcel.Visible = true;
oBook.Activate();
oSheet = (Microsoft.Office.Interop.Excel.Worksheet) oBook.Worksheets["Employee"];
oSheet.get_Range("C5","C5").set_Value(Type.Missing ,"India Software Solutions");
oSheet.get_Range("C9","C9").set_Value(Type.Missing ,"Hemant");
oSheet.SaveAs("C:\\Documents and Settings\\Administrator\\Desktop\\NMDS1.xls",Micro soft.Office.Interop.Excel.XlFileFormat.xlExcel7,Ty pe.Missing,Type.Missing,Type.Missing,Type.Missing, Type.Missing,Type.Missing,Type.Missing,Type.Missin g);
oExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oExcel);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oBook);
System.GC.Collect();
}
catch (Exception ex)
{
Response.Write("Error accessing Excel: " + ex.ToString());
}
}
#endregion
i am getting this error =="Object is not set to instant"
"Error accessing Excel: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Office.Interop.Excel.Workbooks.Open(Stri ng Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) at London.NMDS_Profile.Test_XML.GetExcel_Method() in d:\sfc_new\nmds_profile\test_xml.aspx.cs:line 131 "
SDS
|