email-excel-transfer

Pobieranie załączników z maila przez IMAP i wypełnianie plików Excel przez PowerShell. Użyj gdy użytkownik prosi o pobranie plików z email i wstawienie wartości do arkusza kalkulacyjnego.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "email-excel-transfer" with this command: npx skills add tomasz-pedzierski-infinity/email-excel-transfer

Email → Excel Transfer

Kompletny workflow: pobranie załączników z maila WP → odczyt danych → wypełnienie pliku Excel.

1. Pobranie załączników z maila (IMAP)

import imaplib, ssl, os, base64, time
import email

m = imaplib.IMAP4_SSL('imap.wp.pl', 993, ssl_context=ssl.create_default_context())
m.login('USER_EMAIL', 'USER_APP_PASSWORD')
m.select('INBOX')
time.sleep(0.5)
_, messages = m.search(None, 'FROM "adres@wp.pl" SUBJECT "fraza"')
ids = messages[0].split()
uid = ids[-1]  # najnowszy
_, msg_data = m.fetch(uid, '(RFC822)')
msg = email.message_from_bytes(msg_data[0][1])

os.makedirs('/tmp/mail_attachments', exist_ok=True)
for part in msg.walk():
    if part.get_content_disposition() == 'attachment':
        filename = part.get_filename()
        data = part.get_payload(decode=True)
        if data and 'xlsx' in filename:
            if '=?utf-8?b?' in filename:
                fname = base64.b64decode(filename.split('?')[3]).decode('utf-8')
            else:
                fname = filename
            with open(f'/tmp/mail_attachments/{fname}', 'wb') as f:
                f.write(data)
m.logout()

2. Odczyt danych z plików xlsx

Pliki xlsx to pliki ZIP. Odczyt bez zewnętrznych bibliotek:

import zipfile, re

def read_xlsx(path):
    with zipfile.ZipFile(path) as z:
        with z.open('xl/worksheets/sheet1.xml') as f:
            content = f.read().decode('utf-8')
        with z.open('xl/sharedStrings.xml') as f:
            ss = f.read().decode('utf-8')
    strings = re.findall(r'<t[^>]*>([^<]+)</t>', ss)
    cells = re.findall(r'<c r="([A-Z]+\d+)"([^>]*)>(.*?)</c>', content, re.DOTALL)
    data = {}
    for cell_ref, attrs, cell_content in cells:
        v = re.search(r'<v>([^<]+)</v>', cell_content)
        if v:
            val = v.group(1)
            if 't="s"' in attrs:
                idx = int(val)
                val = strings[idx] if idx < len(strings) else val
            data[cell_ref] = val
    return data

3. Wypełnianie pliku Excel (PowerShell + COM)

Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false
$wb = $excel.Workbooks.Open("C:\sciezka\do\pliku.xlsx")
$ws = $wb.ActiveSheet

# Wstawianie wartości (row, col) - Excel kolumny: B=2, C=3, D=4, E=5, F=6, G=7, H=8
$ws.Cells.Item(6,5).Value2 = 2450000  # E6
$ws.Cells.Item(6,6).Value2 = 2380000  # F6
$ws.Cells.Item(6,7).Value2 = 2520000  # G6
$ws.Cells.Item(6,8).Value2 = 7350000  # H6

$wb.Save()
$wb.Close($false)
$excel.Quit()

4. Przesyłanie plików na Windows (MCP bridge)

MCP bridge: http://172.17.0.1:3001/mcp (dostępne tylko z VM Linux)

Małe pliki (<200KB):

import base64, json

with open('/tmp/plik.xlsx', 'rb') as f:
    b64 = base64.b64encode(f.read()).decode()

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
        "name": "shell_ps",
        "arguments": {
            "cmd": f'[IO.File]::WriteAllBytes("C:\\sciezka\\plik.xlsx", [Convert]::FromBase64String("{b64}"))'
        }
    }
}

Duże pliki — etapami:

  1. fs_write → zapisz base64 do TEMP
  2. shell_ps[IO.File]::WriteAllBytes odczytuje z TEMP

Dane logowania (do uzupełnienia przez użytkownika)

  • Email: USER_EMAIL (np. pentom6@wp.pl)
  • Hasło aplikacji: USER_APP_PASSWORD
  • IMAP: imap.wp.pl:993

Szablony PowerShell

Wstawianie wielu wartości:

$ws.Cells.Item(row, col).Value2 = value
# Row 6-20 = wiersze danych, Kolumny E(5), F(6), G(7), H(8)

Pełny workflow (odczyt → modyfikacja → zapis):

Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false
$wb = $excel.Workbooks.Open("C:\sciezka\wejsciowa.xlsx")
$ws = $wb.ActiveSheet

# Wstaw wartości
$ws.Cells.Item(6,5).Value2 = 2450000
# ... więcej komórek

$wb.SaveAs("C:\sciezka\wyjsciowa.xlsx", 51)  # 51 = xlsx
$wb.Close($false)
$excel.Quit()

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

Email Triage Pro

Intelligently categorize, prioritize, and draft replies for emails. Fetches emails via web_fetch (Gmail web) or browser, no OAuth required. AI-powered classi...

Registry SourceRecently Updated
1740Profile unavailable
Automation

成交加速器 / Deal Closer

成交加速器 — 智能CRM助手,邮件信号提取、销售漏斗分析、AI跟进邮件起草、自学习销售智能、CRM知识图谱、IMAP/SMTP原生邮件

Registry SourceRecently Updated
1520Profile unavailable
Automation

SZZG007 Product Promotion

自动提取商品图片,生成高质量HTML推广邮件模版,支持素材库管理及邮件发送的一体化工具。

Registry SourceRecently Updated
2390Profile unavailable
Automation

WSL-PowerShell Controller

Control Windows PowerShell from WSL by executing commands and scripts on the Windows host using mounted Windows executables.

Registry SourceRecently Updated
4060Profile unavailable