Excel表格可是几乎每天都能用的到,不是自己编辑发给同事,就是别人发来的,而且有时候不仅是对Excel表格进行编辑,还需要进行格式转换,最常见的就是Excel转PDF。几天你那小编给大家讲一个不常见的【Excel转HTML】,有需要的小伙伴赶紧看过来吧,只需要一个PDF转换器即可。
第一步,打开已经安装好的极强PDF转换器,点击页面左侧的【其他文档格式转换】,看见了,有一个【文件转HTML】选项,没错点它。然后点击【添加文件】,把需要进行转换的Excel表格文件加进来。
第二步,在页面下方勾选【自定义】选项,先把文件存储为设置好,然后点击【开始转换】。
第三步,稍等片刻,转换完成之后会有一个如下图所示的提示框,点击【确定】即可。
第四步,下面就预览一下Excel转HTML的成果如何,如下图所示还不错吧。
极强PDF转换器不仅是PDF转换器,还可以实现其他文件的格式转换,还等什么,赶紧来本站免费下载吧。
自动化##Python#
遇到的需求是这样的,需要频繁将htm类型的数据转为Excel表格,这是一个重复性的工作,极大程度上浪费时间和人力,所以我找到了一个解决方案。用Python开发一个桌面的自动化的小工具,虽然实现起来简单,但是真心好用。今天特意写篇文章分享给大家。希望你从获得的是这个思路,里面的功能你可以换成你工作中重复的工作。
from bs4 import BeautifulSoup
import pandas as pd
class htmToExcel(object):
def __init__(self, file_name, file_path):
self.file_name = file_name
self.file_path = file_path
def htm_to_excel(self):
print(self.file_path)
soup = BeautifulSoup(open(self.file_path), features='html.parser')
table = soup.find("table")
tr_list = table.find_all("tr")
th = tr_list.pop(0)
title = th.find_all("th")
lis = []
for tr in tr_list:
data = {}
td = tr.find_all("td")
for i in range(len(td)):
data[title[i].text] = td[i].text
lis.append(data)
df = pd.DataFrame(lis)
df.to_excel('{}.xlsx'.format(str(self.file_name).split('.')[0]), index=False)
return '转换成功!'
if __name__ == '__main__':
file_name = input("请输入文件名字:")
path = 'C:/Users/cherich/Desktop/' + file_name
pross = htmToExcel(file_name, path)
print(pross.htm_to_excel())
pip install tkinter
from tkinter import Tk, Entry, Button, mainloop
import tkinter.filedialog
import htm_to_excel
from tkinter import messagebox
def Upload():
try:
selectFileName = tkinter.filedialog.askopenfilename(title='选择文件')
pross = htm_to_excel.htmToExcel(str(selectFileName).split('/')[-1], selectFileName)
pross.htm_to_excel()
messagebox.showinfo('Info', '转换成功!')
root.destroy()
except Exception as e:
print(e)
messagebox.showinfo('Info', '转换失败!')
root = Tk()
root.title('HTM转Excel小工具')
root.geometry('+500+300')
e1 = Entry(root, width=50)
e1.grid(row=0, column=0)
btn1 = Button(root, text=' 上传 ', command=Upload).grid(row=1, column=0, pady=5)
mainloop()
pip install pyinstaller
在当前目录下,会生成两个文件夹:build和dist。dist里面就是所有可执行exe文件,发送快捷方式到桌面,点击demo.exe就能运行了。
-i 给应用程序添加图标
-F 指定打包后只生成一个exe格式的文件
-D –onedir 创建一个目录,包含exe文件,但会依赖很多文件(默认选项)
-c –console, –nowindowed 使用控制台,无界面(默认)
-w –windowed, –noconsole 使用窗口,无控制台
-p 添加搜索路径
如果生成exe之后,你发现你的程序异常的慢,请检查你的导包代码,尽量不要出现 from ··· import * ,否则每次启动程序,都会导入大量函数占用大量时间,亲测有效。
今天的文章写到这里,如果你觉得对你有帮助,欢迎点赞哦~
信我或关注微信号:狮范儿,回复:学习,获取免费学习资源包。
Excel文件转成html页面代码
main类:启动类
package com.test; import trans.toHtml; public class testToHtml { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub toHtml th=new toHtml(); // System.out.println(System.getProperty("java.library.path")); //-Djava.library.path=D:\jar\jacob_1.9 th.excelToHtml("d:/excel/运维门户通讯录.xlsx", "d:/test.html"); } }
代码:
package trans; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class toHtml { int WORD_HTML = 8; int WORD_TXT = 7; int EXCEL_HTML = 44; /** * WORDתHTML * @param docfile WORD ļ ȫ· * @param htmlfile ת HTML · */ public void wordToHtml(String docfile, String htmlfile) { ActiveXComponent app = new ActiveXComponent("Word.Application"); // word try { app.setProperty("Visible", new Variant(false)); Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch(); Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]); Variant f = new Variant(false); Dispatch.call(doc, "Close", f); } catch (Exception e) { e.printStackTrace(); } finally { app.invoke("Quit", new Variant[] {}); } } /** * EXCELתHTML * @param xlsfile EXCEL ļ ȫ· * @param htmlfile ת HTML · */ public void excelToHtml(String xlsfile, String htmlfile) { ActiveXComponent app = new ActiveXComponent("Excel.Application"); // excel try { app.setProperty("Visible", new Variant(false)); Dispatch excels = app.getProperty("Workbooks").toDispatch(); Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch(); Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(EXCEL_HTML) }, new int[1]); Variant f = new Variant(false); Dispatch.call(excel, "Close", f); } catch (Exception e) { e.printStackTrace(); } finally { app.invoke("Quit", new Variant[] {}); } } /** * /ɾ ļ * @param folderPath ļ ȫ· * @param htmlfile ת HTML · */ public void delFolder(String folderPath) { try { delAllFile(folderPath); //ɾ String filePath = folderPath; filePath = filePath.toString(); java.io.File myFilePath = new java.io.File(filePath); myFilePath.delete(); //ɾ ļ } catch (Exception e) {e.printStackTrace();} } /** * /ɾ ļ ļ * @param path ļ ȫ· */ public boolean delAllFile(String path) { boolean flag = false; File file = new File(path); if (!file.exists()) { return flag; } if (!file.isDirectory()) { return flag; } String[] tempList = file.list(); File temp = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + tempList[i]); } else { temp = new File(path + File.separator + tempList[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delAllFile(path + "/" + tempList[i]);// ɾ ļ ļ delFolder(path + "/" + tempList[i]);// ɾ ļ flag = true; } } return flag; } } 需要的jar包 <<jacob.jar>> <<toHtml.java>> <<testToHtml.java>>
来源网络,侵权联系删除
私信我或关注微信号:狮范儿,回复:学习,获取免费学习资源包。
*请认真填写需求信息,我们会在24小时内与您取得联系。