2017-07-10 8 views
1

は私がPHPEXCELのエクスポートがkohanaでExcelのマシンコードを表示する方法を教えてください。

require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php'; 

    $objPHPExcel = new PHPExcel(); 
    $objPHPExcel->setActiveSheetIndex()->setCellValue('A1', 'Hello world!'); 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 

    $this->response->body($objWriter->save('php://output')); 
    $this->response->send_file(TRUE, '01simple.xls'); 
    exit; 

のようなエラーがようようになって、このコードを試してみましたが、画像次 enter image description here

+0

これはマシンコードではありませんが、間違ってエンコードされたテキスト:) – Akam

答えて

0

あなたはこれを試してみてくださいでした...そのはのために働いて

require_once dirname(__FILE__) . '/../../vendor/PHPExcel/Classes/PHPExcel.php'; 
$phpExcel = new PHPExcel(); 
$phpExcel->getActiveSheet()->setTitle("Title of my excel"); 
$phpExcel->setActiveSheetIndex(0); 
$phpExcel->getActiveSheet()->SetCellValue('A1', 'Hello'); 
$filename = "file_name"; 
ob_clean(); 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"'); 
header('Cache-Control: max-age=0'); 
$objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007'); 
ob_end_clean(); 
$objWriter->save('php://output'); 
+0

ありがとう。私はあなたのコードを含みます。結果は「このサイトには到達できません」のようになります –

+0

このコードのみで別のファイルを作成してください。 'require_once'に正しいパスを与えて、それをテストしてください.... :) –

+0

ありがとう。 kohanaのバージョンの問題があれば。 –

0

このメソッドを使用し私。 1つの変数にコンテンツを設定して割り当てます。ここに私が例を挙げた

  require_once APPPATH.'libraries/reader/PHPExcel.php'; 
      $objPHPExcel = new PHPExcel(); 
      $reportHtml = '<table cellpadding="0" cellspacing="0" class="table table-bordered" style="border:1px solid #f0f0f0;"> 
      <thead> 
       <tr> 
        <th>Customer Name</th> 
        <th>Email</th> 
        <th>Mobile</th> 
        <th>Invoice Id</th> 
        <th>Invoice Date</th> 
        <th>Due Date</th> 
        <th>Balance Amount</th> 
        <th>Total Amount</th> 
       </tr> 
      </thead>'; 
      // Put the html into a temporary file 
      $tmpfile = time().'.html'; 
      file_put_contents($tmpfile, $reportHtml); 
      // Read the contents of the file into PHPExcel Reader class 
      $reader = new PHPExcel_Reader_HTML; 
      $content = $reader->load($tmpfile); 
      // Pass to writer and output as needed 
      header("Cache-Control: private", false); 
      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
      header('Content-Disposition: attachment;filename=test_1'.time().'.xlsx'); 
      header('Cache-Control: max-age=0'); 
      $objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007'); 
      $objWriter->save('php://output'); 
      unlink($tmpfile); 
+0

ありがとうございます。 kohanaフレームワークでのみ読み込みに問題があります。フレームの良い側の作業側で良い。私はコナナフレームワークコードを与えるplz。 –

+0

私はコナナフレームワークを知っています。私はちょうどそれをGoogleと私はいくつかの例がある。私はその仕事の仕方を知っている。 Uちょうどそれを通り抜ける https://github.com/katan/kohana-phpexcel –

+0

リンクhttps://github.com/katan/kohana-phpexcel –

関連する問題