|
-
May 30th, 2006, 05:30 AM
#1
Thread Starter
Lively Member
[RESOLVED] reading data from an excel file (in vb.net)
Hi,
I'm trying to read data from a close excel file in vb.net 2003.
I can't find any specific functions to read the number of colums and rows there are, loop them, and read the values.
I tried looking in the object browser and on msdn, but I can't find anything useful.
Can this be done using Automation or do I have to use a select statement using databases?
Any help is appreciated.
-
May 30th, 2006, 06:11 AM
#2
Re: reading data from an excel file (in vb.net)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 30th, 2006, 06:53 AM
#3
Thread Starter
Lively Member
Re: reading data from an excel file (in vb.net)
Writing data in a file works, but I don't see any methods to read data.
The cells property returns a comObject instead of a string, is it any useful?
I can't view the contents of it.
-
May 30th, 2006, 07:03 AM
#4
Re: reading data from an excel file (in vb.net)
VB Code:
Messagebox.Show(oSht.Cells(1, 1))
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 30th, 2006, 07:40 AM
#5
Thread Starter
Lively Member
Re: reading data from an excel file (in vb.net)
 Originally Posted by RobDog888
VB Code:
Messagebox.Show(oSht.Cells(1, 1))

I tried that, of course, didn't work. 
"Cast from type 'Range' to type 'String' is not valid."
Weird thing, when I use msgbox instead of messagebox.show, I get:
"Additional information: Argument 'Prompt' cannot be converted to type 'String'."
-
May 30th, 2006, 07:46 AM
#6
Re: reading data from an excel file (in vb.net)
That because your using Option Strict On, which is a good thing.
VB Code:
'Try...
Messagebox.Show(CType(oSht.Cells(1, 1), String))
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 30th, 2006, 08:36 AM
#7
Thread Starter
Lively Member
Re: reading data from an excel file (in vb.net)
Same result.
-
Jun 1st, 2006, 01:53 AM
#8
Thread Starter
Lively Member
Re: reading data from an excel file (in vb.net)
Are you sure it should work like that?
-
Jun 1st, 2006, 02:21 AM
#9
Re: reading data from an excel file (in vb.net)
Should be as Range as I was free typing in the Reply box.
VB Code:
Dim oRange As Excel.Range = CType(oSht.Cells(1, 1), Excel.Range)
MessageBox.Show(oRange.Value2.ToString)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|