PhpSpreadsheet run as a Procedure

Questions related to customising nuBuilder Forte with Javascript or PHP.

PhpSpreadsheet run as a Procedure

Postby ernesttan1976 » Thu Aug 27, 2020 6:27 pm

Dear all,

I am trying to run this code as a php procedure by clicking on an input:button, onclick method.
Procedure is run as a new window.
But the window is blank. No error message whatsoever is shown.

Before this, I had run 'composer require PhpOffice\PhpSpreadsheet and now the autoloader is working well. In fact I ran a plain php file with this library and it works well.
But I couldn't get it to work as a php procedure in Nubuilder.

Any advice is greatly appreciated. Thanks!

Code: Select all
require_once 'nudb/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

//Open excel sheet
$inputFileName = "http://58.185.199.182:8000/197201333K-PTE-01-workerList.xlsx";

try {
$spreadsheet = new \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

//Read range
$highestRow = $spreadsheet->getHighestRow;
$dataArray = $spreadsheet->getSheet(0)->rangeToArray(
    'B16:J'.$highestRow, //The worksheet range
    NULL,  // values for empty cells
    TRUE, // should formulas be calculated
    TRUE, // should values be formatted for each cell
    TRUE  // should the array be indexed by cell row and cell column
);

} catch (Exception $e){
   
    die('Error loading file: '.$e->getMessage());
}


header('Content-Type: text/html; charset=utf-8');

//echo '<!DOCTYPE html>';
echo '<html>';
echo '<body>';

//For each row, display
echo '<table>'."\n";
for ($row = 1; $row <= $highestrow-15; ++$row){
    echo '<tr>'.PHP_EOL;
        for ($col = 1; $col <=11; ++ $col){
            //$value = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
            $value = $dataArray[$row-1,$col-1];
            echo '<td>'.$value.'</td>'.PHP_EOL;
        }
    echo '</tr>'.PHP_EOL;
}


echo '</table>'.PHP_EOL;

echo '</body>';
echo '</html>';

//$writer = new Xlsx($spreadsheet);
//header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="demo.xlsx"');
//header('Cache-Control: max-age=0');
//header('Expires: Fri, 11 Nov 2011 11:11:11 GMT');
//header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
//header('Cache-Control: cache, must-revalidate');
//header('Pragma: public');
//$writer->save('php://output');
// ob_end_flush();

//$sql = "UPDATE users SET name=?, surname=?, sex=? WHERE id=?";
//$pdo->prepare($sql)->execute([$name, $surname, $sex, $id]);
//Find the FIN
//Update the other columns

//If cannot find, then give a message.
//If can find then mention "record XX updated"
ernesttan1976
 
Posts: 18
Joined: Sat May 16, 2020 5:38 pm

Re: PhpSpreadsheet run as a Procedure

Postby kev1n » Sat Aug 29, 2020 1:03 am

Hi,

I have no experience with composer but you could add some nuDebug('1'); [code in between] nuDebug('2'); etc. in the code to see where it gets stuck.
Also check nuDebug Results and the server log for errors.
kev1n
 
Posts: 978
Joined: Mon Oct 15, 2018 2:13 am

Re: PhpSpreadsheet run as a Procedure

Postby kev1n » Mon Sep 14, 2020 2:23 pm

Hi,

Were you able to resolve your issue?
kev1n
 
Posts: 978
Joined: Mon Oct 15, 2018 2:13 am


Return to Custom Code