python - pandas html格式的excel文件
PHPz
PHPz 2017-04-18 10:19:39
0
2
794

网页上下载的excel文件,用记事本打开显示如下:

用pandas.read_excel读取的话,提示

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'<html  x'

假如用excel打开再另存为excel,读取当然可以,但是有很多excel文件这样处理就很繁琐,有没有什么方法么

VBS处理代码

Function  GetPath()
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select a folder:", OPTIONS)
If objFolder Is Nothing Then
Wscript.Quit
End If
Set objFolderItem = objFolder.Self
GetPath = objFolderItem.Path

End Function


Function SaveToExcel(src_file,dest_file)

csv_format = 1 '6另存为csv,1另存为xls

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim oExcel
Set oExcel = CreateObject("Excel.Application")

oExcel.DisplayAlerts=false


Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
oBook.Worksheets(1).Activate

oBook.SaveAs dest_file, csv_format

oBook.Close False
oExcel.Quit

End Function

Dim i : i=0
Set oFso = CreateObject("Scripting.FileSystemObject")  
Set oFolder = oFso.GetFolder(GetPath())      
Set oFiles = oFolder.Files 

For Each oFile In oFiles
If Right(oFile.Path,3)="xls" or Right(oFile.Path,4)="xlsx" Then
 
SaveToExcel oFile.Path,oFile.Path
i=i+1
End If
Next
MsgBox "总共处理了"&i&"个EXCEL文件"
Wscript.Quit
PHPz
PHPz

学习是最好的投资!

Antworte allen(2)
Ty80

用vbs打开再另存为EXCEL,再读取

巴扎黑

你这个本来就是excel格式干嘛使用文本打开,你下载后直接panda读就可以了

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!