解析 wxPython 和 Pandas 实现的 XLSX 分析器和网页打开器

在本文中,我们将分析一个使用 wxPython 和 Pandas 库编写的 Python 应用程序,名为 “XLSX Analyzer and Web Opener”。该应用程序的核心功能是:从 Excel 文件中读取数据并显示在网格中,此外,还允许用户使用 Google Chrome 批量打开 Excel 文件中的 URL 列表。
C:\pythoncode\new\analysisxlsx.py

全部代码

import wx
import wx.grid
import pandas as pd
import subprocess
import os

CHROME_PATH = r"C:\Program Files\Google\Chrome\Application\chrome.exe"

class XlsxAnalyzerFrame(wx.Frame):
    def __init__(self):
        super().__init__(parent=None, title='XLSX Analyzer and Web Opener', size=(1200, 800))
        panel = wx.Panel(self)

        main_sizer = wx.BoxSizer(wx.VERTICAL)

        self.file_picker = wx.FilePickerCtrl(panel, wildcard="Excel files (*.xlsx)|*.xlsx")
        self.file_picker.Bind(wx.EVT_FILEPICKER_CHANGED, self.on_file_selected)
        main_sizer.Add(self.file_picker, 0, wx.ALL | wx.EXPAND, 10)

        self.grid = wx.grid.Grid(panel)
        main_sizer.Add(self.grid, 1, wx.ALL | wx.EXPAND, 10)

        open_button = wx.Button(panel, label='Open URLs in Chrome')
        open_button.Bind(wx.EVT_BUTTON, self.on_open_urls)
        main_sizer.Add(open_button, 0, wx.ALL | wx.CENTER, 10)

        panel.SetSizer(main_sizer)
        self.Layout()
        self.Show()

        self.grid_created = False

    def on_file_selected(self, event):
        file_path = self.file_picker.GetPath()
        if file_path:
            try:
                df = pd.read_excel(file_path, sheet_name='sheet1')
                expected_columns = [
                    "blog-list-box href", "course-img src", "blog-list-box-top", 
                    "blog-list-content", "article-type", "view-time-box", "view-num", 
                    "give-like-num", "comment-num", "comment-num 2", "btn-edit-article href"
                ]
                if not all(col in df.columns for col in expected_columns):
                    raise ValueError("Excel file does not contain all expected columns")
                self.update_grid(df)
            except Exception as e:
                wx.MessageBox(f'Error reading file: {
     
     str(e)}', 'Error', wx.OK | wx.ICON_ERROR)

    def update_grid(self, df
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值