2017-05-02 14 views
0
$file = '{full path and filename}'; 

//Read file 
$file_type = PHPExcel_IOFactory::identify($file); 
$excel_reader = PHPExcel_IOFactory::createReader($file_type);    
$this->php_excel = $excel_reader->load($file);    

//Set some values 
$this->php_excel->setActiveSheetIndex(0); 
$this->php_excel->getActiveSheet()->SetCellValue('A1', 'Hello'); 
$this->php_excel->getActiveSheet()->SetCellValue('B2', 'world!'); 
$this->php_excel->getActiveSheet()->SetCellValue('C1', 'Hello'); 
$this->php_excel->getActiveSheet()->SetCellValue('D2', 'world!'); 

//Write to file new location  
$excel_writer = PHPExcel_IOFactory::createWriter($this->php_excel, 'Excel2007'); 
$excel_writer->save('c:\test.xls'); 

を保存するときにc:\test.xlsが作成されますが、私は(OpenOfficeのからではなく、私はそれは問題ではないと思う)のExcelファイルをロードしようとしているエラーを取得しています。私が読んでいるファイルは約260kbですが、作成されたtest.xlsは約64kbです。それは無効で、OpenOfficeはファイルを修復しようとします。無効なファイル形式PHPExcel

私は間違っていますか? @マークベイカーへ

+2

'Excel2007'は' .xlsx'ファイルのためのライターです。 'Excel5'は' .xls'ファイルの作者です...その違いは非常に重要です –

+0

Aha。どうもありがとうございました!それがトリックでした。 – bestprogrammerintheworld

答えて

0

おかげで私は単に私がライターを作成した行を変更することができることを考え出し:

//Given that the file that are going to be saved should be of the same 
//format that the read file has. 
$excel_writer = PHPExcel_IOFactory::createWriter($this->php_excel, $file_type); 
関連する問題