我无法将表导出到excel中

时间:2017-02-01 12:39:41

标签: php excel phpexcel

我正在使用phpExcel库来表export。我尝试了excelexport插件,但在我的情况下失败了。

打印时output看起来像这样

my jun k 输出https://jsfiddle.net/80gzzp4a/

  

我在服务器上运行代码
   我正在将表存入

$ _ SESSION

这是我的代码

<?php

include('../connectmssql.php');
$obj = new SqlDB(); 
error_reporting(E_ALL);
ini_set('display_errors', 1);

$filename = 'abc.xlsx';
$table = stripslashes($_SESSION["tableDataToBePrintedNowOnly"]);
require 'Classes/PHPExcel.php'; 
// save $table inside temporary file that will be deleted later
$tmpfile = tempnam(sys_get_temp_dir(), 'html');
//$tmpfile = '/tmp/' . rand(0, getrandmax()) . rand(0, getrandmax()) . ".tmp";

file_put_contents($tmpfile, $table);

// insert $table into $objPHPExcel's Active Sheet through $excelHTMLReader
$objPHPExcel     = new PHPExcel();
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML');
$excelHTMLReader->loadIntoExisting($tmpfile, $objPHPExcel);
$objPHPExcel->getActiveSheet()->setTitle('any name you want'); // Change sheet's title if you want

unlink($tmpfile); // delete temporary file because it isn't needed anymore

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // header for .xlxs file
header('Content-Disposition: attachment;filename='.$filename); // specify the download file name
header('Cache-Control: max-age=0');
?>

更新1 :现在我收到此error

  

注意:使用未定义的常量PHPEXCEL_ROOT - 假设   'PHPEXCEL_ROOT'中   C:\ HostingSpaces \ cybrainwebsites \ assessment.sahasraadvisoryagency.com \超级管理员\类\ PHPExcel \ Autoloader.php   第73行

     

致命错误:未捕获错误:类'PHPExcel_Shared_ZipStreamWrapper'   找不到   C:\ HostingSpaces \ cybrainwebsites \ assessment.sahasraadvisoryagency.com \超级管理员\类\ PHPExcel \ Autoloader.php:31   堆栈跟踪:#0   C:\ HostingSpaces \ cybrainwebsites \ assessment.sahasraadvisoryagency.com \超级管理员\ printtable.php(9):   require()#1 {main}抛出   C:\ HostingSpaces \ cybrainwebsites \ assessment.sahasraadvisoryagency.com \超级管理员\类\ PHPExcel \ Autoloader.php   在第31行

更新2 :没有错误,但excel将保持空白。

if i  echo this line  echo $table = stripslashes($_SESSION["tableDataToBePrintedNowOnly"]);

数据将如下所示:https://jsfiddle.net/4dx9utjc/1/

  

如果我不回应那么没有数据

我做错了请帮助我,提前谢谢!!

0 个答案:

没有答案