Is there a way to convert csv file to excel file upon request through apache/.htaccess
How do I open a CSV file in Microsoft Excel without changing the column formatting? To open a comma-delimited (CSV) file properly, use Excel's Data Import from Text feature to open the import wizard and set all columns as text.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With