Microsoft® Chuyển đổi định dạng Excel qua PHP

Nhập và xuất các tệp Excel dưới dạng bảng tính, web, hình ảnh và bố cục cố định

 

Thư viện PHP Excel tăng tốc quá trình lập trình và chuyển đổi bảng tính đồng thời hỗ trợ các định dạng phổ biến bao gồm XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, ODS. Nó cũng cho phép xuất các tệp Excel sang PDF, XPS, HTML, MHTML, Trơn Các định dạng văn bản và hình ảnh phổ biến như TIFF, JPG, PNG, BMP và SVG.

Chuyển đổi Excel thành XLSX, ODS, SXC & FODS bằng PHP

Việc chuyển đổi giữa các định dạng bảng tính chỉ yêu cầu tải một bảng tính có phiên bản của Sách bài tập và lưu lại ở định dạng mong muốn trong khi chọn giá trị thích hợp từ Lưu định dạng sự liệt kê.

Mã PHP để chuyển đổi định dạng tệp Excel
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);
 

Chuyển đổi Excel thành PDF, XPS, HTML & MD bằng PHP

Các lớp chuyên biệt có sẵn để kiểm soát quá trình chuyển đổi cho các định dạng đầu ra cụ thể như Tùy chọn lưu Pdf để xuất tệp Excel dưới dạng PDF, Tùy chọn XpsSave để chuyển đổi Excel sang XPS, Tùy chọn lưu Html để hiển thị Excel dưới dạng HTML và MarkdownSaveOptions để chuyển đổi Excel sang Markdown.

Mã PHP cho Excel tới PDF và Định dạng Web
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);
 

Chuyển đổi JSON sang Excel & Excel thành JSON Sử dụng PHP

Các nhà phát triển PHP có thể dễ dàng tải và chuyển đổi tệp JSON sang Excel chỉ bằng vài dòng mã. Tương tự, dữ liệu Excel có thể xuất sang dữ liệu JSON.

Mã PHP cho chuyển đổi JSON sang Excel
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");
Mã PHP cho Excel chuyển đổi sang JSON
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");
 

Chuyển đổi bảng tính Excel sang JPG, BMP, PNG & GIF bằng PHP

Mỗi bảng tính của một tệp Excel có thể được chuyển đổi sang các định dạng hình ảnh khác nhau, hãy gọi Tùy chọn Hình ảnh Hoặc In .setImageFormat để đặt định dạng hình ảnh.

Mã PHP để chuyển đổi Excel sang hình ảnh
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")
 

Chuyển Excel sang Word & PowerPoint Sử dụng PHP

Có thể tải bất kỳ bảng tính nào và chuyển đổi nó thành tệp Word DOCX & PowerPoint PPTX trong khi sử dụng Tùy chọn lưu Docx & Tùy chọn lưu Pptx các lớp như được minh họa dưới đây.

Mã PHP cho Excel sang Word & chuyển đổi PowerPoint
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)