Microsoft® Conversione formato Excel tramite Python

Importa ed esporta file Excel come formati di fogli di calcolo, Web, immagini e layout fisso

 

Python La libreria Excel accelera i processi di programmazione e conversione dei fogli di calcolo supportando i formati più diffusi tra cui XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, ODS Permette anche di esportare file Excel in PDF, XPS, HTML, MHTML, Plain Formati di testo e immagini popolari come TIFF, JPG, PNG, BMP e SVG.

Converti Excel in XLSX, ODS, SXC e FODS

L’interconversione del formato del foglio di calcolo richiede solo il caricamento di un foglio di calcolo con un’istanza di Cartella di lavoro e salvare nuovamente nel formato desiderato selezionando il valore appropriato da Salva formato enumerazione.

Python Codice per Conversione Formato File Excel
// load the template file
workbook = Workbook("Book1.xls")
  
// save as XLSX, ODS, SXC & FODS formats
workbook.save("output.xlsx", SaveFormat.XLSX);
workbook.save("output.ods", SaveFormat.ODS);
workbook.save("output.sxc", SaveFormat.SXC);
workbook.save("output.fods", SaveFormat.FODS);
 

Converti Excel in PDF, XPS, HTML e MD

Sono disponibili classi specializzate per controllare il processo di conversione per formati di output specifici come PdfSaveOptions per esportare file Excel come PDF, XpsSaveOptions per la conversione da Excel a XPS, HtmlSaveOptions per rendere Excel come HTML e MarkdownSaveOptions per la conversione da Excel a Markdown.

Python Codice per formati Excel fino a PDF e Web
// load template Excel file from disc
book = Workbook("template.xlsx")

// save Excel in PDF_A_1_B format
pdfOptions = PdfSaveOptions()
pdfOptions.setCompliance(PdfCompliance.PDF_A_1_B)
book.save("output.pdf", pdfOptions);

// save Excel in XPS with 1 page per worksheet
xpsOptions = XpsSaveOptions()
xpsOptions.setOnePagePerSheet(True)
book.save("output.xps", xpsOptions);

// save Excel in HTML with images as Base64
htmlOptions = HtmlSaveOptions()
htmlOptions.setExportImagesAsBase64(True)
book.save("output.html", htmlOptions);

// save Excel in Markdown (MD) while retaining cell formatting
mdOptions = MarkdownSaveOptions()
mdOptions.setFormatStrategy(CellValueFormatStrategy.CELL_STYLE)
book.save("output.md", mdOptions);
 

Converti JSON in Excel ed Excel in JSON

Gli sviluppatori Python possono caricare e convertire facilmente i file JSON in Excel in poche righe di codice. Allo stesso modo, i dati Excel possono essere esportati nei dati JSON.

Python Codice per la conversione da JSON a Excel
//Load your source json file
workbook = Workbook("Data.json")
//save file to xlsx format
workbook.save("output.xlsx")
Python Codice per Excel in JSON Conversione
//Load your source xlsx file
workbook = Workbook("input.xlsx")
//save file to json format
workbook.save("Data.json")
 

Converti fogli di lavoro Excel in JPG, BMP, PNG e GIF

Ogni foglio di lavoro di un file Excel può essere convertito in diversi formati di immagine, call OpzioniImmagineOrStampa .setImageFormat per impostare il formato dell’immagine.

Python Codice per conversione Excel in immagine
// load template spreadsheet
workbook = Workbook("template.xlsx")
// create & set an instance of ImageOrPrintOptions
options = ImageOrPrintOptions()
// set output image format
options.setImageFormat(ImageFormat.getPng())
// create SheetRender for first worksheet in the collection
sheet = workbook.getWorksheets().get(0)
sr = SheetRender(sheet, options)
// render worksheet to image
sr.toImage(0, "output.jpg")
 

Converti Excel in Word e PowerPoint

È possibile caricare qualsiasi foglio di calcolo e convertirlo nei file Word DOCX e PowerPoint PPTX durante l’utilizzo DocxSaveOptions & PptxSaveOptions classi come illustrato di seguito.

Codice Python per la conversione da Excel a Word e PowerPoint
// load the template file
workbook = Workbook("template.xlsx")

// save spreadsheet as DOCX
docxOptions = DocxSaveOptions()
workbook.save("output.docx", docxOptions)

// save spreadsheet as PPTX
pptxOptions = PptxSaveOptions()
workbook.save("output.pptx", pptxOptions)