Reading Worksheet names from excel files
Paul Witmond
Hello,I need to read some data from an Excel sheet. To do this we need to know the sheetname.
In VB we can use
Workbooks.Open ("c:excelfile.xls")
Worksheets(1).Activate
MsgBox Worksheets(1).Name
How can I do this in Customize ?
:bang:
Paul
Manuel Marhold
Hi Paul,there are more than one way to do this.
You can use the Excel-Application-Object, but to do this, Excel has to be installed on the computer.
You can also connect to the Excel-file via ODBC (Office-12-Acces-driver preferred). This need to be installed as well, but is only an ODBC-Driver and for free.
Paul Witmond
Hi Manuel,Do you have an example of using the application object ?
Regards,
Paul
Manuel Marhold
Hi Paul,just a few seconds with google:
http://forums.devx.com/showthread.php?t=155202
Paul Witmond
Hi Manuel,Coresuite doen not like "Imports Excel = Microsoft.Office.Interop.Excel"
Any suggestions ??
Thanks,
Paul
Manuel Marhold
Hi Paul,this is because the Refernce to the dll is missing.
Try to use [DllImport()] or something like this.
I don't know exacly how but there is the ability to load dll at runtime and use them.
Paul Witmond
Hi Manuel,I have tried to zip and rename the .net DLL but no result
DLLIMPORT is also not working.
I think we are missing something.
When using standard VB it's very easy.......
Manuel Marhold
Hi Paul,when using VBA in Excel it is easy, yes, because when you are in excel, you already have the Excel-Application.
If you want to use the Excel-Appliaction in an VisualStudio-Application, you have to set a reference to Microsoft.Office.Interop.Excel. By using the objects in that reference, you can just work as easy as in Excel itself.
But you must have the reference or use API/ActiveX (like in vb script you can create an Application Object of Excel).
I think the easiest way in your case will be the OleDb-Connection with the http://www.microsoft.com/downloads/details.aspx?familyid=7554f536-8c28-4598-9b72-ef94e038c891&displaylang=en ("Provider=Microsoft.ACE.OLEDB.12.0;[...]") and then use Conn.GetSchema("TABLES").Rows (which is a System.Data.DataRowCollection) to get the ifnromation about the Tables (= sheets)
0
Please sign in to leave a comment.
Comments
0 comments