I want to write an excel .xlsb file whose name is the day number.
For example, the file name for yesterday 23.xlsb
.
The original file name is "Template.xlsb" and the location is different. As you can see this file, it is copied and renamed to a new location. I have many macros and vba codes in this file, and therefore I do not want to create a new Excel file.
At the end, the link for this Excel file is in this variable $renamed_link
.
$renamed_link = C:\Documents and Settings\Administrator\Desktop\Rezultate DIDU\2017\Apr\23.xlsb
.
I want to fill out the first worksheet called "Parametri" with data from my SQL query ( $parametri
).
The range from the sheet to be filled with data is from A2
to T and the total number of the rows
. The table contains 20 columns.
<?php
require(realpath(dirname(__FILE__)."/PHPExcel-1.8/Classes/PHPExcel.php"));
$sql_data = date('d.m.Y', strtotime('-1days'));
$conn = oci_connect('USER', 'PASS', 'dark:1521/DAR');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
Else {echo 'Connection successfully !';
}
$parametri = oci_parse($conn,"SELECT * FROM R0508UNITP WHERE TO_DATE('${sql_data}','DD.MM.YYYY') BETWEEN R0508UNITP.R0508VFROM AND R0508UNITP.R0508VTILL");
oci_execute($parametri);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($parametri, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
$day = date('j', strtotime('-1 days'));
$month = date('M', strtotime('-1 days'));
$year = date('Y', strtotime('-1 days'));
$link = "C:\Documents and Settings\Administrator\Desktop\Rezultate DIDU\\${year}\\${month}";
$template_link = 'C:\Documents and Settings\Administrator\Desktop\Rezultate DIDU\Template.xlsb';
$destination_link = "C:\Documents and Settings\Administrator\Desktop\Rezultate DIDU\\${year}\\${month}".'\Template.xlsb';
$renamed_link = "C:\Documents and Settings\Administrator\Desktop\Rezultate DIDU\\${year}\\${month}\\${day}".'.xlsb';
if(!is_dir($link))
{
mkdir($link, 0777,true);
}
if(!file_exists($destination_link))
{
copy($template_link,$destination_link);
} else {
}
rename($destination_link,$renamed_link);
?>
Screen print of my php table (some of them).
In this table, I want to be in my excel file.

source
share