Microsoft® Excel-Formatkonvertierung über Python

Importieren und exportieren Sie Excel-Dateien als Tabellenkalkulation, Web, Bild und Format mit festem Layout

 

Python Die Excel-Bibliothek beschleunigt die Programmierung und Konvertierung von Tabellenkalkulationen und unterstützt gleichzeitig gängige Formate wie XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, 07619348 1. Es ermöglicht auch den Export von Excel-Dateien nach PDF, XPS, HTML, MHTML, Plain Text- und gängige Bildformate wie TIFF, JPG, PNG, BMP und SVG.

Konvertieren Sie Excel in XLSX, ODS, SXC und FODS

Für die gegenseitige Konvertierung des Tabellenformats ist lediglich das Laden einer Tabelle mit einer Instanz von erforderlich Arbeitsmappe und Speichern im gewünschten Format zurück, während Sie den entsprechenden Wert aus auswählen SaveFormat Aufzählung.

Python Code für die Konvertierung des Excel-Dateiformats
// 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);
 

Konvertieren Sie Excel in PDF, XPS, HTML und MD

Es stehen spezielle Klassen zur Verfügung, um den Konvertierungsprozess für bestimmte Ausgabeformate zu steuern, z PDFSaveOptions um Excel-Dateien als PDF zu exportieren, XpsSaveOptions für die Konvertierung von Excel in XPS, HtmlSaveOptions um Excel als HTML darzustellen und MarkdownSaveOptions für die Konvertierung von Excel in Markdown.

Python Code für Excel bis PDF und Webformate
// 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);
 

Konvertieren Sie JSON in Excel und Excel in JSON

Python-Entwickler können JSON-Dateien problemlos in nur wenigen Codezeilen laden und in Excel konvertieren. Ebenso können Excel-Daten in JSON-Daten exportiert werden.

Python Code für die Konvertierung von JSON in Excel
//Load your source json file
workbook = Workbook("Data.json")
//save file to xlsx format
workbook.save("output.xlsx")
Python-Code für Excel in JSON-Konvertierung
//Load your source xlsx file
workbook = Workbook("input.xlsx")
//save file to json format
workbook.save("Data.json")
 

Konvertieren Sie Excel-Arbeitsblätter in JPG, BMP, PNG und GIF

Jedes Arbeitsblatt einer Excel-Datei kann in verschiedene Bildformate konvertiert werden ImageOrPrintOptions .setImageFormat zum Festlegen des Bildformats.

Python Code für die Konvertierung von Excel in Bilder
// 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")
 

Konvertieren Sie Excel in Word & PowerPoint

Es ist möglich, jede Tabellenkalkulation zu laden und sie während der Verwendung in Word-Dateien DOCX und PowerPoint PPTX zu konvertieren DocxSaveOptions & PptxSaveOptions Klassen wie unten gezeigt.

Python-Code für Excel in Word und PowerPoint-Konvertierung
// 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)