Results 1 to 10 of 10

Thread: Excel reader

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Excel reader

    Is there a way I can get some ExcelReader class? I don't want to use ADO.NET. Thanks in advance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Excel reader

    Unless you want to read an XLS file in binary form and decipher it you'll either have to use Office Automation or ADO.NET.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel reader

    There is an Excel Viewer Utility but just for viewing the xls file without having to have Excel installed.

    If thats not acceptable then automate Excel. What do you want to do with it?
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Excel reader

    I really love to see something like:

    Code:
    public void Test3() 
    		{
    			ExcelReader e = new ExcelReader("Some.xls");
    			e.WorkSheet = "WorksheetName";
    			ExcelRow r = e.First();
    			while (r != null) 
    			{
    				Console.WriteLine(r["A"].ToString());
    				Console.WriteLine(r["B"].ToString());
    				Console.WriteLine(r["C"].ToString());
    				r.Next();
    			}
    		}

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel reader

    Fine!

    Got tired of formatting the code to look nice so I just attached it for you.

    It creates an Excel.Application object and on the form it has a browse button to open a workbook. Then the left button will write a value to cell A1 and save the workbook. Then when you close the form, Excel closes properly.

    Whew!!!


    Ps, sorry about naming the buttons with relevant names and stuff.

    Edit: 28,000 POSTS! Meow!
    Attached Files Attached Files
    Last edited by RobDog888; May 25th, 2006 at 03:13 AM. Reason: updated attachment
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Excel reader

    Hehehe. Ok thanks but I know a little about this stuff. Anyway, I just create my ExcelReader class encapsulating the ones you posted plus Iterator. Thanks again!

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel reader

    Np, I just noticed I forgot to change a line of code to open the workbook in the textbox instead of my test hard coded file.

    VB Code:
    1. Excel.Workbook oWB = (Excel.Workbook)moApp.Workbooks.Open([b]@textBox1.Text[/b],objMissing,objMissing,...
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Excel reader

    hi RobDog888. I have to create a program to do some excel manipulation and your program helped me a lot that you attached.

    However there's 2 lines in your code:

    using Excel = Microsoft.Office.Interop.Excel;
    ///Add a reference to MS Excel xx.0 Object Library

    Where could I get this reference / Dll? I hope this is not a silly question, if it was forgive me, its the first tiem I'm doing this.

    This is since i'm getting the error that :

    The type or namespace name 'Interop' does not exist in the class or namespace 'Microsoft.Office' (are you missing an assembly reference?)


    Jennifer.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Excel reader

    Quote Originally Posted by JenniferBabe
    hi RobDog888. I have to create a program to do some excel manipulation and your program helped me a lot that you attached.

    However there's 2 lines in your code:

    using Excel = Microsoft.Office.Interop.Excel;
    ///Add a reference to MS Excel xx.0 Object Library

    Where could I get this reference / Dll? I hope this is not a silly question, if it was forgive me, its the first tiem I'm doing this.

    This is since i'm getting the error that :

    The type or namespace name 'Interop' does not exist in the class or namespace 'Microsoft.Office' (are you missing an assembly reference?)


    Jennifer.
    You add a reference to the appropriate Office application's object library from the COM tab.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Excel reader

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width