I want to convert Excel file to CSV file with php

Asked 2 years ago, Updated 2 years ago, 123 views

What do you want to do

Convert the Excel file stored on the server side to a csv file using the PHPExel library and
I want to save it as a new csv file.

  • Image of Excel file already stored on server side (juuu.xls)

    item1 item2 item3
    2 3 6
    
  • The csv file you want to convert

    item1, item2, item3
    2,3,6
    

Excel file image already stored on server side (juchuu.xls)

item1 item2 item3
2 3 6

New csv file you want to convert

item1, item2, item3
2,3,6

Actual Programs

  • The juchuu.xls is stored in the appropriate folder on the server side
  • A complete set of PHPEXLEL programs is stored on the server side as a library
**<?php

echo "Step 0";
require_once(DIR."/lib/PHPExcel.php");
require_once(DIR."/lib/PHPExcel/IOFactory.php");

echo "Step 1";
// Generate PHPExcel object
$reader=PHPExcel_IOFactory::createReader("Excel 2007");

echo "Step 2";
// Load Excel
book=book=objReader->load('./juchuu.xls');

echo "Step 3";
// Save CSV
writer=PHPExcelIOFactory::createWriter(writer=PHPExcelIOFactory::createWriter(book, 'csv');
$writer->save('./juchuu3.csv');?>**

What you can't do (result)

  • Step 2
  • Of course, the csv file is not saved either.

What would you like to know

What's wrong?

Reference Articles

Convert xls files to CSV in PHPExcel - Qiita

php csv excel

2022-09-30 19:56

1 Answers

Cubick has already commented, but in PHPExcel,

PHPExcel last version, 1.8.1, was released in 2015. The project was officially prepared in 2017 and permanently archived in 2019.

The project has not been maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or another alternative.

So I think you should follow it.

$reader=PHPExcel_IOFactory::createReader("Excel 2007");

For now, Excel 2007 is the so-called .xlsx format. If you are dealing with the .xls format, you must specify Excel5.The Qiita article also says so.

(By the way, there is no room for u in spelling because key)


2022-09-30 19:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.