2015-02-24 92 views
1

我想創建一個應用程序,當您導入CSV時,它將導出到.xlsx。但也有一些conditins:PHP:ParseCSV或PHPExcel哪個更好?

  1. 我需要更改列的順序,並刪除了一些列的時,其出口
  2. 我也需要改變顏色和字體(大小,顏色)
  3. 並且還在單個.xlsx文件上創建多個工作表。

哪個更適合在這類應用上使用,誰能幫助我,分享哪些更好。我對兩者都進行了探索,但我需要一些指導和一些更好的解決方案。謝謝。

回答

1
// output headers so that the file is downloaded rather than displayed 
header('Content-Type: text/csv; charset=utf-8'); 
header('Content-Disposition: attachment; filename=file.csv'); 

// create a file pointer connected to the output stream 
$output = fopen('php://output', 'w'); 

// output the column headings 
fputcsv($output, array('First Name', 'Last Name')); 

你需要使用插件或任何東西。 PHP本身就具有功能。我上面寫的是一個定義文件並輸出CSV第一行的例子。

fputcsv()的每次使用都會輸出一個新行。

所以你可以通過在數組中告訴它哪個值到達行中的哪個位置來定義事物的順序。

+0

但我的擔憂是基於3個條件。我如何更改顏色或字體大小?但是,謝謝你的回答。 – frogcoder 2015-02-24 12:57:02

+1

@frogcoder CSV代表逗號分隔值。你不能實現這一點,因爲CSV文件不支持字體樣式等 – Hazonko 2015-02-24 15:27:16

+0

是不是。但是如果您讀取csv並將其解析爲數組並將其導出爲.csv – frogcoder 2015-02-25 04:58:48