如何设置csv文件的列大小? [英] how to set size of column of csv file?
问题描述
我想在csv文件中设置每个coulom的大小,我想设置coloum对字段的大小,我不知道我可以做的代码设置大小?任何一个可以帮助它将被感谢,提前感谢。
这是我的代码
i want to set the size of each coulom in csv file, i want to set the size of coloum against the field, i dont know where i can do the code of to set the size? any one can help it will be arepciated, thanks in advance. this is my code
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;
}
推荐答案
。CSV文件没有任何格式,包括列大小。
You can't... a CSV file has no formatting of any kind, including column size.
如果要控制列宽,则需要将数据写入一个格式支持列宽度,如BIFF(.xls)或OfficeOpenXML(.xlsx)或OASIS开放文档格式(.ods)或Gnumeric或其他电子表格。
If you want to control column widths, then you need to write the data to a format that does support columns widths, such as BIFF (.xls) or OfficeOpenXML (.xlsx) or OASIS Open Document Format (.ods) or Gnumeric or other spreadsheet.
这篇关于如何设置csv文件的列大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!