Zefix_search/read_write_xlsx.php

29 lines
787 B
PHP
Raw Normal View History

2023-09-25 22:22:50 +02:00
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/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");
}