PDA

View Full Version : تفسیر اطلاعات مجود در یک فایل غیر متنی؟



vb.civil
شنبه 11 شهریور 1396, 19:19 عصر
سام دوستان
آیا میشه اطلاعات موجود در یک فایل غیر متنی رو تفسیر کرد؟

مثلا یه فایل xls (اکسل) داریم میخوام بدون حضور یا حتی نصب بودن اکسل روی سیستم از محتویات این فایل با خبر بشم
مثلا کلا چند شیت داره و . . .

www.pc3enter.tk
سه شنبه 14 شهریور 1396, 22:50 عصر
بیا ۲ تا کد مختلفه
Dim ExcelObj AsObject
Dim ExcelBook AsObject
Dim ExcelSheet AsObject
Dim i AsInteger

Set ExcelObj = CreateObject("Excel.Application")
Set ExcelSheet = CreateObject("Excel.Sheet")

ExcelObj.WorkBooks.Open App.Path &"\ExcelFile.xls"

Set ExcelBook = ExcelObj.WorkBooks(1)
Set ExcelSheet = ExcelBook.WorkSheets(1)

Dim l As ListItem
lvwList.ListItems.Clear
With ExcelSheet
i =1
DoUntil.cells(i,1)&""=""
Set l = lvwList.ListItems.Add(,,.cells(i,1))
l.SubItems(1)=.cells(i,2)
l.SubItems(2)=.cells(i,3)
l.SubItems(3)=.cells(i,4)
i = i +1
Loop

EndWith

ExcelObj.WorkBooks.Close

Set ExcelSheet =Nothing
Set ExcelBook =Nothing
Set ExcelObj =Nothing

و کد بعدی =======================

ISAMs to do this and it even works on machines where Excel is not installed!
Dim SheetName AsString
Dim RS As ADODB.Recordset
Dim LI As ListItem
Dim I AsInteger

'Look up 1st Worksheet (or just hardcode its Name).
'
'Notes:
' o Can use Excel 8.0 or Excel 5.0 to read most Excel 7.0/97
' Workbooks, but there is no IISAM specifically for Excel 7.0.
' o Use HDR=Yes if your Worksheet has a header row.
With CreateObject("ADOX.Catalog")
.ActiveConnection ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" _
& App.Path &"\sample.xls';" _
&"Extended Properties='Excel 5.0;HDR=No'"
SheetName =.Tables(0).Name
Set RS =New ADODB.Recordset
Set RS.ActiveConnection =.ActiveConnection
EndWith
'The "Table" name can be a range too, e.g. [Sheet1$A1C7]
With RS
.Open "["& SheetName &"]", _
, _
adOpenForwardOnly, _
adLockReadOnly, _
adCmdTable
ListView.ListItems.Clear
ListView.View = lvwReport
For I =0To.Fields.Count -1
ListView.ColumnHeaders.Add ,,.Fields(I).Name
Next
DoUntil.EOF
Set LI = ListView.ListItems.Add(,,CStr(.Fields(0).Value))
For I =1To.Fields.Count -1
LI.SubItems(I)=CStr(.Fields(I).Value)
Next
.MoveNext
Loop
.Close
EndWith



منبع http://www.vbforums.com/showthread.php?382404-How-to-read-xls-file-using-vb


https://blogs.msdn.microsoft.com/rahulso/2006/12/15/open-excel-file-with-vb6-and-read-the-content/


میگم تاحالا روی دکمه تشکر کلیک کردی؟؟؟؟