Login   Register  
PHP Classes
elePHPant
Icontem

File: demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of dbforch  >  PHP CSV XLS Converter  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: Demo script
Class: PHP CSV XLS Converter
Convert data from CSV files to Excel XLS format
Author: By
Last change: Generates a test csv file and noticing the user that PHPExcel (www.phpexcel.net) is required to run this demo.
Date: 1 year ago
Size: 748 bytes
 

Contents

Class file image Download
<?php

  
// required class
  
require_once "CSVToExcelConverter2.class.php";
  
// requires the PHPExcel library (www.phpexcel.net)
  // require_once "path/to/PHPExcel.php";

  // source csv file
  
$csv_file 'test.csv';
  
  
// create the source test csv
  
if(($fh fopen($csv_file'w+')) !== false) {
    
fputcsv($fh, array(
      array(
'Value1','Value2','Value3'),
      array(
'Value4','Value5','Value6')
    ));
    
fclose($fh);
  }
  else {
    echo 
"unable to perform demo, test csv file could not be created";
    exit();
  }
  
  
// start converting
  // xls filename will be automatically generated
  
$converter = new CSVToExcelConverter2($csv_file); 
  
$converter->skipFirstRow(false);
  
$converter->convert();