Writing XML Output
Write row arrays, workbook wrappers, metadata, typed values, and arbitrary structured payloads as XML.
Updated
Xml::write()XmlWriter::writeWorkbook()XmlWriter::payloadToString()What you will learn
- Configure root, row, cell, and sheet element names.
- Choose a compact or pretty document with an XML declaration.
- Serialize structured workbook arrays directly for API responses.
Write associative rows#
Xml::write($products, 'products.xml', [
'root' => 'products',
'row_tag' => 'product',
'include_row_number' => true,
'declaration' => true,
'pretty' => true,
]);Write a complete workbook#
use Mnb\PHPExcel\Writer\XmlWriter;
$xml = (new XmlWriter())->workbookToString($workbook, [
'root' => 'workbook',
'sheet_tag' => 'sheet',
'row_tag' => 'row',
'include_metadata' => true,
'workbook_wrapper' => true,
]);Serialize any structured payload#
$payload = MnbExcel::read('report.xlsx')
->withHeaderRow(1)
->toStructuredWorkbookArray();
$xml = (new XmlWriter())->payloadToString($payload, [
'root' => 'spreadsheet',
'pretty' => true,
]);Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue