【发布时间】:2018-10-17 20:09:09
【问题描述】:
这有点愚蠢和不必要,但也有点浪费时间,因为我每天都这样做。但我想知道是否有一种方法可以使用 PHP 将数据导出为 CSV,在 excel 中打开文件时不需要使用文本导入向导。
目前我的代码看起来像这样,我认为这似乎在我所看到的每个地方都很标准:
header("Content-type: text/csv");
header('Content-Disposition: attachment; filename=exported_shipments_'.date("Ymd").'.csv');
header("Pragma: no-cache");
header("Expires: 0");
echo "name" . "\t";
echo "address_1" . "\t";
echo "address_2" . "\t";
echo "city" . "\t";
echo "province_code" . "\t";
echo "postal_code" . "\t";
echo "country_code" . "\t";
echo "phone" . "\t";
echo "package_contents" . "\t";
echo "description" . "\t";
echo "value" . "\t";
echo "value_currency" . "\t";
echo "order_store" . "\t";
echo "order_id" . "\t";
echo "package_type" . "\t";
echo "size_x" . "\t";
echo "size_y" . "\t";
echo "size_z" . "\t";
echo "size_unit" . "\t";
echo "weight" . "\t";
echo "weight_unit" . "\t";
echo "postage_type" . "\t";
echo "signature_requested" . "\t";
echo "insurance_requested" . "\t";
echo "ship_date" . "\t";
echo "\n";
等等。
我可以做些什么来让 excel 识别出我希望它立即被分隔,而不必使用向导?
【问题讨论】:
-
如果它是 csv,你为什么要使用标签? csv 中的 C 代表什么?
-
另存为 excel xls/xlsx 对您来说不是一个选项吗?