Excel/CSV 내보내기 옵션을 CakePHP 웹 사이트와 통합하고 싶습니다. 사용 가능한 구성 요소 나 도우미에 대해 알고 싶습니까?cakephp excel/csv 내보내기 구성 요소
감사합니다.
Excel/CSV 내보내기 옵션을 CakePHP 웹 사이트와 통합하고 싶습니다. 사용 가능한 구성 요소 나 도우미에 대해 알고 싶습니까?cakephp excel/csv 내보내기 구성 요소
감사합니다.
이 솔루션은 유는 1 단계
CakePHP는 1.3에 통합 할 수 있습니다 .. CakePHP는 2.0입니다 : /보기/도우미 디렉토리의 앱에 Csv.php로 다음 파일을 저장
<?php
class CsvHelper extends AppHelper
{
var $delimiter = ',';
var $enclosure = '"';
var $filename = 'Export.csv';
var $line = array();
var $buffer;
function CsvHelper()
{
$this->clear();
}
function clear()
{
$this->line = array();
$this->buffer = fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+');
}
function addField($value)
{
$this->line[] = $value;
}
function endRow()
{
$this->addRow($this->line);
$this->line = array();
}
function addRow($row)
{
fputcsv($this->buffer, $row, $this->delimiter, $this->enclosure);
}
function renderHeaders()
{
header('Content-Type: text/csv');
header("Content-type:application/vnd.ms-excel");
header("Content-disposition:attachment;filename=".$this->filename);
}
function setFilename($filename)
{
$this->filename = $filename;
if (strtolower(substr($this->filename, -4)) != '.csv')
{
$this->filename .= '.csv';
}
}
function render($outputHeaders = true, $to_encoding = null, $from_encoding ="auto")
{
if ($outputHeaders)
{
if (is_string($outputHeaders))
{
$this->setFilename($outputHeaders);
}
$this->renderHeaders();
}
rewind($this->buffer);
$output = stream_get_contents($this->buffer);
if ($to_encoding)
{
$output = mb_convert_encoding($output, $to_encoding, $from_encoding);
}
return $this->output($output);
}
}
?>
2 단계 : 컨트롤러에이 도우미를 추가
var $helpers = array('Html', 'Form','Csv');
3 단계 : 예에 대한 컨트롤러의 방법 "다운로드"를 만들 수 있습니다. homes_controller.php
<?php
function download()
{
$this->set('orders', $this->Order->find('all'));
$this->layout = null;
$this->autoLayout = false;
Configure::write('debug', '0');
}
?>
4 단계 :보기에이 코드를 넣어 5 (최종 단계)
/주택 : 당신이 CSV
<?php
echo $this->Html->link('Download',array('controller'=>'homes','action'=>'download'), array('target'=>'_blank'));
?>
단계를 다운로드해야 할 곳에서 페이지의 링크를 넣어 /download.ctp
<?php
$line= $orders[0]['Order'];
$this->CSV->addRow(array_keys($line));
foreach ($orders as $order)
{
$line = $order['Order'];
$this->CSV->addRow($line);
}
$filename='orders';
echo $this->CSV->render($filename);
?>
최근에는 XLS 및 CSV로 데이터를 내보내는 데 필요한 일부 프로젝트에서 작업했습니다. 이 헬퍼는 정말 좋은 일 :
http://bakery.cakephp.org/articles/ifunk/2007/09/10/csv-helper-php5
http://bakery.cakephp.org/articles/wasenbr/2007/04/12/excel-xls-helper
우리는 몇 가지 옵션 선택과 함께 모두 가져올 수없는 경우에만 , 당신이 CSV 또는 엑셀을 원 하든지, 오히려 두 개의 분리 된 lpers? –
CakePHP를 내 PHPExcel 사용에 대한 the bakery에있는 기사가있다. 이 라이브러리는 스프레드 시트 데이터를 다양한 형식으로 작성하기위한 옵션을 제공합니다. 링크 된 제과점 기사에 제공된 예제는 xls 및 xlsx 파일 용이지만 csv도 옵션입니다.
필요 없음 모든 구성 요소 또는 도우미
큰 튜토리얼 http://andy-carter.com/blog/exporting-data-to-a-downloadable-csv-file-with-cakephp
컨트롤러
public function export() {
$this->response->download("export.csv");
$data = $this->Subscriber->find('all');
$this->set(compact('data'));
$this->layout = 'ajax';
return;
}
route.php
Router::parseExtensions('csv');
export.ctp 파일
<?php
app/Views/Subscribers/export.ctp
foreach ($data as $row):
foreach ($row['Subscriber'] as &$cell):
// Escape double quotation marks
$cell = '"' . preg_replace('/"/','""',$cell) . '"';
endforeach;
echo implode(',', $row['Subscriber']) . "\n";
endforeach;
?>
http : // andy-carter라는 원본 저자의 글을 잊어 버렸습니다.co.kr/blog/exporting-data-to-a-downloadable-csv-file-with-cakephp – rocknrollcanneverdie
안녕하세요. 모든 것이 잘 작동하고 localhost가 좋지만 온라인으로 접속하려고한다면 다운로드 팝업을받을 수 없지만 브라우저 자체에 데이터가 표시됩니다. 제발 어떤 해결책을 제안 해주세요. –
내 보낸 데이터를 Excel 코드로 가져 오는 중 .. 그 코드 아래에 원하는 데이터 목록이 있습니다. 어떤 도움도 왜 파일에 내보내기 코드가 ?? –
cakephp 3에서 작동합니까? – Faisal