python - pandas html格式的excel文件
問題描述
網(wǎng)頁上下載的excel文件,用記事本打開顯示如下:
用pandas.read_excel讀取的話,提示
XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b’<html x’
假如用excel打開再另存為excel,讀取當(dāng)然可以,但是有很多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讀就可以了
相關(guān)文章:
1. Python中使用超長的List導(dǎo)致內(nèi)存占用過大2. 實現(xiàn)bing搜索工具urlAPI提交3. python - Django有哪些成功項目?4. Python從URL中提取域名5. MySQL主鍵沖突時的更新操作和替換操作在功能上有什么差別(如圖)6. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題7. node.js - windows10下的npm全局路徑的復(fù)原或者將npm徹底刪除?8. 數(shù)據(jù)庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。9. 直接打字符不可以嗎?>和>有區(qū)別嗎10. node.js - 微信小程序websocket連接問題
