如何设置csv文件列的大小? [英] How to set size of column of csv file?
本文介绍了如何设置csv文件列的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
code> function export($ result)
{
Configure :: write('debug',0);
$ filename =excel。csv;
$ csv_file = fopen('php:// output','w');
header('Content-Type: csv; charset = utf-8');
header('Content-Disposition:attachment; filename ='$ filename。''');
//列标题.csv文件
$ header_row1 = array(
姓氏,
名字,
中间名,
);
$ header_row = array_merge($ header_row1,$ header_row2);
fputcsv($ csv_file,$ header_row,',',''');
//数组索引对应于数据库表中的字段名称
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文件没有任何类型的格式,包括列大小。
如果要控制列宽,则需要将数据写入支持列宽度的格式,例如BIFF(.xls)或OfficeOpenXML(.xlsx)或OASIS Open Document Format(.ods)或Gnumeric或其他电子表格。
I want to set the size of each column in csv file, I want to set the size of column against the field, I don't know where I can do the code of to set the size? Can anyone help it will be appreciated, 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;
}
解决方案
You can't... a CSV file has no formatting of any kind, including column size.
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屋!
查看全文