|
-
Oct 11th, 2006, 04:30 AM
#1
Thread Starter
Hyperactive Member
read from an excel
I wanna read the values of each cell in the excel thru my c# code
im using the following line of code but its not working
pla tell me whats wrong here and suggest me the correct solution thnx
Code:
excel = new Microsoft.Office.Interop.Excel.Application();
excelworkbook = (Microsoft.Office.Interop.Excel._Workbook)(excel.Workbooks.Add("C:\\A.xls");
excelworksheet = (Microsoft.Office.Interop.Excel._Worksheet)excelworkbook.Sheets[1];
for (int i = 1; i <= excelworksheet.UsedRange.Columns.Count; i++)
tdbExcel.Columns[i - 1].Text = excelworksheet.UsedRange.get_Item(1, i).ToString();
-
Oct 11th, 2006, 04:34 AM
#2
Re: read from an excel
What is the error(s) or specify more then "not working". 
Perhaps my C# Excel FAQ may help?
http://vbforums.com/showthread.php?t=406639
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 
-
Oct 11th, 2006, 04:52 AM
#3
Thread Starter
Hyperactive Member
Re: read from an excel
{"Object reference not set to an instance of an object."}
this is the error that m getting
-
Oct 11th, 2006, 04:55 AM
#4
Re: read from an excel
On what line of code?
"excel" is a reserved word as I would suggest not using it and rename it to something else.
Are you using the "using" imports at the top of your class file?
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 
-
Oct 11th, 2006, 05:03 AM
#5
Thread Starter
Hyperactive Member
Re: read from an excel
i m getting this error at following line
Code:
tdbExcel.Columns[i - 1].Text = excelworksheet.UsedRange.get_Item(1, i).ToString();
no Excel is a reserve word while excel is not and secondly m not using "Using" imports for Excel as i have added refrence of excel
that is working fine for writing excel but to read it ... its causng problem
-
Oct 11th, 2006, 01:31 PM
#6
Re: read from an excel
Then it could be that your tdbExcel is not created?
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
|