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. python相关问题求解决,有偿2. javascript - input输入框触发change事件后,外部元素会被选中3. python - 用__call__ 实现装饰器功能4. javascript - vue2.0中router.repalce跟router.push有什么区别,二者的应用场景是会有怎样的区别?5. javascript - prismplayer播放器全屏问题6. javascript - 在sublime中如何给.vue文件注释?7. python - 请问用cxfreeze打包的可执行程序能反编译出源码么?8. HTML5怎么访问本地文件?9. javascript - 这种上传图片预览怎么做?10. javascript - 把字符串日期转换成一般时间格式后,发现小于10的数字不会自动添加0在前面,如下