?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小時內與您取得聯系。