2

我在网上找到了几个关于强制包含 fputcsv 输出的主题,发现这是不可能的。由于某些导入要求,我需要用引号将每个输出括起来。单独的单词有效,但非单独的作品无效。我看到有几个解决方法,但我无法让它们工作。例如,我有这个代码:

/**
 * Writes the row(s) for the given order in the csv file.
 * A row is added to the csv file for each ordered item. 
 * 
 * @param Mage_Sales_Model_Order $order The order to write csv of
 * @param $fp The file handle of the csv file
 */
protected function writeOrder($order, $fp) 
{
    $common = $this->getCommonOrderValues($order);
    $orderItems = $order->getItemsCollection();
    $itemInc = 0;
    foreach ($orderItems as $item)
    {
        if (!$item->isDummy()) {
            $record = array_merge($common, $this->getOrderItemValues($item, $order, ++$itemInc));
            fputcsv($fp, $record, self::DELIMITER, self::ENCLOSURE);
        }
    }
}

你能帮我解决这个问题吗?

4

1 回答 1

0

在https://pear.php.net/package/File_CSV/使用 PEAR 的 File_CSV 包

您的代码看起来像这样,这显然是不完整的:

<?php
require 'File/CSV.php'; 
$csv_conf = array(
    'fields' => 3, 
    'crlf' => "\r\n", 
    'quote' => '"', 
    'sep' => ','
);

$common = $this->getCommonOrderValues($order);
$orderItems = $order->getItemsCollection();
$itemInc = 0;
foreach($orderItems as $item) {
    if (!$item->isDummy()) {
        $record = array_merge(
            $common, 
            $this->getOrderItemValues($item, $order, ++$itemInc)
        );
        $res = File_CSV::write($fileName, $record, $csv_conf);
    }
}
于 2013-12-12T15:27:38.463 回答