Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Excel XLS to CSV using PHP

Tags:

php

csv

xls

Can anyone guide me how to convert XLS to CSV using PHP?

I have excel spread sheet which contains a list of documents, I want to convert this with CSV format using PHP.

like image 988
RAAAAM Avatar asked Oct 14 '11 10:10

RAAAAM


People also ask

How write data from Excel to PHP?

Export Data to Excel with PHP The $data variable holds the data in array format which will be exported to Excel using PHP. ); The filterData() function is used to filter string before added to the excel sheet row. The following code helps to export data in excel and download it as a file.


1 Answers

This will surely work,

require_once 'Classes/PHPExcel/IOFactory.php';  $inputFileType = 'Excel5'; $inputFileName = 'YOUR_EXCEL_FILE_PATH';  $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcelReader = $objReader->load($inputFileName);  $loadedSheetNames = $objPHPExcelReader->getSheetNames();  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');  foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {     $objWriter->setSheetIndex($sheetIndex);     $objWriter->save($loadedSheetName.'.csv'); } 

Hope this helps...

like image 65
Rajat Modi Avatar answered Oct 19 '22 23:10

Rajat Modi