I can't use the insertDate method, because I must show datetime based on user timezone. That is why I use the insertText to mimic this behavior. but the insertText method is insane, it will add " ' " before the date formated string, check the picture below.
<?php
use Carbon\Carbon;
require_once 'vendor/autoload.php';
// Example configuration for the xlswriter
$config = [
'path' => '/var/www/html'
];
// Create a new Excel file
$writer = new \Vtiful\Kernel\Excel($config);
$writer->fileName("example.xlsx")
->header(['date1', 'date2', 'date3', 'date4', 'date5']);
// Use the current timestamp
$timestamp = (new DateTime('now', new DateTimezone('GMT+8')))->getTimestamp(); // or use any specific timestamp
$value = Carbon::now('UTC');
$t2 = Carbon::parse($value, 'UTC')
->timezone('GMT+8');
var_dump($t2->toDateTimeString());
// Insert the date with the timestamp
$writer->insertDate(1, 0, $timestamp, 'yyyy-mm-dd hh:mm:ss');
// any string, "hello", no " ' " before the output
$writer->insertText(1, 1, "hello", 'yyyy-mm-dd hh:mm:ss');
// there is a " ' " before the output
$writer->insertText(1, 2, $t2->toDateTimeString(), 'yyyy-mm-dd hh:mm:ss');
// without format , there is a " ' " before the output
$writer->insertText(1, 3, '2024-06-28 09:47:36');
// with format , there is a " ' " before the output
$writer->insertText(1, 4, '2024-06-28 09:47:36', 'yyyy-mm-dd hh:mm:ss');
// Output the file
$writer->output();
Please use following to reproduce the problem.
I can't use the insertDate method, because I must show datetime based on user timezone. That is why I use the insertText to mimic this behavior. but the insertText method is insane, it will add " ' " before the date formated string, check the picture below.