Aggiornato il 17 Marzo 2022 alle 16:28 • Tempo di lettura: 1 minuti • Autore: Michele Sabatini
In questo periodo sto sviluppando un CMS custom (per ottimizzare performance e codice) e per gestire alcuni dati è emersa la necessità di dover analizzare dei file .xlsx di grandi dimensioni.
Visto che sto implementando questo CMS su diversi progetti, stare a programmare funzioni sempre nuove è una procedura abbastanza lunga per me, soprattutto in PHP (normalmente utilizzo un solo linguaggio di programmazione per facilitare lo sviluppo/manutenzione anche ai miei collaboratori).
Ho deciso, quindi, di trasformare il tutto in un JSON tramite un semplicissimo script in Python.
Installiamo la libreria Pandas:
pip install pandas
Successivamente andiamo a sviluppare il codice:
import pandas
prendi_excel= pandas.read_excel('file_excel.xlsx', sheet_name='nome_foglio_da_analizzare')
json = prendi_excel.to_json(orient='records')
f = open("output.json", "a")
f.write(json)
f.close()
In questo modo, con delle semplicissime istruzioni, sarai in grado di trasformare un file da .xlsx a .json in pochissimi secondi.
Basterà un foreach ed il gioco è fatto.
Una piccola chicca DEV che potrebbe aiutare molti SEO (e non solo).
Buona SEO,
Michele
Pagine Utili
Informazioni
© Copyright 2022 MicheleSabatini.it · Tutti i diritti riservati · Sviluppato da Sabatini Michele con UIKit e YooTheme PRO - Progetti
Cookie | Durata | Descrizione |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Lascia un commento