csv to excel conversion

后端 未结 6 1683
天涯浪人
天涯浪人 2020-12-05 05:26

Is there a way to convert csv file to excel file upon request through apache/.htaccess

6条回答
  •  时光取名叫无心
    2020-12-05 05:48

    Using PHPExcel

    include 'PHPExcel/IOFactory.php';
    
    $objReader = PHPExcel_IOFactory::createReader('CSV');
    
    // If the files uses a delimiter other than a comma (e.g. a tab), then tell the reader
    $objReader->setDelimiter("\t");
    // If the files uses an encoding other than UTF-8 or ASCII, then tell the reader
    $objReader->setInputEncoding('UTF-16LE');
    
    $objPHPExcel = $objReader->load('MyCSVFile.csv');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('MyExcelFile.xls');
    

提交回复
热议问题