Data isn't being written into excel file in PHP

Viewed 16

I am using simplexlsxgen library to write the records fetched from mysql database into an excel file.

My code:

$arr = array();
$sql = "SELECT * FROM `emp_table`";
$result = $con->query($sql);
if ($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
        $temp=array();
        array_push($temp,'<center>'.trim($row["EmpNo"]).'</center>',
                  '<center>'.trim($row["EmpName"].'</center>');
        array_push($arr,$temp);
    }
    var_dump($arr); //all records are present in array
    $xlsx = \Shuchkin\SimpleXLSXGen::fromArray($arr)
                ->setDefaultFont('Courier New')
                ->setDefaultFontSize(14)
                ->setColWidth(1, 35)
                ->saveAs('../reports/file.xlsx);
}

When I open the downloaded excel file, it keeps showing No data written in the top left cell of the excel sheet. Why isn't my data being written in the excel file?

0 Answers
Related