Zefix_search/read_write_xlsx.php

29 lines
693 B
PHP

<?php
require 'SimpleXLSX.php';
require 'SimpleXLSXGen.php';
function read_xls_file($filename){
$fileContent = [];
if ($xlsx = SimpleXLSX::parse($filename)) {
$fileContent = ($xlsx->rows());
} else {
echo SimpleXLSX::parseError();
}
return $fileContent;
}
function write_xlsxFile($filename, $data) {
$xlsx = SimpleXLSXGen::fromArray($data);
$xlsx->saveAs($filename);
}
function download_xlsxFile($data) {
$xlsxArray = read_xls_file($_SERVER['DOCUMENT_ROOT'] ."/data/data.xlsx");
foreach ($data as $row) {
array_push($xlsxArray, $row);
}
$xlsx = SimpleXLSXGen::fromArray($xlsxArray);
$xlsx->downloadAs("data.xlsx");
}