我是 cakephp 新手,我需要使用 cakephp2.0 将“.xls”文件转换为“.csv”文件。我尝试使用 PhpExcel,即使它不起作用。
问问题
444 次
1 回答
0
first download the Spreadsheet_Excel_Reader class, save it inside vendor folder
before starting the controller class add the following
App::uses('Vendor', 'excel_reader');
inside the function
public function createcsvfromxls() {
$data = new Spreadsheet_Excel_Reader(WWW_ROOT . 'pathtofile.xls', true);
ob_clean();
if ($filename = tempnam(sys_get_temp_dir(), "csv")) {
if ($file = fopen($filename, "w")) {
fputcsv($file, array('column 1', 'column 2'));
}
$exeldata = $data->sheets['0']['cells'];
foreach ($exeldata as $key => $val) {
fputcsv($file, array('columonedata', 'colum2data'));
}
}
fclose($file);
header("Content-Type: application/xls");
header("Content-Disposition: attachment;Filename=DHAProviderdetails.csv");
header("charset: UTF-8");
echo readfile($filename);
unlink($filename);
exit;
}
try this
于 2013-06-19T12:25:37.493 回答