Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Unable to fetch values from Excel Worksheet in vb.net



Hi

i have a serious problem while i was working in Excel.I want to fetch
columns from an excel worksheet and i need to compare it with an sql
querry fields,so i tried to open an excle worksheet first..


Unfortunately my code was throwing error like


CLSID\{00020819-0000-0000-C000-000000000046} IS NOT VALID OR NOT
REGISTERED.
But the same exe is working fine in other Pc's except mine.Then i
overcome the error with the code


Dim oldCI As System.Globalization.CultureInfo =
System.Threading.Thread.CurrentThread.CurrentCultu re
System.Threading.Thread.CurrentThread.CurrentCultu re = New
System.Globalization.CultureInfo("en-US")


after that excel sheet was opening but i cant read the rows or columns
in it
error throws like "Old format or Invalid Type Library" in the
particular statement wherever i used worksheet.methodname


Here i put the entire code


please help me


Imports System.Windows.Forms
Imports Microsoft.Office.Core
Imports Excel
Public Class Form1
Inherits System.Windows.Forms.Form
Public xlApp As New Excel.Application


Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click


Try


Dim strFileName As String
Dim intRows, intCols As Integer
Dim r, c As Integer
Dim Strquerry As String
Dim strpos As Integer
Dim strposc As String
Dim StrMid As String
'Create a dialog box to find the excel file


Dim dlg As New OpenFileDialog
dlg.Filter = "Excel Files (*.xls)|*.xls"
dlg.FilterIndex = 0
dlg.ShowDialog()
strFileName = dlg.FileName


Dim oldCI As System.Globalization.CultureInfo =
System.Threading.Thread.CurrentThread.CurrentCultu re
System.Threading.Thread.CurrentThread.CurrentCultu re = New
System.Globalization.CultureInfo("en-US")


Dim xlWB As Excel.Workbook
xlWB = xlApp.Workbooks.Open(strFileName)
TextBox1.Text = strFileName
xlWB.Application.Visible = True


System.Threading.Thread.CurrentThread.CurrentCultu re = oldCI


Dim xls As Excel.Sheets
Dim xlsheet As New Excel.Worksheet


xls = xlWB.Worksheets


xlsheet = CType(xls.Item(1), Excel.Worksheet)
xlsheet.activate()


intRows = xlsheet.UsedRange.Rows.Count
If intRows < 0 Then
intCols = xlsheet.UsedRange.Columns.Count
If intCols < 0 Then


' Scroll through all the rows and columns retrieving values.
For r = 1 To intRows
For c = 1 To intCols
Strquerry = TextBox2.Text
strpos = InStr(1, Strquerry, "(")
strposc = InStr(strpos, Strquerry, ",")
StrMid = Mid(Strquerry, strpos, CType(xlsheet.Cells(r, c),
Excel.Range).Text)
StrMid = Mid(Strquerry, strposc, CType(xlsheet.Cells(r, c),
Excel.Range).Text)
MsgBox(StrMid)
Next
Next


xlWB.Close(False)
xlApp.Quit()
xls = Nothing
xlWB = Nothing
xlApp = Nothing
End If


End If
Catch ex As Exception
MsgBox(ex.Message)
End Try


End Sub


End Class


thanks in advance
Dimple




*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to fetch the rebate from another worksheet using itemcode pol Excel Worksheet Functions 1 July 14th 09 07:27 PM
fetch values from w/sheet TUNGANA KURMA RAJU Excel Discussion (Misc queries) 0 April 2nd 09 03:43 AM
Unable to Insert Worksheet/Move and copy worksheet Excel 2003 lukerush Excel Worksheet Functions 2 September 7th 06 05:05 PM
Fetch parameters from web into Excel Jonas B Excel Programming 1 May 30th 06 11:11 PM
To fetch the values from the excel cells into the variable chetana Excel Programming 2 September 2nd 04 11:47 AM


All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"