 |
|
 |
Hi,
I am trying to read excel 2003 xls file in visual studio 2008 by using the code published in this website "Loading and reading the Microsoft Excel file contents using C#" By _duk_
The file test.xls is exist in the path.
But am getting the below error.
System.Runtime.InteropServices.COMException was unhandled HelpLink="C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm" Message="'c:\\test.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted." Source="Microsoft Office Excel" ErrorCode=-2146827284 StackTrace: at Microsoft.Office.Interop.Excel.Workbooks.Open(String 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 WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\VSTAF\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 32 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at WindowsFormsApplication1.Program.Main() in C:\VSTAF\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
can anyone tell me the solution
Thanks in advance
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi vishwa. Its bit late for your solution but it may help you.
you need to add a dll (Microsoft.Office.Interop.Excel.dll)as reference
then use this as namespace-
using Excel = Microsoft.Office.Interop.Excel;
Hope this'll relief your headache.
Cheers. Raj.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
One suggestion: Move the row: rowIndex = 2+index; to the end of the while loop, or else there will be exception thrown.
Hope I can help U
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
if i read the excel file its contains a date format the c# is considered as a text or decimal value so how to Read the date formated column in excel file
muruga
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi , I have written a code to read Excel 2003 . But my user has Office 97 . It throws an exception at
// code for creating an object of Excel.ApplicationClass() //create a workBook object ...
excelObj.Workbooks.Open ( StrFilename,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,false,Missing.Value,Missing.Value,Missing.Value);
Can you provide any solution for this ?
Regards, Tara
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Dear fellows
I have problem about which i donot from where i can get help.
What is Working:
I have made a ASP.NET (C#) application that is reading Data from Excel (cell b cell). That is working fine and i can check it in browser.
Problem:
Now using this code i made a web part in C# and i want to show it in SharPoint Server 2007 site page. Now that is not working , thats mean not showing the web part on the page.
And when i comment the excel ralated code in web part coding and check it at SharePoint server, web part works.
I donot know what to do, Please Help
Piece of code is:
Excel.Application app = new Excel.Application();
Excel.Workbook wbook = null;
Excel.Worksheet wsheet = null;
Excel.Range range = null;
app.Visible = false;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
string filepath = inputFile1.Value.ToString();
if (filepath != "")
{
wbook = app.Workbooks.Open(filepath, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
string currentSheet = "Sheet1";
wsheet = (Excel.Worksheet)wbook.Worksheets.get_Item(currentSheet);
range = wsheet.get_Range("B6", "H20");
System.Array myvalues = (System.Array)range.Cells.Value2;
valueArray = ConvertToStringArray(myvalues);
if (app != null)
{
app.Workbooks.Close();
app.Quit();
}
app = null;
wsheet = null;
range = null;
Asif khan
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi there,
I've created a web using visual studio and c#. I can use your code no problem when i'm running it off my local host. However once it's hosted i'm getting the following error:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
Source Error:
Line 54: { Line 55: //sets up an excel class called excelApp Line 56: Excel.Application excelApp = new Excel.ApplicationClass(); Line 57: Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); Line 58:
Is it at all possible to use this code online??
Thanks,
Adrian.
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
 |
Essentially what it is says (I think) is that the Excel Com libs are not available online... or at least, not available in the environment you are hosted in.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I want to import data from excel 2007 file. I am getting "COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005." error while creating object of Application class. But note that the Microsoft office is not installed on my machine. I want to import excel file without installing the micrsoft excel?
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
I tried this sample and when i opened my "Task Manager" I saw that there are many instances of Excel. Any reason why?
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
Yes, the author failed to extensively test his application
Use the following to ensure a complete closure of the process.
Please not this is not the complete solution. If the program exits with an exception before this point, instances may not be closed as your workbook will be unavailable.
usage: shutDownExcel(workSheet,workBook,app);
#region Close Excel // from microsofts MSDN private void NAR(object o) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(o); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } finally { o = null; } } //not from the msdn private void shutDownExcel(Excel.Worksheet workSheet, Excel.Workbook workBook, Excel.ApplicationClass app) { NAR(workSheet); workBook.Close(false, false, Type.Missing); NAR(workBook); app.Quit(); NAR(app); }
#endregion
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi, The performance using the code is very poor, you can try is using just 5000 rows with say 10 columns and try to copy/write that, will take more than 5 min. even on 3GHz Machine .
thanks  anil (pl) india
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Um, DUH! You can't possibly expect excel to perform like SQLServer with that kind of data. Sheesh.
void (*)()
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Yes, unfortunately I've noticed this too. Not much you can do, it's the way the old COM objects are set up. You have to get each column individually. If only there was a way to get a bunch of columns at once.
One way I've found to get data from an xls a bit faster is to write an excel macro to write the data into a CSV file, then read the CSV file. You can use the Excel libraries mentioned in this post to execute the macro (see http://support.microsoft.com/?kbid=306683)
John
|
| Sign In·View Thread·PermaLink | 1.75/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
field1 = ((Excel.Range)workSheet.Cells[rowIndex, ColumnIndex1]).Text.ToString(); Use this code
Murugupandiyan.k
Murugupandiyan.k
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Firstly I'm having to use Excel 9.0 rather than Excel 10.0 Not sure if thats whats causing this problem. Anyone know where/how to update this without having to go get a new copy of Office/Excel.
Anyway if thats not the problem the code doesn't exit properly it always throw the an exception when it runs.
I've got two rows in the test.xls and it reads them properly, but when it's done with that it throws and expection and then dies.
After the While loop, which is supposed to terminate when it runs out of stuff, I added 'Console.WriteLine("Foo");' It never makes it up to this point. It just wrote out the two rows of the excel file and then throws the exception (So its not a case, which I suspected, that it runs out of things to do and thus jumps from the Try method to Catch method.
I tried modifying the loop to a do-while, but that didn't give any better results.
I suspect that its a case that its not reading the empty cells as null but something else, and something that it can't type-cast and thus it throws an exception.
Anyway for the purposes of completeness follows is a copy of the command window output after running the program. Thanks for any feedback or bug-fixes anyone posts here.
Nutter
D:\My Documents\Programming Projects\ConsoleApplication1\bin\Debug>consoleapplic ation1 Name : Number or text,23 Name : Peter Pan,Pan Object reference not set to an instance of an object.
Unemployed Ex-Student Bum - Will work for coffee.
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
Change the loop to this :
{ string firstName = ((Excel.Range)workSheet.Cells[rowIndex,colIndex1]).Value2.ToString(); string lastName = ((Excel.Range)workSheet.Cells[rowIndex,colIndex2]).Value2.ToString(); Console.WriteLine("Name : {0},{1} ",firstName,lastName); rowIndex = 2+index; //remove the first line and insert it here index++; }
This is how I make the loop exit properly.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
 |
Ah thanks for that.
Now I'll just have to try and remember what it was I needed it for Still thanks all the same, it still might come in handy for something I'm working on.
Unemployed Ex-Student Bum - Will work for coffee.
|
| Sign In·View Thread·PermaLink | 2.00/5 (3 votes) |
|
|
|
 |