Microsoft® Excel Format Conversion via PHP
Import & export Excel files as spreadsheet, web, image and fixed-layout formats
PHP Excel Library speeds up spreadsheet programming and conversion processes while supporting popular formats including XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, ODS. It also allows to export Excel files to PDF, XPS, HTML, MHTML, Plain Text and popular image formats such as TIFF, JPG, PNG, BMP and SVG.
Convert Excel to XLSX, ODS, SXC & FODS Using PHP
Inter-conversion of spreadsheet format only requires loading a spreadsheet with an instance of Workbook and saving back in the desired format while selecting appropriate value from SaveFormat enumeration.
PHP Code for Excel File Format Conversion
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// load the template file
$workbook = new Workbook("input.xlsx");
// save as XLSX, ODS, SXC & FODS formats
$workbook->save("output.xlsx", SaveFormat::Xlsx);
$workbook->save("output.ods", SaveFormat::Ods);
$workbook->save("output.scx", SaveFormat::Sxc);
$workbook->save("output.fods", SaveFormat::Fods);
Convert Excel to PDF, XPS, HTML & MD Using PHP
Specialized classes are available to control the conversion process for specific output formats such as PdfSaveOptions to export Excel files as PDF, XpsSaveOptions for Excel to XPS conversion, HtmlSaveOptions to render Excel as HTML and MarkdownSaveOptions for Excel to Markdown conversion.
PHP Code for Excel to PDF and Web Formats
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// load the template file
$workbook = new Workbook("input.xlsx");
// save Excel in PDF_A_1_B format
$pdfOptions = new PdfSaveOptions();
$pdfOptions->setCompliance(PdfCompliance::PDF_A_1_B);
$workbook->save("output.pdf", pdfOptions);
// save Excel in XPS with 1 page per worksheet
$xpsOptions = new XpsSaveOptions();
$xpsOptions->setOnePagePerSheet(true);
$workbook->save("output.xps", xpsOptions);
// save Excel in HTML with images as Base64
$htmlOptions = new HtmlSaveOptions();
$htmlOptions->setExportImagesAsBase64(true);
$workbook->save("output.html", htmlOptions);
// save Excel in Markdown (MD) while retaining cell formatting
$mdOptions = new MarkdownSaveOptions();
$mdOptions->setFormatStrategy(CellValueFormatStrategy::CELL_STYLE);
$workbook->save("output.md", mdOptions);
Convert JSON to Excel & Excel to JSON Using PHP
PHP developers can easily load & convert JSON files to Excel in just a few lines of code. Similarly, Excel data can be exported to JSON data.
PHP Code for JSON to Excel Conversion
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// Load your source json file
$workbook = new Workbook("Data.json");
//save file to xlsx format
$workbook->save("output.xlsx");
PHP Code for Excel to JSON Conversion
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// Load your source xlsx file
$workbook = new Workbook("input.xlsx");
// save file to json format
$workbook->save("Data.json");
Convert Excel Worksheets to JPG, BMP, PNG & GIF Using PHP
Each worksheet of an Excel file can be converted to different image formats, call ImageOrPrintOptions .setImageFormat to set the image format.
PHP Code for Excel to Image Conversion
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// load template spreadsheet
$workbook = new Workbook("template.xlsx");
// create & set an instance of ImageOrPrintOptions
$options = new ImageOrPrintOptions();
// set output image type
$options->setImageType(ImageType::PNG);
// create SheetRender for first worksheet in the collection
$sheet = $workbook->getWorksheets()->get(0);
$sr = new SheetRender(sheet, options);
// render worksheet to image
$sr->toImage(0, "output.jpg")
Convert Excel to Word & PowerPoint Using PHP
It is possible to load any spreadsheet and convert it to Word DOCX & PowerPoint PPTX files while using DocxSaveOptions & PptxSaveOptions classes as demonstrated below.
PHP Code for Excel to Word & PowerPoint Conversion
require_once("Java.inc");
require_once("lib/aspose.cells.php");
use aspose\cells;
use aspose\cells\Workbook;
// load template spreadsheet
$workbook = new Workbook("template.xlsx");
// save spreadsheet as DOCX
$docxOptions = new DocxSaveOptions();
$workbook->save("output.docx", docxOptions);
// save spreadsheet as PPTX
$pptxOptions = new PptxSaveOptions();
$workbook->save("output.pptx", pptxOptions)