資源簡介
用python實現的一個小工具, 將KML的坐標提取出來轉換為Excel格式的文件,基于xlwings實現的Excel操作, 附源碼

代碼片段和文件信息
from?xml.dom.minidom?import?parse
import?os
import?time
import?xlwings?as?xw
import?sys
def?get_path():
????print(‘wwwww‘)
????print(os.path.dirname(os.path.realpath(sys.executable)))
????path?=?os.path.dirname(os.path.realpath(sys.executable))
????#path?=?“D:\workspace\python\KMLtoExcel“
????if?not?os.path.isdir(path):
????????print(“路徑不正確“)
????????return?get_path()
????return?path
def?parse_xml(path?file):
????old_path?=?path
????path?=?os.path.join(path?file)
????print(‘正在解析:?‘?path)
????doc?=?parse(path)
????root?=?doc.documentElement
????coordinates?=?root.getElementsByTagName(“coordinates“)
????xylist=[]
????for?coordinate?in?coordinates:
????????old_data?=?coordinate.childNodes[0].data
????????new_data?=?“?“.join([old.replace(““?“?“)?for?old?in?old_data.split(“0“)])
????????print(new_data)
????????xylist.append([new_data.split(‘?‘)[1]new_data.split(‘?‘)[2]])
????#?添加一個新的工作薄
????app?=?xw.App(visible=True?add_book=False)
????wb?=?app.books.add()
????sht?=?wb.sheets[0]
????print(xylist)
????sht.range(‘a1‘).value?=?xylist
????#?保存文件
????wb.save(‘./‘+os.path.basename(file)+‘.xlsx‘)
????wb.close()
????app.quit()
file_path?=?get_path()
files?=?os.listdir(file_path)
for?f?in?files:
????if?os.path.splitext(f)[-1]?==?“.kml“:
????????parse_xml(file_path?f)
????time.sleep(0.5)?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???10165058??2020-09-14?11:05??坐標解析工具\KMLToExcel.exe
?????文件???????1401??2020-09-22?08:59??坐標解析工具\KMLToExcel.py
?????文件?????????86??2020-09-22?08:58??坐標解析工具\使用說明.txt
?????目錄??????????0??2020-09-22?09:00??坐標解析工具
-----------?---------??----------?-----??----
?????????????10166545????????????????????4
- 上一篇:邏輯回歸訓練測試的完整代碼和數據集
- 下一篇:偷偷復制U盤文件,偷老師課件神器
評論
共有 條評論