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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号