Veljean
asked on
Read Excel documents with C#
Hi Everybody
I want to read a xsl document from my C# application, i need a string concatenated for each row in the selected sheet, can give me tips to do this please?
I want to read a xsl document from my C# application, i need a string concatenated for each row in the selected sheet, can give me tips to do this please?
ASKER
There is not another way to do this without open Excel?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thanks... i will check it out ;)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Microsoft.Office.Interop.E
Now you have a new namespace: Microsoft.Office.Interop.E
Create a new application object
Excel.Application appExcel = new Excel.ApplicationClass();
Now a new excel is running in the background.
You can open new worksheets with:
Excel.Worksheets ws = appExcel.Worksheet;
ws .open().
You can find all the documentations here:
http://msdn.microsoft.com/de-de/library/microsoft.office.interop.excel%28en-us%29.aspx
VERY IMPORTANT:
These classes are COM classes, therefore you *MUST* release them before quitting (using quit() method) the excel application.
If you don't release all the object, the excel.exe will simply won't quit.
To do that you need to use:
Marshal.ReleaseComObject()
(http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.releasecomobject.aspx)
As an example,
lets say that you're using appExcel and ws that I wrote above, than you will have to:
appExcel.quit();
Marshal.ReleaseComObject(a
Marshal.ReleaseComObject(w
Good Luck!