您的位置:首页技术文章
文章详情页

python - pandas html格式的excel文件

【字号: 日期:2022-09-20 13:59:46浏览:38作者:猪猪

问题描述

网页上下载的excel文件,用记事本打开显示如下:python - pandas html格式的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读就可以了

标签: python
相关文章: