python - pandas html格式的excel文件
問題描述
網頁上下載的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 = 0Const OPTIONS = 0Set objShell = CreateObject('Shell.Application')Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, 'Select a folder:', OPTIONS)If objFolder Is Nothing ThenWscript.QuitEnd IfSet objFolderItem = objFolder.SelfGetPath = objFolderItem.PathEnd FunctionFunction SaveToExcel(src_file,dest_file)csv_format = 1 ’6另存為csv,1另存為xlsSet objFSO = CreateObject('Scripting.FileSystemObject')Dim oExcelSet oExcel = CreateObject('Excel.Application')oExcel.DisplayAlerts=falseDim oBookSet oBook = oExcel.Workbooks.Open(src_file)oBook.Worksheets(1).ActivateoBook.SaveAs dest_file, csv_formatoBook.Close FalseoExcel.QuitEnd FunctionDim i : i=0Set oFso = CreateObject('Scripting.FileSystemObject') Set oFolder = oFso.GetFolder(GetPath()) Set oFiles = oFolder.Files For Each oFile In oFilesIf Right(oFile.Path,3)='xls' or Right(oFile.Path,4)='xlsx' Then SaveToExcel oFile.Path,oFile.Pathi=i+1End IfNextMsgBox '總共處理了'&i&'個EXCEL文件'Wscript.Quit
問題解答
回答1:用vbs打開再另存為EXCEL,再讀取
回答2:你這個本來就是excel格式干嘛使用文本打開,你下載后直接panda讀就可以了
相關文章:
1. 輸入地址報以下截圖錯誤,怎么辦?2. angular.js - angularJs ngRoute怎么在路由傳遞空字符串及用ng-switch取得3. javascript - ie11以下單擊打開不了file,雙擊可以。求解?4. vim里的高亮javascript的javascript.vim 已經放到syntax里了,但是不行。5. html5 - video ios不能播放怎么辦?6. android - xml的drawable作背景,是否會產生錯誤7. python - pip install出現下面圖中的報錯 什么原因?8. node.js - node中MYSQL的異步問題9. javascript - 求助一個關于indexedDB的問題10. 我何時應該在Java中使用JFrame.add(component)和JFrame.getContentPane()。add(component)
