Unable To Create Excel Sheet At Runtime In my Application.
-
Hi All, I am developing a web application. In that I have a web page that imports the data from EXCEL SHEET To Database. While doing this I have set some validation over the EXCEL Data. If the data is incorrect i need to write it in a new excel file which is created at run time. I have written the code to create new excel file with some data. But While Creating The Excel File I am Getting an error which i am unable to solve. So, Please Help me to solve my problem. I am using VS 2008 with c#. The Error is : Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space. • To make more memory available, close workbooks or programs you no longer need. • To free disk space, delete files you no longer need from the disk you are saving to. The Code I have Written is :
Excel.Application WRExcel = null;
Excel.Workbooks WRwbs = null;Excel.\_Workbook WRwb = null; Excel.Sheets WRss = null; Excel.\_Worksheet WRws = null; object objOpt = System.Reflection.Missing.Value; if (System.IO.File.Exists("C:\\\\Excel1.xls")) { //Delete The Existing Excel Sheet System.IO.File.Delete("C:\\\\Excel1.xls"); } //create Excel spreadsheet WRExcel = new Excel.Application(); WRwb = WRExcel.Workbooks.Add(objOpt); // **My Error Occurs Here** WRss = (Excel.Sheets)WRwb.Worksheets; WRws = (Excel.\_Worksheet)(WRss.get\_Item(1)); //create Excel column headings WRws.Cells\[1, 1\] = "Part Number."; WRws.Cells\[1, 2\] = "Kit Part."; WRws.Cells\[1, 3\] = "Description"; WRws.Cells\[1, 4\] = "Reason For Reject"; WRws.Cells\[2, 1\] = RowNo.Trim(); WRws.Cells\[2, 2\] = ColumnNo.Trim(); WRws.Cells\[2, 3\] = ErrorMsg.Trim(); WRws.Cells\[2, 4\] = Filename; //save workbook WRwb.SaveAs("C:\\\\Excel1.xls", objOpt, objOpt, objOpt, objOpt, Opt, Excel.XlSaveAsAccessMode.xlNoChange, objOpt, objOpt, objOpt, objOpt, objOpt); //close workbook WRwbs.Close();
Please Help me to Solve My Problem. Thanks & Regards Sanket Patil
.
-
Hi All, I am developing a web application. In that I have a web page that imports the data from EXCEL SHEET To Database. While doing this I have set some validation over the EXCEL Data. If the data is incorrect i need to write it in a new excel file which is created at run time. I have written the code to create new excel file with some data. But While Creating The Excel File I am Getting an error which i am unable to solve. So, Please Help me to solve my problem. I am using VS 2008 with c#. The Error is : Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space. • To make more memory available, close workbooks or programs you no longer need. • To free disk space, delete files you no longer need from the disk you are saving to. The Code I have Written is :
Excel.Application WRExcel = null;
Excel.Workbooks WRwbs = null;Excel.\_Workbook WRwb = null; Excel.Sheets WRss = null; Excel.\_Worksheet WRws = null; object objOpt = System.Reflection.Missing.Value; if (System.IO.File.Exists("C:\\\\Excel1.xls")) { //Delete The Existing Excel Sheet System.IO.File.Delete("C:\\\\Excel1.xls"); } //create Excel spreadsheet WRExcel = new Excel.Application(); WRwb = WRExcel.Workbooks.Add(objOpt); // **My Error Occurs Here** WRss = (Excel.Sheets)WRwb.Worksheets; WRws = (Excel.\_Worksheet)(WRss.get\_Item(1)); //create Excel column headings WRws.Cells\[1, 1\] = "Part Number."; WRws.Cells\[1, 2\] = "Kit Part."; WRws.Cells\[1, 3\] = "Description"; WRws.Cells\[1, 4\] = "Reason For Reject"; WRws.Cells\[2, 1\] = RowNo.Trim(); WRws.Cells\[2, 2\] = ColumnNo.Trim(); WRws.Cells\[2, 3\] = ErrorMsg.Trim(); WRws.Cells\[2, 4\] = Filename; //save workbook WRwb.SaveAs("C:\\\\Excel1.xls", objOpt, objOpt, objOpt, objOpt, Opt, Excel.XlSaveAsAccessMode.xlNoChange, objOpt, objOpt, objOpt, objOpt, objOpt); //close workbook WRwbs.Close();
Please Help me to Solve My Problem. Thanks & Regards Sanket Patil
.
http://forums.asp.net/t/1038105.aspx/1[^] Creating a formatted MS-Excel sheet using ASP[^] You can have a look on these.