简体   繁体   中英

Open excel file using PHPExcel and save it to a folder

I am trying to make a PHP file to run online (eg http://www.writephponline.com/ and alternatively I can use PUTTY). This script will get an excel file from a link. Then it will save it to a folder (given link). It seems that there is an error.

include 'my_link/Classes/PHPExcel.php';
$inputFileName = 'FILE_NAME';

$reader = new PHPExcel_Reader_Excel2007;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$reader = PHPExcel_IOFactory::createReader($inputFileType);
$workbook =  $reader->load($file);

$objWriter = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007'); 
$objWriter->save('FOLDER_NAME'); 

exit(); 

The error is :

01) Class 'PHPExcel_Reader_Excel2007' not found

UPD:

I even tried that :

require_once('apolosiskos.co.uk/Classes/PHPExcel.php');
require_once('apolosiskos.co.uk/Classes/IOFactory.php'); 
require_once('apolosiskos.co.uk/Classes/Excel2007.php');

$fileType=PHPExcel_IOFactory::identify("FILE.xlsx");
$objReader = PHPExcel_IOFactory::createReader("Excel2007");

$objReader->setReadDataOnly(true);   
$objPHPExcel = $objReader->load("FILE.xlsx");
$objWriter->save("http://apolosiskos.co.uk/output.xlsx");

and I got :

02) PHPExcel_IOFactory

I have included the source though and I don't know why it is not working. Is there a public link for PHPExcel.php so I can test?

Alternatively you can read your file like this;

$reader = PHPExcel_IOFactory::createReaderForFile($inputFileName);
$reader->setReadDataOnly(true);
$workbook = $reader->load($inputFileName);

Unless you have special reason for choosing to use PHPExcel_Reader_Excel2007

You can't require fully qualified php files from a server, it expects a file.

Right now your require is just getting the output of the files you are including, as it is making a request to that URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM