<?php //php test_xlsxwriter.php >out.xlsx //Generates a spreadsheet with multiple sheets, 10K rows, 10 columns include_once __DIR__ . '/../xlsxwriter.class.php'; $headers = array('id' => 'string', 'name' => 'string', 'description' => 'string', 'n1' => 'string', 'n2' => 'string', 'n3' => 'string', 'n4' => 'string', 'n5' => 'string', 'n6' => 'string', 'n7' => 'string'); $sheet_names = array('january', 'february', 'march', 'april', 'may', 'june'); $start = microtime(true); $writer = new XLSXWriter(); foreach ($sheet_names as $sheet_name) { $writer->writeSheetHeader($sheet_name, $headers); for ($i = 0; $i < 10000; $i++) { $writer->writeSheetRow($sheet_name, random_row()); } } $writer->writeToStdOut(); file_put_contents("php://stderr", '#' . floor(memory_get_peak_usage() / 1024 / 1024) . "MB" . "\n"); file_put_contents("php://stderr", '#' . sprintf("%1.2f", microtime(true) - $start) . "s" . "\n"); function random_row() { return $row = array(rand() % 10000, chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)), md5(uniqid()), rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000); }
<?php include_once "xlsxwriter.class.php"; $header = array("string", "string", "string", "string", "string"); $row1 = array("Merge Cells Example"); $row2 = array(100, 200, 300, 400, 500); $row3 = array(110, 210, 310, 410, 510); $sheet_name = 'Sheet1'; $writer = new XLSXWriter(); $writer->writeSheetHeader($sheet_name, $header, $suppress_header_row = true); $writer->writeSheetRow($sheet_name, $row1); $writer->writeSheetRow($sheet_name, $row2); $writer->writeSheetRow($sheet_name, $row3); $writer->markMergedCell($sheet_name, $start_row = 0, $start_col = 0, $end_row = 0, $end_col = 4); $writer->writeToFile('example.xlsx');
<?php include_once "xlsxwriter.class.php"; $writer = new XLSXWriter(); $writer->writeSheetHeader('Sheet1', array('c1' => 'string', 'c2' => 'string', 'c3' => 'string', 'c4' => 'string')); //optional for ($i = 0; $i < 50000; $i++) { $writer->writeSheetRow('Sheet1', array(rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000)); } $writer->writeToFile('output.xlsx'); echo '#' . floor(memory_get_peak_usage() / 1024 / 1024) . "MB" . "\n";