Zefix_search/read_write_xlsx.php

29 lines
693 B
PHP
Raw Permalink Normal View History

2023-09-25 22:22:50 +02:00
<?php
2023-09-25 23:23:42 +02:00
require 'SimpleXLSX.php';
require 'SimpleXLSXGen.php';
2023-09-25 22:22:50 +02:00
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");
}