ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Piloting excel with vb.net (https://www.excelbanter.com/excel-programming/366817-piloting-excel-vbulletin-net.html)

VoTiger

Piloting excel with vb.net
 
Hi,
i would like to know how i can get the type of an excel field. I have
tried to use the vartype method but it's always returning "object"
which refers to the field and not to the type of data which is in the
field...

Hope someone will be able to help me.

Regards


VoTiger

Piloting excel with vb.net
 
Can someone help me please ? I am really stuck and i don't know how to
get out of this...


Tim Williams

Piloting excel with vb.net
 
Check the type of the *contents*, not the cell itself (which will always be "object")

--
Tim Williams
Palo Alto, CA


"VoTiger" wrote in message oups.com...
Can someone help me please ? I am really stuck and i don't know how to
get out of this...




Chip Pearson

Piloting excel with vb.net
 
Make sure you pass the Value property of the cell, not just a
reference to the cell itself.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"VoTiger" wrote in message
oups.com...
Hi,
i would like to know how i can get the type of an excel field.
I have
tried to use the vartype method but it's always returning
"object"
which refers to the field and not to the type of data which is
in the
field...

Hope someone will be able to help me.

Regards




VoTiger

Piloting excel with vb.net
 
Thank you, all of you, for helping me to get out of this. For those who
want to do the same thing here is the code i have made to get the type
of the excel data field :

Public Function GetDataFromXL() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
Dim plage As Excel.Range
Dim col As Integer
Dim row As Integer

plage = XLApplication.Selection()
col = plage.Columns.Count()
row = plage.Rows.Count

'Dim ii As String = XLworksheet.Type.GetTypeCode.ToString

For i As Integer = 0 To col - 1
dt.Columns.Add("Col" & i)
Next

For i As Integer = 0 To row - 1
dr = dt.NewRow
For j As Integer = 0 To col - 1
dr(j) = plage.Value2(i + 1, j + 1)
Debug.WriteLine(VarType(plage(i + 1, j + 1).Value()))
Debug.WriteLine(plage.Value2(i + 1, j + 1))
Next
dt.Rows.Add(dr)
Next
Return dt
End Function

Hope this will help someone else.

Best Regards,



All times are GMT +1. The time now is 08:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com