10 Replies - 1643 Views - Last Post: 07 April 2012 - 03:08 PM Rate Topic: -----

#1 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

excel

Posted 07 April 2012 - 02:14 AM

hello all ,

please i would like to know what is the easiet way to read an excel file (xlsx) from vb.net 2010
to read some values in excel cells
please
thank you
Is This A Good Question/Topic? 0
  • +

Replies To: excel

#2 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: excel

Posted 07 April 2012 - 02:21 AM

This tutorial in written for VB6. But I don't think there would be much of a difference. I can't be sure since I haven't worked with Excel through VB.NET.

This tutorial is for VB.NET. Check it out first.
Was This Post Helpful? 1
  • +
  • -

#3 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

Re: excel

Posted 07 April 2012 - 02:42 AM

thank you for ur reply but i need something more easier. just a simple code to read excel cells
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: excel

Posted 07 April 2012 - 04:50 AM

Here's a tutorial from our tutorial's section that covers word and excel.
Was This Post Helpful? 1
  • +
  • -

#5 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

Re: excel

Posted 07 April 2012 - 01:04 PM

View PostCharlieMay, on 07 April 2012 - 04:50 AM, said:

Here's a tutorial from our tutorial's section that covers word and excel.

thank you for ur reply i dont know why cant i get a straight fwd answer:( please help me this tuturial makes it as template then uses it as this or i dont know how i want an excel file on c:\ lets say cell b,5 has the value "5" i want it displayed on a text box please help me :(
Was This Post Helpful? 0
  • +
  • -

#6 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: excel

Posted 07 April 2012 - 01:18 PM

You cannot get a straight forward answer because you can find it in the posted links.
For example, if you look carefully in the tutorial CharlieMay mentioned, you will see (my comments between the lines)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        oExcel = CType(CreateObject("Excel.Application"), Excel.Application)
	oBook = oExcel.Workbooks.Open(Application.StartupPath & "\" & TextBox5.Text & ".xlt") 'the extension is not relevant. here you can put whatever valid path you want. For example oExcel.Workbooks.Open("C:\WhateverExcelFile.xls") or C:\WhateverExcelFile.xlsx

	Try
		With oExcel
			.Visible = True ' this can dissapear
			'Add details
			.Range("E12").Value = TextBox1.Text ' here it is assigned to cell E12 the value from textbox1. If you want to display the value from cell E12 into a textbox, just switch the operators 
			.Range("E13").Value = TextBox2.Text
			.Range("E14").Value = TextBox3.Text
			.Range("E15").Value = TextBox4.Text
		End With
	Catch ex As Exception
		MsgBox("Error: " & ex.ToString, MsgBoxStyle.Critical, "Error!")
	End Try

End Sub




Don't forget to quit Excel
 objExcel.Quit()


Was This Post Helpful? 1
  • +
  • -

#7 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

Re: excel

Posted 07 April 2012 - 01:59 PM

View PostIonut, on 07 April 2012 - 01:18 PM, said:

You cannot get a straight forward answer because you can find it in the posted links.
For example, if you look carefully in the tutorial CharlieMay mentioned, you will see (my comments between the lines)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        oExcel = CType(CreateObject("Excel.Application"), Excel.Application)
	oBook = oExcel.Workbooks.Open(Application.StartupPath & "\" & TextBox5.Text & ".xlt") 'the extension is not relevant. here you can put whatever valid path you want. For example oExcel.Workbooks.Open("C:\WhateverExcelFile.xls") or C:\WhateverExcelFile.xlsx

	Try
		With oExcel
			.Visible = True ' this can dissapear
			'Add details
			.Range("E12").Value = TextBox1.Text ' here it is assigned to cell E12 the value from textbox1. If you want to display the value from cell E12 into a textbox, just switch the operators 
			.Range("E13").Value = TextBox2.Text
			.Range("E14").Value = TextBox3.Text
			.Range("E15").Value = TextBox4.Text
		End With
	Catch ex As Exception
		MsgBox("Error: " & ex.ToString, MsgBoxStyle.Critical, "Error!")
	End Try

End Sub




Don't forget to quit Excel
 objExcel.Quit()


thank you for your prompt reply
i am trying it now i am getting on ((Application.StartupPath <--- this part)
Error 1 Reference to a non-shared member requires an object reference. C:\Users\Training\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 12 39 WindowsApplication1

View Post.nethelp, on 07 April 2012 - 01:56 PM, said:

View PostIonut, on 07 April 2012 - 01:18 PM, said:

You cannot get a straight forward answer because you can find it in the posted links.
For example, if you look carefully in the tutorial CharlieMay mentioned, you will see (my comments between the lines)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        oExcel = CType(CreateObject("Excel.Application"), Excel.Application)
	oBook = oExcel.Workbooks.Open(Application.StartupPath & "\" & TextBox5.Text & ".xlt") 'the extension is not relevant. here you can put whatever valid path you want. For example oExcel.Workbooks.Open("C:\WhateverExcelFile.xls") or C:\WhateverExcelFile.xlsx

	Try
		With oExcel
			.Visible = True ' this can dissapear
			'Add details
			.Range("E12").Value = TextBox1.Text ' here it is assigned to cell E12 the value from textbox1. If you want to display the value from cell E12 into a textbox, just switch the operators 
			.Range("E13").Value = TextBox2.Text
			.Range("E14").Value = TextBox3.Text
			.Range("E15").Value = TextBox4.Text
		End With
	Catch ex As Exception
		MsgBox("Error: " & ex.ToString, MsgBoxStyle.Critical, "Error!")
	End Try

End Sub




Don't forget to quit Excel
 objExcel.Quit()


thank you for your prompt reply
i am trying it now i am getting on ((Application.StartupPath <--- this part)
Error 1 Reference to a non-shared member requires an object reference. C:\Users\Training\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 12 39 WindowsApplication1

plus one things i am getting on --> Range("E12").Value
Error 3 'Range' is a type and cannot be used as an expression. C:\Users\Training\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 17 33 WindowsApplication1
Was This Post Helpful? 0
  • +
  • -

#8 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: excel

Posted 07 April 2012 - 02:01 PM

You have to declare oExcel as Excel.Application and oBook as Excel.Workbook. Also, go back to the tutorial and read the References part
Was This Post Helpful? 1
  • +
  • -

#9 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

Re: excel

Posted 07 April 2012 - 02:13 PM

View PostIonut, on 07 April 2012 - 02:01 PM, said:

You have to declare oExcel as Excel.Application and oBook as Excel.Workbook. Also, go back to the tutorial and read the References part

i already did
Dim oExcel As New Excel.Application
Dim obook As New Excel.Workbook

i fixed the before post now the range is giving me error as i told you before

plus one things i am getting on --> Range("E12").Value
Error 3 'Range' is a type and cannot be used as an expression. C:\Users\Training\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb 17 33 WindowsApplication1

maybe coz i have vb 2010 and excel 2010 its all throwing errors on this one too


obook As New Excel.Workbook

Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
Was This Post Helpful? 0
  • +
  • -

#10 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: excel

Posted 07 April 2012 - 02:50 PM

change Range with cells(5, 11).value
Was This Post Helpful? 1
  • +
  • -

#11 .nethelp  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 31-March 12

Re: excel

Posted 07 April 2012 - 03:08 PM

View PostIonut, on 07 April 2012 - 02:50 PM, said:

change Range with cells(5, 11).value

thank you again for ur prompt replies urgreat but i am sorry its all throwing erros all over the place i dimmed everything with imports and i added reference its ok i am gonna sleep now maybe by luck someday i will find an easy code that works for me thank you again so much
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1