genderwatchprotocol/spreadSheetReader/read_write_xlsx.php

29 lines
787 B
PHP
Raw Normal View History

2023-02-14 19:56:51 +01:00
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSX.php';
require $_SERVER['DOCUMENT_ROOT'] . '/spreadSheetReader/SimpleXLSXGen.php';
2023-02-15 17:12:23 +01:00
function read_xls_file($filename){
$fileContent = [];
if ($xlsx = SimpleXLSX::parse($filename)) {
$fileContent = ($xlsx->rows());
} else {
echo SimpleXLSX::parseError();
}
return $fileContent;
}
2023-02-14 19:56:51 +01:00
2023-02-15 17:12:23 +01:00
function write_xlsxFile($filename, $data) {
2023-02-14 23:20:53 +01:00
$xlsx = SimpleXLSXGen::fromArray($data);
2023-02-15 17:12:23 +01:00
$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);
2023-02-15 13:31:48 +01:00
$xlsx->downloadAs("data.xlsx");
2023-02-14 19:56:51 +01:00
}