1
我在我的庫存部分有以下代碼,當我運行這段代碼時,它保存了一個excel文件,但結果顯示整個html文件不是我的數據。Joomla導出或下載報告到CSV
<?php
$csv = NULL;
$arr = array("product_name","product_sku","product_in_stock","virtuemart_product_id","product_price_display","product_instock_value");
$csv = "Product Name, Product SKU, In Stock, Booked ordered products, Cost Price, Stock Value \n";
$c=0;
while(list($key,$value)=each($arr)){
$c++;
$cc=1;
foreach ($this->inventorylist as $key => $product){
$cc++;
$csv .= join(',',array($product->product_name.",".$product->product_sku.",".$product->product_in_stock.",".$product->virtuemart_product_id.",".$product->product_price_display.",".$product->product_instock_value))." \n";
}
}
JResponse::clearHeaders();
JResponse::setHeader('Content-Type', 'application/vnd.ms-excel', true);
JResponse::setHeader('Content-Disposition', 'csv; filename=inventory_report.csv; size='.strlen($csv), true);
JResponse::sendHeaders();
任何幫助將不勝感激。
感謝
Khalique
一些額外的見解,如果你的var_dump什麼happends '$ csv'變量? – Lodder
看看核心com_banners組件,它會下載一個csv文件。 – Elin