我想在 csv 文件中设置每一列的大小,我想根据字段设置列的大小,我不知道在哪里可以做代码来设置大小?任何人都可以帮助它,将不胜感激,在此先感谢。
这是我的代码
function export($result)
{
Configure::write('debug',0);
$filename = "excel.".csv";
$csv_file = fopen('php://output', 'w');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
// The column headings of .csv file
$header_row1 = array(
"Last Name",
"First Name",
"Middle Name",
);
$header_row = array_merge($header_row1,$header_row2);
fputcsv($csv_file,$header_row,',','"');
// Array indexes correspond to the field names in your db table(s)
if (!isset($result['Post']['User'])) {
$row1 = array(
$result['Post']['prefix_name'],
$result['Post']['first_name'],
$result['Post']['middle_name'],
$result['Post']['last_name'],
);
}
else {
$row1 = array(
$result['Post']['prefix_name'],
$result['Post']['first_name'],
$result['Post']['middle_name'],
$result['Post']['last_name'],
);
}
$row = array_merge($row1,$row2);
unset($row2);
fputcsv($csv_file,$row,',','"');
}
fclose($csv_file);
exit;
}