Warning: include_once(/home/favoledo/robertozanardo.com/wp-content/sunrise.php): Failed to open stream: No such file or directory in /home/favoledo/robertozanardo.com/wp-includes/ms-settings.php on line 52

Warning: include_once(): Failed opening '/home/favoledo/robertozanardo.com/wp-content/sunrise.php' for inclusion (include_path='.:/opt/alt/php83/usr/share/pear:/opt/alt/php83/usr/share/php:/usr/share/pear:/usr/share/php') in /home/favoledo/robertozanardo.com/wp-includes/ms-settings.php on line 52
Estrarre immagini da excel - Odoo e Soluzioni Open Source

Estrarre immagini da excel

Nel caso di un file Excel con all’interno delle immagini (no path, no url) semplicemente ‘incollate’ dentro, come nel caso, ad esempio, di un listino prezzi, un catalogo o altro possiamo utilizzare un codice pyton per farci creare una cartella contenente le immagini e rinominate secondo nostre specifiche.

Ho preso spunto da un estratto di codice (inizialmente non funzionante) presente su stackoverflow (qui il link al thread).

Il codice accetta come parametri il file excel e crea una directory temporanea per le elaborazioni, alla fine elimina la cartella temporanea e lascia un cartella di destinazione contenente le immagini estratte.

Lo riporto qui per comodità (funzionante):

import pathlib
import shutil

def extract_xls_images(path):

    if type(path) is str:
        path = pathlib.Path(path)
    if path.suffix != '.xlsx':
        raise ValueError('path must be an xlsx file')

    source_file = path.name
    name = path.name.replace(''.join(path.suffixes), '').replace(' ', '') # name of excel file without suffixes
    
    temp_file = pathlib.Path(name).parent / 'temp.xlsx' # temp xlsx
    temp_zip = temp_file.with_suffix('.zip') # temp zip

    shutil.copyfile(source_file, temp_file)

    temp_file.rename(str(temp_zip))

    extract_dir =  temp_file.parent / 'temp'
    extract_dir.mkdir(exist_ok=True)
    destination_dir =  temp_file.parent / 'dest'
    destination_dir.mkdir(exist_ok=True)

    shutil.unpack_archive(temp_zip, extract_dir) # unzip xlsx zip file
    paths_img = sorted((extract_dir / 'xl' / 'media').glob('*.png')) # find images
    move_paths = {path: destination_dir / (name + f'-{str(n)}.png') for n, path in enumerate(paths_img)} # create move path dict 
    new_paths = [shutil.move(old, new) for old, new in move_paths.items()] # move / rename image files

    shutil.rmtree(extract_dir) # delete temp folder
    temp_zip.unlink() # delete temp file

    return new_paths

extract_xls_images('listino_agricow.xlsx')

 

 

Lascia un commento

kolaybet giriş
kolaybet
betgaranti
Kolaybet
kolaybet
bettilt
grandpashabet
Kolaybet
grandpashabet
kolaybet
betpark
betgaranti
betpark
betgaranti
kolaybet
kolaybet
betpark
betpark
betgaranti
betgaranti 2026
hellocasino
betgaranti 2026
betgaranti
betgaranti 2026
Kolaybet 2026
Kolaybet
Kolaybet Mobil Giriş
Kolaybet Güncel Giriş
bettilt
vdcasino
betpark
betpark
betgaranti
betgaranti 2026
betgaranti güncel giriş
betgaranti mobil giriş
kolaybet
Kolaybet
Kolaybet Giriş
Kolaybet Güncel Giriş
Kolaybet 2026
Kolaybet
Kolaybet Güncel Giriş
Kolaybet 2026
Kolaybet Güncel Giriş
Kolaybet Giriş
grandpashabet
betpark
betpark
bettilt
kolaybet
kolaybet giriş
sahabet
sahabet
onwin
onwin
sahabet
sahabet
onwin
onwin
grandpashabet
kolaybet
betpark
betgaranti
kolaybet güncel giriş
kolaybet giriş
kolaybet
kolaybet resmi giriş
kolaybet mobil giriş
Kolaybet 2026
Kolaybet Giriş Güncel
Kolaybet Güncel Giriş
Kolaybet Giriş
kolaybet
kolaybet güncel giriş
Kolaybet
Kolaybet Güncel Giriş
Kolaybet Telegram
Kolaybet Resmi Giriş
Kolaybet Giriş
Kolaybet 2026
betpark
betpark
holiganbet