整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

怎么把Excel表格转换成HTML格式?Excel转HTML

 Excel表格可是几乎每天都能用的到,不是自己编辑发给同事,就是别人发来的,而且有时候不仅是对Excel表格进行编辑,还需要进行格式转换,最常见的就是Excel转PDF。几天你那小编给大家讲一个不常见的【Excel转HTML】,有需要的小伙伴赶紧看过来吧,只需要一个PDF转换器即可。

  第一步,打开已经安装好的极强PDF转换器,点击页面左侧的【其他文档格式转换】,看见了,有一个【文件转HTML】选项,没错点它。然后点击【添加文件】,把需要进行转换的Excel表格文件加进来。 


  第二步,在页面下方勾选【自定义】选项,先把文件存储为设置好,然后点击【开始转换】。 


  第三步,稍等片刻,转换完成之后会有一个如下图所示的提示框,点击【确定】即可。 


  第四步,下面就预览一下Excel转HTML的成果如何,如下图所示还不错吧。 


  极强PDF转换器不仅是PDF转换器,还可以实现其他文件的格式转换,还等什么,赶紧来本站免费下载吧。

自动化##Python#

遇到的需求是这样的,需要频繁将htm类型的数据转为Excel表格,这是一个重复性的工作,极大程度上浪费时间和人力,所以我找到了一个解决方案。用Python开发一个桌面的自动化的小工具,虽然实现起来简单,但是真心好用。今天特意写篇文章分享给大家。希望你从获得的是这个思路,里面的功能你可以换成你工作中重复的工作。

一、背景介绍

首先 htm 数据是如下这样的,一个网址。内容在网页中,这里需要写爬虫,获取网页中的信息,自动保存到excel ,并输出excel格式的文件。

1、需求结果

2、解析htm里的内容,并保存到excel

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())

二、设计窗口

创建桌面窗口,这里使用tkinter,它是Python 自带的gui库,安装后即可使用。

1、安装命令:

pip install tkinter

2、利用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()

三、打包exe

本功能打包成exe的好处是不需要将代码部署到服务器,直接将打包好的exe发给对方,就能直接使用。对于这种小而轻的功能非常友好。

1、安装命令:

pip install pyinstaller

2、 打开DOS窗口并切换到demo.py文件的目录,注意路径不要有中文:





在当前目录下,会生成两个文件夹:build和dist。dist里面就是所有可执行exe文件,发送快捷方式到桌面,点击demo.exe就能运行了。

3、pyinstaller指令的常见可选参数:

-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>>

来源网络,侵权联系删除

私信我或关注微信号:狮范儿,回复:学习,获取免费学习资源包。