iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

How to Convert Excel to CSV in PHP

104 36
    • 1). Right-click the PHP file you want to edit and select "Open With." Click your PHP editor from the list of programs in the drop-down menu.

    • 2). Include the Excel class file header. Add the following code at the top of the PHP page:

      require_once 'reader.php';

    • 3). Open the Excel file. The following code opens the file and sets a handler you can use to iterate through each record:

      $file= new Spreadsheet_Excel_Reader();
      $file->setOutputEncoding('ASCII');
      $fild->read("file.xls");

      Replace "file.xls" in the above code with the name of your own file.

    • 4). Load all of the file's rows. The following code loads the items in the Excel file content:

      $rows= $file->sheets[0]['cells'];

    • 5). Loop through each item and create the CSV file. In the following example, the first cell in each row is written to a CSV file:

      $csv= fopen("export.csv", "w+");
      foreach($cells as $rows){
      fwrite($csv, implode(',', $row)."\n");
      }

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.