How to convert xls to xlsx in codeigniter?

Member

by lottie , in category: PHP Frameworks , 2 months ago

How to convert xls to xlsx in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by lindsey.homenick , 2 months ago

@lottie 

To convert xls to xlsx in CodeIgniter, you can use a PHP library like PHPExcel. Here's how you can do it:

  1. Install PHPExcel library in your CodeIgniter project by downloading it from GitHub or using Composer.
  2. Load the PHPExcel library in your controller where you want to convert the file. You can load it using the following code:
1
$this->load->library('PHPExcel');


  1. Read the xls file using PHPExcel library and then save it as xlsx. Here's an example code snippet to convert xls to xlsx:
1
2
3
4
5
6
$inputFileName = 'path/to/your/input.xls';
$spreadsheet = PHPExcel_IOFactory::load($inputFileName);

$writer = PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel2007');
$outputFileName = 'path/to/your/output.xlsx';
$writer->save($outputFileName);


  1. Make sure to replace 'path/to/your/input.xls' with the actual path of your xls file and 'path/to/your/output.xlsx' with the path where you want to save the xlsx file.
  2. Run your CodeIgniter application and visit the controller where you added the conversion code to convert the xls file to xlsx.


By following these steps, you should be able to convert xls to xlsx in CodeIgniter using PHPExcel library.