Microsoft® การแปลงรูปแบบ Excel ผ่าน Python

นำเข้าและส่งออกไฟล์ Excel เป็นรูปแบบสเปรดชีต เว็บ รูปภาพ และเค้าโครงคงที่

 

Python Excel Library เร่งความเร็วการเขียนโปรแกรมสเปรดชีตและกระบวนการแปลงในขณะที่รองรับรูปแบบยอดนิยม ได้แก่ XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, 076193 481 นอกจากนี้ยังอนุญาตให้ส่งออกไฟล์ Excel ไปที่ PDF, XPS, HTML, MHTML, Plain รูปแบบข้อความและรูปภาพยอดนิยม เช่น TIFF, JPG, PNG, BMP และ SVG

แปลง Excel เป็น XLSX, ODS, SXC & FODS

การแปลงรูปแบบสเปรดชีตระหว่างกันจำเป็นต้องโหลดสเปรดชีตที่มีอินสแตนซ์ของ สมุดงาน และบันทึกกลับในรูปแบบที่ต้องการพร้อมเลือกค่าที่เหมาะสมจาก บันทึกรูปแบบ การแจงนับ

Python รหัสสำหรับการแปลงรูปแบบไฟล์ 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);
 

แปลง Excel เป็น PDF, XPS, HTML & MD

มีคลาสเฉพาะสำหรับควบคุมกระบวนการแปลงสำหรับรูปแบบเอาต์พุตเฉพาะ เช่น PdfSaveตัวเลือก เพื่อส่งออกไฟล์ Excel เป็น PDF ตัวเลือก XpsSave สำหรับการแปลง Excel เป็น XPS ตัวเลือก HtmlSave เพื่อแสดง Excel เป็น HTML และ MarkdownSaveOptions สำหรับการแปลง Excel เป็น Markdown

Python รหัสสำหรับ Excel ถึง PDF และรูปแบบเว็บ
// 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);
 

แปลง JSON เป็น Excel และ Excel เป็น JSON

นักพัฒนา Python สามารถโหลดและแปลงไฟล์ JSON เป็น Excel ได้อย่างง่ายดายด้วยโค้ดเพียงไม่กี่บรรทัด ในทำนองเดียวกัน ข้อมูล Excel สามารถส่งออกไปยังข้อมูล JSON

รหัส Python สำหรับการแปลง JSON เป็น Excel
//Load your source json file
workbook = Workbook("Data.json")
//save file to xlsx format
workbook.save("output.xlsx")
Python รหัสสำหรับการแปลง Excel เป็น JSON
//Load your source xlsx file
workbook = Workbook("input.xlsx")
//save file to json format
workbook.save("Data.json")
 

แปลงแผ่นงาน Excel เป็น JPG, BMP, PNG & GIF

แต่ละแผ่นงานของไฟล์ Excel สามารถแปลงเป็นรูปแบบภาพต่างๆ โทร ImageOrPrintOptions .setImageFormat เพื่อกำหนดรูปแบบภาพ

Python รหัสสำหรับการแปลง Excel เป็นรูปภาพ
// 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")
 

แปลง Excel เป็น Word & PowerPoint

เป็นไปได้ที่จะโหลดสเปรดชีตและแปลงเป็นไฟล์ Word DOCX & PowerPoint PPTX ขณะใช้งาน ตัวเลือก DocxSave & ตัวเลือก PptxSave ชั้นเรียนที่แสดงด้านล่าง

รหัส Python สำหรับการแปลง Excel เป็น Word & 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)