0

我需要编写一些 xls(x) 文件,但不知道 Kohana 3.2.2 框架的良好扩展(模块),我知道 PHPExcel(我找到了很多链接和存储库),但其中大部分基于在我的项目中不支持的 PEAR 库上,也许有人知道一个好的解决方案?

所以我需要一个带有良好文档和模块的链接。谢谢。

升级版

我通过以下代码对 PHPExcel 库进行了第一次测试:

$objPHPExcel = new PHPExcel();
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Hello')
                ->setCellValue('B1', 'world!');

            // header("Content-Type:application/vnd.ms-excel");
            // header("Content-Disposition:attachment;filename='simple.xls'");

            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');    
            $name = $objWriter->save('docs/MyExcel12.xlsx');

            $file = $_SERVER['DOCUMENT_ROOT']."/docs/MyExcel12.xlsx";
            /*      
            if (file_exists($file))
            {
                header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                header('Content-Disposition: attachment; filename='.basename($file));
                header('Content-Length: '.filesize($file));
                readfile($file);                
            }*/

            if (file_exists($file))
            {
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename='.basename($file));
                header('Content-Length: '.filesize($file));
                readfile($file);
            }

我看到应用此代码后创建的文件,但浏览器没有强制下载它,因为你可以看到我使用了不同的标题,但没有我的文件。帮助!?

UPD我也使用过:

            header("Content-Type:application/vnd.ms-excel");
            header("Content-Disposition:attachment;filename='simple.xls'");

            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel5');   
            $objWriter->save('php://output');

但是有错误(而不是文件):

net::ERR_FILE_NOT_FOUND

我做了一个重定向,但我认为这不是一个解决方案:

    $this->request->redirect('docs/new.xlsx');
4

1 回答 1

1

将 PHPExcel 集成到 Kohana http://www.flynsarmy.com/2010/07/phpexcel-module-for-kohana-3/

于 2013-02-16T19:28:04.043 回答