【发布时间】:2016-08-09 19:20:24
【问题描述】:
我目前在一个系统中工作,该系统早在我进入这家公司之前就建立在 symfony 1.4 上。
我正在尝试修改强制下载 excel 的功能,但我无法确定内容的设置位置。我的假设是它以某种方式抓取了整个 '$this' 对象?
我看到了标题:
$this->getResponse()->setHttpHeader('Content-Disposition', 'filename=winners.xls');
$this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
我看到这个函数被调用了:
$this->setLayout('none');
其他所有内容都是传递给视图的变量。
我只需要能够引用正在发送以供下载的内容,以便我可以通过 PHPExcel 运行它。
知道如何引用正在发送的内容吗?
更新:这是整个函数
$round = $request->getParameter("round");
$league = $request->getParameter("league");
$this->all_contest_ids = array();
$contest = asPickem::getInstance()->getContest();
// find all child contest ids
$this->all_contest_ids[] = $contest->getId();
if ($contest->getNode()->hasChildren()) {
foreach ($contest->getNode()->getDescendants() as $child) {
$this->all_contest_ids[] = $child->getId();
}
}
if (!$round || $round == "-1") {
$tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankUserOverall';
$query = Doctrine_Core::getTable($tablename)->getRankingsQuery(asPickem::getInstance()->getContest()->getId(), $this->getExcludedUserEntryIds());
$this->title = "Overall Rankings";
} // show round results
else {
if (isset($league)) {
$tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankLeagueUser';
$query = Doctrine_Core::getTable($tablename)->getRankingsQuery($league, $round);
} else {
$tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankUser';
$query = Doctrine_Core::getTable($tablename)->getRankingsQuery(asPickem::getInstance()->getContest()->getId(), $round, $this->getExcludedUserEntryIds($this->round));
}
$r = Doctrine_Core::getTable('CampaignRound')->find($round);
$this->title = $r->getView() . " Rankings";
}
$limit = $request->getParameter("limit", 100);
if ($limit > 0) {
$query->limit($limit);
}
$this->rankings = $query->execute();
// load survey questions
$survies = array();
$thisSurvies = Doctrine_Core::getTable('Survey')->getByContest(asPickem::getInstance()->getContest()->getId());
foreach ($thisSurvies as $survey) {
$survies[] = $survey;
}
// if this contest is a child of a portal then include the parent surveys
$c = asPickem::getInstance()->getContest();
while ($c->getParent()) {
$c = $c->getParent();
if ($c->getProduct()->getSlug() == 'portal') {
$this->includeParentSurveyQuestions = true;
break;
}
}
if ($this->includeParentSurveyQuestions) {
$contest = asPickem::getInstance()->getContest();
while ($contest->getParent()) {
$contest = $contest->getParent();
$parentSurvies = Doctrine_Core::getTable('Survey')->getByContest($contest->getId());
foreach ($parentSurvies as $survey) {
$survies[] = $survey;
}
}
}
$this->questions = array();
foreach ($survies as $survey) {
foreach ($survey->getSortedQuestions() as $question) {
$this->questions[$question->getId()] = $question->getQuestionText();
}
}
unset($survies);
$temp = tempnam(sys_get_temp_dir(), 'html');
file_put_contents($temp, $this->getResponse()->getTemplate());
//build instance of PHPExcel object, and load/read html file
require_once dirname(__FILE__) . '/../../../../../EXCEL/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML');
$excelHTMLReader->loadIntoExisting($temp, $objPHPExcel);
$objPHPExcel->getActiveSheet()->setTitle('userlist');
//delete the temporary file
unlink($temp);
$this->getResponse()->setHttpHeader('Content-Disposition', 'filename=winners.xls');
$this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$this->renderText($writer->save('php://output'));
$this->setLayout('none');
【问题讨论】:
标签: php phpexcel symfony-1.4