本文整理汇总了PHP中PHPExcel_IOFactory::createWriter方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_IOFactory::createWriter方法的具体用法?PHP PHPExcel_IOFactory::createWriter怎么用?PHP PHPExcel_IOFactory::createWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_IOFactory
的用法示例。
在下文中一共展示了PHPExcel_IOFactory::createWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
public function generate(array $fields, array $data, $fileName = 'excelDbDump')
{
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
// Field names in the first row
$col = 0;
foreach ($fields as $field) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
// Fetching the table data
$row = 2;
foreach ($data as $data) {
$col = 0;
foreach ($fields as $field) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->{$field});
$col++;
}
$row++;
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
// Sending headers to force the user to download the file
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $fileName . '_' . date('d-m-y') . '.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}
示例2: generate
function generate($generator)
{
require_once "PHPExcel.php";
$data = $generator->generateExportData();
$this->chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$this->charArray = str_split($this->chars, 1);
$objPHPExcel = new PHPExcel();
// set document properties
$objPHPExcel->getProperties()->setTitle("Test Data");
// create a first sheet and populate the headings
$objPHPExcel->setActiveSheetIndex(0);
// hardcoded limitation of 26 x 27 columns (right now)
$numCols = count($data["colData"]);
for ($i = 0; $i < $numCols; $i++) {
$col = $this->getExcelCol($i, 1);
$objPHPExcel->getActiveSheet()->setCellValue($col, $data["colData"][$i]);
}
for ($i = 0; $i < count($data["rowData"]); $i++) {
for ($j = 0; $j < $numCols; $j++) {
$col = $this->getExcelCol($j, $i + 2);
$objPHPExcel->getActiveSheet()->setCellValue($col, $data["rowData"][$i][$j]);
}
}
// redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
示例3: actionExportExcel
public function actionExportExcel()
{
$model = new Reporte();
$evento_id = $_POST['Report']['evento_id'];
$sector_id = $_POST['Report']['sector_id'];
$subsector_id = $_POST['Report']['subsector_id'];
$rama_actividad_id = $_POST['Report']['rama_actividad_id'];
$actividad_id = $_POST['Report']['actividad_id'];
$dataReporte = $model->search($evento_id, $sector_id, $subsector_id, $rama_actividad_id, $actividad_id);
$objExcel = new PHPExcel();
$objExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Nombre')->setCellValue('B1', 'Cédula')->setCellValue('C1', 'Celular')->setCellValue('D1', 'Teléfono')->setCellValue('E1', 'E-mail')->setCellValue('F1', 'Dirección')->setCellValue('G1', 'Sector')->setCellValue('H1', 'Subsector')->setCellValue('I1', 'Rama de Actividad')->setCellValue('J1', 'Actividad');
$id = 2;
foreach ($dataReporte as $Reporte) {
$objExcel->setActiveSheetIndex(0)->setCellValue('A' . $id, $Reporte['nombre_completo'])->setCellValue('B' . $id, $Reporte['cedula'])->setCellValue('C' . $id, $Reporte['celular'])->setCellValue('D' . $id, $Reporte['telefono'])->setCellValue('E' . $id, $Reporte['email'])->setCellValue('F' . $id, $Reporte['direccion'])->setCellValue('G' . $id, $Reporte['sector'])->setCellValue('H' . $id, $Reporte['subsector'])->setCellValue('I' . $id, $Reporte['rama_actividad'])->setCellValue('J' . $id, $Reporte['actividad']);
$id++;
}
for ($i = 'A'; $i <= 'O'; $i++) {
$objExcel->setActiveSheetIndex(0)->getColumnDimension($i)->setAutoSize(TRUE);
}
$objExcel->getActiveSheet()->setTitle('ReporteParticipantes');
//// Se activa la hoja para que sea la que se muestre cuando el archivo se abre
$objExcel->setActiveSheetIndex(0);
//
//// Inmovilizar paneles
$objExcel->getActiveSheet(0)->freezePane('A4');
$objExcel->getActiveSheet(0)->freezePaneByColumnAndRow(1, 2);
// Se manda el archivo al navegador web, con el nombre que se indica, en formato 2007
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="ReporteParticipantes.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
示例4: get_comments_xls
function get_comments_xls($filename, $cons)
{
require_once TEMPLATEPATH . '/app/PHPExcel.php';
global $wpdb;
$sql = "SELECT post_title,comment_ID,comment_author, comment_date_gmt, comment_content\n\t\t\tFROM {$wpdb->comments}\n\t\t\t\tLEFT OUTER JOIN {$wpdb->posts} ON ({$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID)\n\t\t\t\tINNER JOIN {$wpdb->term_relationships} as r1 ON ({$wpdb->posts}.ID = r1.object_id)\n\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} as t1 ON (r1.term_taxonomy_id = t1.term_taxonomy_id)\n\t\t\tWHERE comment_approved = '1'\n\t\t\t\tAND comment_type = ''\n\t\t\t\tAND post_password = ''\n\t\t\t\tAND t1.taxonomy = 'category'\n\t\t\t\tAND t1.term_id = " . $cons . "\n\t\t\torder by comment_date_gmt";
$qr = $wpdb->get_results($sql, ARRAY_N);
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Consultator")->setLastModifiedBy("Consultator")->setTitle("Consultator")->setSubject("Consultator")->setDescription("Αρχείο Εξαγωγής Σχολίων")->setKeywords("Σχόλια")->setCategory("Αρχείο Σχολίων");
// Add some data // Headers
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Άρθρο')->setCellValue('B1', 'Κωδικός Σχολίου')->setCellValue('C1', 'Σχολιαστής')->setCellValue('D1', 'Ημερομηνία Υποβολής')->setCellValue('E1', 'Σχόλιο');
$objPHPExcel->getActiveSheet()->fromArray($qr, NULL, 'A2');
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Σχόλια Διαβούλευσης');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
exit;
}
示例5: createExcel
function createExcel($no_telp, $npwd)
{
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Disyanjak Bandung")->setLastModifiedBy("Disyanjak Bandung")->setTitle("Daftar SMS")->setSubject("Daftar SMS")->setDescription("Daftar SMS untuk ke WP")->setKeywords("office PHPExcel php")->setCategory("Test result file");
$objPHPExcel->getActiveSheet()->getStyle('A2')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER);
// Add some data
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Phone No.')->setCellValue('A2', $no_telp);
//$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1);
//$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld");
//$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
//$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Daftar SMS');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$fileName = 'send_sms_' . $npwd;
$objWriter->save($fileName . '.xlsx');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($fileName . '.xls');
return $fileName;
}
示例6: create
function create()
{
//load our new PHPExcel library
$this->load->library('excel');
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
//name the worksheet
$this->excel->getActiveSheet()->setTitle('test worksheet');
//set cell A1 content with some text
$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
//change the font size
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
//make the font become bold
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
//merge cell A1 until D1
$this->excel->getActiveSheet()->mergeCells('A1:D1');
//set aligment to center for that merged cell (A1 to D1)
$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$filename = 'just_some_random_name.xls';
//save our workbook as this file name
header('Content-Type: application/vnd.ms-excel');
//mime type
header('Content-Disposition: attachment;filename="' . $filename . '"');
//tell browser what's the file name
header('Cache-Control: max-age=0');
//no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
}
示例7: test_read_write_excel
public function test_read_write_excel()
{
$inputFileName = 'print_docs/excel/excel_template/KEMSA Customer Order Form.xlsx';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
// echo "$inputFileType";die;
$file_name = time() . '.xlsx';
$excel2 = PHPExcel_IOFactory::createReader($inputFileType);
$excel2 = $objPHPExcel = $excel2->load($inputFileName);
// Empty Sheet
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$excel2->setActiveSheetIndex(0);
$excel2->getActiveSheet()->setCellValue('H4', '4')->setCellValue('H5', '5')->setCellValue('H6', '6')->setCellValue('H7', '7')->setCellValue('H8', '7');
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++) {
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
if (isset($rowData[0][2]) && $rowData[0][2] != 'Product Code') {
$excel2->getActiveSheet()->setCellValue("H{$row}", '7');
}
}
$objWriter = PHPExcel_IOFactory::createWriter($excel2, $inputFileType);
$objWriter->save("print_docs/excel/excel_files/" . $file_name);
}
示例8: run
public static function run($debug = false, $mailOut = true)
{
try {
self::$_debug = $debug;
if ($debug) {
echo '<pre>';
}
$objPHPExcel = self::_getOutput();
if (!$objPHPExcel instanceof PHPExcel) {
throw new Exception('System Error: can NOT generate CSV without PHPExcel object!');
}
// Set document properties
$filePath = self::$_rootDir . '/' . md5(new UDate()) . '.csv';
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter(',')->setEnclosure('"')->setLineEnding("\r\n")->setSheetIndex(0);
ob_start();
$objWriter->save('php://output');
$excelOutput = ob_get_clean();
$class = get_called_class();
$asset = Asset::registerAsset($class::_getAttachedFileName(), $excelOutput, Asset::TYPE_TMP);
if ($mailOut === true) {
self::_mailOut($asset);
}
return $asset;
} catch (Exception $ex) {
echo $ex->getMessage();
die('ERROR!');
}
}
示例9: footer
protected function footer($objPHPExcel, $start, $file_name, $format, $html_title)
{
$start++;
$jemaat = get_jemaat_from_user_id(Yii::app()->user->getId());
$objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Dicetak oleh: " . $jemaat->real_name);
$start++;
$objPHPExcel->setActiveSheetIndex(0)->mergeCells("A{$start}:G{$start}")->setCellValue("A{$start}", "Pada tanggal " . get_date_today('dd/MM/yyyy') . " jam " . get_time_now());
ob_end_clean();
ob_start();
if ($format == 'excel') {
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename={$file_name}.xls");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
} else {
$objPHPExcel->getActiveSheet()->setShowGridlines(false);
$mPDF1 = Yii::app()->ePdf->mpdf();
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A4');
$objWriter = new PHPExcel_Writer_HTML($objPHPExcel);
$header = $objWriter->generateHTMLHeader(true);
$header = str_replace("<body>", "<body onload='window.print();'>", $header);
$header = str_replace("Untitled Spreadsheet", $html_title, $header);
$html = $header . $objWriter->generateStyles(true) . $objWriter->generateSheetData() . $objWriter->generateHTMLFooter();
if ($format == 'pdf') {
$mPDF1->WriteHTML($html);
$mPDF1->Output('MutasiKasDitangan.pdf', 'D');
} else {
echo $html;
}
}
}
示例10: run
public function run($args)
{
Yii::import('application.components.PHPExcel.PHPExcel.PHPExcel_IOFactory');
Yii::import('application.modules.store.models');
$inputFileName = Yii::getPathOfAlias('application.components.spreadsheetReader.translates') . '/' . 'cargotogo_products.xlsx';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($inputFileName);
$db = \Yii::app()->db;
$max_id = $db->createCommand()->select('MAX(id)')->from('site_store_product')->queryScalar();
$row = 1;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Наименование')->setCellValue('B1', 'Ссылка')->setCellValue('C1', 'Регион')->setCellValue('D1', 'Название подраздела')->setCellValue('E1', 'Ссылка на подраздел ')->setCellValue('F1', 'Название раздела (верхний уровень)')->setCellValue('G1', 'Название раздела (второй уровень)')->setCellValue('H1', 'Ссылка на раздел (второй уровень)');
$row++;
$data = [];
for ($i = 1; $i <= $max_id; $i++) {
$db->setActive(true);
$product = $db->createCommand()->select('id, name, slug, category_id')->from('site_store_product')->where('id=' . $i)->queryRow();
if (!empty($product)) {
echo $product['id'] . "\n";
$region = $db->createCommand()->select('value')->from('site_store_product_attribute_eav')->where('product_id=' . $product['id'] . ' AND attribute="adres_name"')->queryRow();
if (!empty($product['category_id'])) {
$category = $db->createCommand()->select('id, slug, parent_id, name_ru')->from('site_store_category')->where('id=' . $product['category_id'])->queryRow();
}
$data = ['name' => $product['name'], 'link' => 'http://cargotogo.com/store/show/' . $product['slug'], 'region' => isset($region) ? $region['value'] : '', 'sub_category_name' => isset($category) ? $category['name_ru'] : '', 'sub_category_link' => isset($category) ? 'http://cargotogo.com/store/' . $this->getParentStoreCategoriesLink($category, $db) : '', 'main_category_name' => isset($category) ? $this->getMainStoreCategoryName($category, $db) : '', 'second_category_name' => isset($category) ? $this->getSecondStoreCategoryName($category, $db) : '', 'second_category_link' => isset($category) ? 'http://cargotogo.com/store/' . $this->getSecondStoreCategoryLink($category, $db) : ''];
$objPHPExcel->getActiveSheet()->setCellValue('A' . $row, $data['name'])->setCellValue('B' . $row, $data['link'])->setCellValue('C' . $row, $data['region'])->setCellValue('D' . $row, $data['sub_category_name'])->setCellValue('E' . $row, $data['sub_category_link'])->setCellValue('F' . $row, $data['main_category_name'])->setCellValue('G' . $row, $data['second_category_name'])->setCellValue('H' . $row, $data['second_category_link']);
$row++;
}
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($inputFileName);
}
示例11: exportToExcel
/**
* @brief 将数组导出成为excel文件记录
*
* @param array $data 数组,数组的第一个元素是数组的相关模板信息
* @param string $type 导出的excel文件类型
* @return public function
* @retval
* @see
* @note
* @author 吕宝贵
* @date 2016/01/02 23:46:49
**/
public function exportToExcel(array $data, array $meta, $type = 1)
{
//字符集转换,excel使用gbk字符集
array_walk($meta, [$this, 'convertToGBK']);
$this->objPHPExcel->getProperties()->setCreator($meta['author'])->setLastModifiedBy($meta['modify_user'])->setTitle($meta['title'])->setSubject($meta['subject'])->setDescription($meta['description'])->setKeywords($meta['keywords'])->setCategory($meta['category']);
$this->objPHPExcel->setActiveSheetIndex(0);
$objActiveSheet = $this->objPHPExcel->getActiveSheet();
$objActiveSheet->setTitle($meta['title']);
$columnCount = count($data[0]);
$rowIndex = 1;
foreach ($data as $payable) {
//Excel的第A列,uid是你查出数组的键值,下面以此类推
$currentCharAscii = 64;
for ($columnIndex = 0; $columnIndex < $columnCount; $columnIndex++) {
$currentCharAscii += 1;
$objActiveSheet->setCellValueExplicit(chr($currentCharAscii) . $rowIndex, $payable[$columnIndex], \PHPExcel_Cell_DataType::TYPE_STRING);
}
$rowIndex += 1;
}
$filename = $meta['filename'];
$this->objPHPExcel->getActiveSheet()->setTitle('明细记录');
$this->objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel5');
$objWriter->save('php://output');
return true;
}
示例12: actionDownload
/**
* This function will handle the download Action
* This takes three parameters and generated the excel file
* @coupontype : This parameter will hold the value of coupon type [deal=>1 | coupon=>0]
* @store : This parameter will hold the value of website ID
* @category : This parameter will hold the value of category ID
* @return filtered coupons to search view
*/
public function actionDownload($couponType, $Stores, $Category)
{
$coupontype = $_GET['couponType'];
$store = isset($_GET['Stores']) ? $_GET['Stores'] : "all";
$category = isset($_GET['Category']) ? $_GET['Category'] : "all";
$coupons = $this->extractData(Coupon::find(), $category, $store, $category);
$excel = new PHPExcel();
$excel->getActiveSheet()->setCellValue('B1', "Title")->setCellValue('C1', "Website Name")->setCellValue('D1', "Coupon Code")->setCellValue('E1', "Description");
$i = 2;
foreach ($coupons as $coupon) {
$excel->getActiveSheet()->setCellValue('B' . $i, $coupon->Title)->setCellValue('C' . $i, $coupon->website->WebsiteName)->setCellValue('D' . $i, $coupon->CouponCode)->setCellValue('E' . $i, $coupon->Description);
$i++;
}
// Naming the active spread sheet
$excel->getActiveSheet()->setTitle('List Of Coupons');
$excel->setActiveSheetIndex(0);
// Redirect output to a clients web browser (Excel5)
header('Cache-Control: max-age=0');
$objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
// It will be called file.xls
header('Content-Disposition: attachment; filename="result.xls"');
// Write file to the browser
$objWriter->save('php://output');
}
示例13: downloadExcelFileByArray
public static function downloadExcelFileByArray($data, $fileName = '')
{
self::prepare();
if (!$fileName) {
$fileName = 'xls-download-' . date('Y-m-d-H-i-s') . '.xls';
}
$objPHPExcel = new \PHPExcel();
$objPHPExcel->getActiveSheet()->fromArray($data);
$objPHPExcel->getActiveSheet()->freezePane('A2');
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $fileName . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// always modified
header('Cache-Control: cache, must-revalidate');
// HTTP/1.1
header('Pragma: public');
// HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
示例14: exportExcel
public function exportExcel($objPHPExcel, $versionExcel = '', $fileName = '')
{
//2003 use 'Excel5'
$extFile = $versionExcel == 'Excel2007' ? ".xlsx" : ".xls";
if ($fileName == "") {
$fileName = date("yMdhis") . $extFile;
}
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $fileName . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// always modified
header('Cache-Control: cache, must-revalidate');
// HTTP/1.1
header('Pragma: public');
// HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $versionExcel);
$objWriter->save('php://output');
exit;
}
示例15: export
public function export($content, $title = '报表', $SavePath = null)
{
$objPHPExcel = $this->objPHPExcel;
// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("Office 2003 XLSX Test Document")->setSubject("Office 2003 XLSX Test Document")->setDescription("Test document for Office 2003 XLSX, generated using PHP classes.")->setKeywords("office 2003 openxml php")->setCategory("Test result file");
// Set default font
$objPHPExcel->getDefaultStyle()->getFont()->setName('宋体');
$objPHPExcel->getDefaultStyle()->getFont()->setSize(12);
// Add some data, resembling some different data types
$trid = 1;
foreach ($content as $tr) {
$tdtotal = 0;
foreach ($tr as $td) {
$tdid = intval($tdtotal / 26) >= 1 ? chr(ord('A') + intval($tdtotal / 26) - 1) . chr(ord('A') + $tdtotal % 26) : chr(ord('A') + $tdtotal % 26);
$objPHPExcel->getActiveSheet()->setCellValue($tdid . $trid, $td);
$tdtotal++;
}
$trid++;
}
//Set Width
for ($i = 0; $i < $tdtotal; $i++) {
$tdid = intval($i / 26) >= 1 ? chr(ord('A') + intval($i / 26) - 1) . chr(ord('A') + $i % 26) : chr(ord('A') + $i % 26);
$objPHPExcel->getActiveSheet()->getColumnDimension($tdid)->setWidth(12);
}
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle($title);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2003 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$SavePath = $SavePath ? $SavePath : ROOT_PATH . '/sites/3i/data/' . date('YmdHis') . '.xls';
$objWriter->save($SavePath);
return $SavePath;
}