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讀就可以了
相關文章:
