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.
/*
Connect to the local server using Windows Authentication and specify
the AdventureWorks database as the database in use. To connect using
SQL Server Authentication, set values for the "UID" and "PWD"
attributes in the $connectionInfo parameter. For example:
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>"AdventureWorks");
*/
$sql = "SELECT Personnel.Name as PersonnelName, Trade.Trade, round(Trace.Duration/60.0-1,2) as Hours, CONVERT(varchar,Trace.Timestamp,20) as TimestampEntry, CONVERT(varchar,Trace.TimestampExit,20) as TimestampExit, Company.SiteName as Project, Location.Name as LocationName, CONVERT(varchar,Trace.Timestamp,11) as DateSort
FROM PTS.dbo.Trace
INNER JOIN PTS.dbo.Personnel ON Personnel.PID = Trace.PID
INNER JOIN PTS.dbo.Location ON Location.LocID = Trace.LocID
INNER JOIN PTS.dbo.Company ON Company.CompanySiteID = Location.CompanySiteID
INNER JOIN PTS.dbo.Trade ON Trade.TradeID = Personnel.TradeID
WHERE ((((Trace.Timestamp BETWEEN '2020-09-01' AND '2020-09-29') AND round(Trace.Duration/60.0-1,2) > 0)) OR (Trace.Timestamp BETWEEN '2020-09-29' AND DATEADD(day, 1, '2020-09-29'))) AND Company.SiteName LIKE '%P4601%'
ORDER BY DateSort, Personnel.Name
";
} else {
$sql = "SELECT Personnel.Name as PersonnelName, Trade.Trade, round(Trace.Duration/60.0-1,2) as Hours, CONVERT(varchar,Trace.Timestamp,20) as TimestampEntry, CONVERT(varchar,Trace.TimestampExit,20) as TimestampExit, Company.SiteName as Project, Location.Name as LocationName, CONVERT(varchar,Trace.Timestamp,11) as DateSort
FROM PTS.dbo.Trace
INNER JOIN PTS.dbo.Personnel ON Personnel.PID = Trace.PID
INNER JOIN PTS.dbo.Location ON Location.LocID = Trace.LocID
INNER JOIN PTS.dbo.Company ON Company.CompanySiteID = Location.CompanySiteID
INNER JOIN PTS.dbo.Trade ON Trade.TradeID = Personnel.TradeID
WHERE ((((Trace.Timestamp BETWEEN '#DateFrom#' AND '#DateTo#') AND round(Trace.Duration/60.0-1,2) > 0)) OR (Trace.Timestamp BETWEEN '#DateTo#' AND DATEADD(day, 1, '#DateTo#'))) AND Company.SiteName LIKE '%#Project#%'
ORDER BY DateSort, Personnel.Name";
//Get the column names.
$columnNames = array();
if(!empty($rows)){
//We only need to loop through the first row of our result
//in order to collate the column names.
$firstRow = $rows[0];
foreach($firstRow as $colName => $val){
$columnNames[] = $colName;
}
}
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Fill;
$sheet->fromArray(
$columnNames, // The data to set
NULL, // Array values with this value will not be set
'A2' // Top left coordinate of the worksheet range where
// we want to set these values (default is A1)
);
$sheet->fromArray(
$rows, // The data to set
NULL, // Array values with this value will not be set
'A3' // Top left coordinate of the worksheet range where
// we want to set these values (default is A1)
);
Above is the source code I put into a nuProcedure.
I copied the phpspreadsheet library to the vendors folder under Nubuilder.
The database I'm extracting from is MSSQL, need to change to others as needed.
ernesttan1976 wrote: ↑Mon Oct 05, 2020 11:09 am
Hi Kevin,
Above is the source code I put into a nuProcedure.
I copied the phpspreadsheet library to the vendors folder under Nubuilder.
The database I'm extracting from is MSSQL, need to change to others as needed.
I am also trying to use PhpSpreadsheet. Is there a way to make this work without putting the library within the nuBuilder directory structure? My goal is to keep the nuBuilder update process as simple as possible.