Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnyga committed Mar 4, 2021
1 parent 535b5bd commit 10163e1
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
$onlyValidate = 1;
}


// The default locale. For alternative locales use language field. For additional locales use locale:fieldName.
$defaultLocale = 'en_US';

Expand Down Expand Up @@ -57,6 +58,20 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

/*
* Check that a file and a folder exists
* ------------------------------------
*/
if (!file_exists($fileName)) {
echo date('H:i:s') . " ERROR: given file does not exist" . EOL;
die();
}

if (!file_exists($filesFolder)) {
echo date('H:i:s') . " ERROR: given folder does not exist" . EOL;
die();
}

/*
* Load Excel data to an array
* ------------------------------------
Expand Down Expand Up @@ -502,7 +517,7 @@ function createArray($sheet) {
for ($row = 2; $row <= $highestrow; $row++) {
$a = array();
for ($column = 1; $column <= $columncount; $column++) {
if (strpos($header[$column], "bstract")) {
if (strpos($header[$column], "bstract") !== false) {
if ($sheet->getCellByColumnAndRow($column,$row)->getValue() instanceof \PhpOffice\PhpSpreadsheet\RichText\RichText) {
$value = $sheet->getCellByColumnAndRow($column,$row)->getValue();
$elements = $value->getRichTextElements();
Expand Down Expand Up @@ -552,27 +567,27 @@ function createArray($sheet) {
}

# Check the highest author number
function countMaxAuthors($articles) {
function countMaxAuthors($sheet) {
$highestcolumn = $sheet->getHighestColumn();
$headerRow = $sheet->rangeToArray('A1:' . $highestcolumn . "1");
$header = $headerRow[0];
$authorFirstnameValues = array();
foreach ($header as $headerValue) {
if (strpos($headerValue, "authorFirstname")) {
if (strpos($headerValue, "authorFirstname") !== false) {
$authorFirstnameValues[] = (int) trim(str_replace("authorFirstname", "", $headerValue));
}
}
return max($authorFirstnameValues);
}

# Check the highest file number
function countMaxFiles($articles) {
function countMaxFiles($sheet) {
$highestcolumn = $sheet->getHighestColumn();
$headerRow = $sheet->rangeToArray('A1:' . $highestcolumn . "1");
$header = $headerRow[0];
$fileValues = array();
foreach ($header as $headerValue) {
if (strpos($headerValue, "fileLabel")) {
if (strpos($headerValue, "fileLabel") !== false) {
$fileValues[] = (int) trim(str_replace("fileLabel", "", $headerValue));
}
}
Expand Down

0 comments on commit 10163e1

Please sign in to comment.