donglang1894 2013-03-05 12:39
浏览 448
已采纳

如何设置csv文件列的大小?

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;
}
  • 写回答

3条回答 默认 最新

  • donglinxin8765 2013-03-05 12:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题