本文整理汇总了PHP中PHPExcel::createSheet方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel::createSheet方法的具体用法?PHP PHPExcel::createSheet怎么用?PHP PHPExcel::createSheet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel
的用法示例。
在下文中一共展示了PHPExcel::createSheet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: payQuickerReport
public function payQuickerReport()
{
$market = array(1 => 'US', 2 => 'CA', 3 => 'AU', 4 => 'NZ', 5 => 'GB');
// error_reporting(E_ALL);
$data = $this->RoyaltiesEarned->getRoyaltiesReport(3, ['method' => 'all']);
// echo '<pre>';
// print_r($data);
// echo '</pre>';
// die;
// for ($i = 0; $i <= $queryCount; $i = $i + $this->payQuickerReportLimit) {
//
// }
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("");
$objPHPExcel->getProperties()->setLastModifiedBy("");
$objPHPExcel->getProperties()->setTitle("");
$objPHPExcel->getProperties()->setSubject("");
$objPHPExcel->getProperties()->setDescription("");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Instructions');
// Add some data
$objPHPExcel->createSheet(1);
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setTitle('Instant Payments');
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'INSTANT PAYMENTS');
$objPHPExcel->getActiveSheet()->SetCellValue('A2', "RECIPIENT'S EMAIL ADDRESS\n * Required!");
$objPHPExcel->getActiveSheet()->SetCellValue('B2', "PAYMENT AMOUNT\n * Required");
$objPHPExcel->getActiveSheet()->SetCellValue('C2', "COUNTRY CODE\n * Required");
$objPHPExcel->getActiveSheet()->SetCellValue('D2', "STATE CODE\n * Required");
$objPHPExcel->getActiveSheet()->SetCellValue('E2', "COMMENT\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('F2', "SECURITY ID\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('G2', "SECURITY ID HINT\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('H2', "ACCOUNTING ID\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('I2', "EXPIRATION DATE\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('J2', "UDF1\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('K2', "UDF2\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('L2', "UDF3\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('M2', "AUTO ISSUE DEBIT CARDS\n Optional");
$objPHPExcel->getActiveSheet()->SetCellValue('N2', "EXCLUDE FROM 1099 RECONCILIATION\n Optional");
// Add data
for ($i = 0; $i < count($data); $i++) {
$cell = $i + 3;
$objPHPExcel->getActiveSheet()->setCellValue('A' . $cell, $data[$i]['Email']['email'])->setCellValue('B' . $cell, $data[$i]['RoyaltiesEarned']['amount'])->setCellValue('C' . $cell, $market[$data[$i]['RoyaltiesEarned']['market_id']])->setCellValue('D' . $cell, $data[$i]['State']['abbrev'])->setCellValue('D' . $cell, $data[$i]['State']['abbrev'])->setCellValue('E' . $cell, $data[$i]['User']['first_name'])->setCellValue('M' . $cell, 'YES');
}
$objPHPExcel->createSheet(2);
$objPHPExcel->setActiveSheetIndex(2);
$objPHPExcel->getActiveSheet()->setTitle('Version');
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Version');
$objPHPExcel->getActiveSheet()->SetCellValue('A2', '816eda7a-db7a-4c83-adeb-206bdfad2bb0');
// Save Excel 2007 file
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
// 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="file.xls"');
// Write file to the browser
// $objWriter->save('php://output');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
}
示例2: load
//.........这里部分代码省略.........
// Set base date
if ($xmlWorkbook->workbookPr) {
PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
if (isset($xmlWorkbook->workbookPr['date1904'])) {
$date1904 = (string)$xmlWorkbook->workbookPr['date1904'];
if ($date1904 == "true" || $date1904 == "1") {
PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904);
}
}
}
$sheetId = 0; // keep track of new sheet id in final workbook
$oldSheetId = -1; // keep track of old sheet id in final workbook
$countSkippedSheets = 0; // keep track of number of skipped sheets
$mapSheetId = array(); // mapping of sheet ids from old to new
if ($xmlWorkbook->sheets)
{
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
++$oldSheetId;
// Check if sheet should be skipped
if (isset($this->_loadSheetsOnly) && !in_array((string) $eleSheet["name"], $this->_loadSheetsOnly)) {
++$countSkippedSheets;
$mapSheetId[$oldSheetId] = null;
continue;
}
// Map old sheet id in original workbook to new sheet id.
// They will differ if loadSheetsOnly() is being used
$mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets;
// Load sheet
$docSheet = $excel->createSheet();
$docSheet->setTitle((string) $eleSheet["name"]);
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
$xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$sharedFormulas = array();
if (isset($eleSheet["state"]) && (string) $eleSheet["state"] != '') {
$docSheet->setSheetState( (string) $eleSheet["state"] );
}
if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) {
if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) {
$docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView['zoomScale']) );
}
if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) {
$docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) );
}
if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
$docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false);
}
if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) {
$docSheet->setShowRowColHeaders((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'] ? true : false);
}
if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) {
$docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'] ? true : false);
}
if (isset($xmlSheet->sheetViews->sheetView->pane)) {
示例3: create_worksheet
/**
* create new worksheet
*
* @access protected
*/
protected function create_worksheet()
{
$newsheet = $this->_spreadsheet->createSheet();
$new_worksheet = new Worksheet($this->_spreadsheet, $newsheet);
$this->_worksheets[$this->_spreadsheet->getIndex($newsheet)] = $new_worksheet;
return $new_worksheet;
}
示例4: addSheet
/**
* Add sheet
*
* @param string $name
* @return $this for method chaining
*/
public function addSheet($name)
{
$index = $this->_xls->getSheetCount();
$this->_xls->createSheet($index)->setTitle($name);
$this->setActiveSheet($index);
return $this;
}
示例5: buildSpreadSheet
public function buildSpreadSheet($worksheetName = null, $index = 0)
{
if ($index != 0) {
$this->writer->createSheet($index);
}
$this->writer->setActiveSheetIndex($index);
if (!is_null($worksheetName)) {
$this->worksheetName = $this->shortsWorksheetName($worksheetName);
}
$this->putColumtTitlesInSpreadsheet();
$this->putLineValuesInSpreadsheet();
$this->writer->setActiveSheetIndex(0);
$excelWriter = PHPExcel_IOFactory::createWriter($this->writer, 'Excel5');
$excelWriter->save($this->spreadPath);
}
示例6: sheet
/**
* @param integer|callable|string $sheetID
* @param null $callback
*
* @return $this
* @throws \PHPExcel_Exception
*/
public function sheet($sheetID, $callback = null)
{
// Default
$isCallable = false;
// Init a new PHPExcel instance without any worksheets
if (!$this->excel instanceof PHPExcel) {
$this->original = $this->excel;
$this->initClonedExcelObject($this->excel);
// Clone all connected sheets
foreach ($this->original->getAllSheets() as $sheet) {
$this->excel->createSheet()->cloneParent($sheet);
}
}
// Copy the callback when needed
if (is_callable($sheetID)) {
$callback = $sheetID;
$isCallable = true;
} elseif (is_callable($callback)) {
$isCallable = true;
}
// Clone the loaded excel instance
$this->sheet = $this->getSheetByIdOrName($sheetID);
// Do the callback
if ($isCallable) {
call_user_func($callback, $this->sheet);
}
// Return the sheet
return $this->sheet;
}
示例7: set_data
/**
* Writes cells to the spreadsheet
* array(
* 1 => array('A1', 'B1', 'C1', 'D1', 'E1'),
* 2 => array('A2', 'B2', 'C2', 'D2', 'E2'),
* 3 => array('A3', 'B3', 'C3', 'D3', 'E3'),
* );
*
* @param array of array( [row] => array([col]=>[value]) ) ie $arr[row][col] => value
* @return void
*/
public function set_data(array $data, $multi_sheet = FALSE)
{
// Single sheet ones can just dump everything to the current sheet
if (!$multi_sheet) {
$sheet = $this->_spreadsheet->getActiveSheet();
$this->set_sheet_data($data, $sheet);
} else {
foreach ($data as $sheetname => $sheetData) {
$sheet = $this->_spreadsheet->createSheet();
$sheet->setTitle($sheetname);
$this->set_sheet_data($sheetData, $sheet);
}
// Now remove the auto-created blank sheet at start of XLS
$this->_spreadsheet->removeSheetByIndex(0);
}
}
示例8: arrayToExcel
function arrayToExcel($objPHPExcel = null, $rows, $writeArrayKeysAsHeader = false, $rowStartWrite = 1, $setActiveSheetTo = 0, $sheetName = null)
{
include_once 'sites/all/libraries/PHPExcel/PHPExcel/Writer/Excel2007.php';
// Create an object/instance for the output spreadsheet
if (is_null($objPHPExcel)) {
$objPHPExcel = new PHPExcel();
}
myExcel_setActiveRow($rowStartWrite);
// Create new sheet is needed
$sheetOk = true;
do {
try {
$objPHPExcel->setActiveSheetIndex($setActiveSheetTo);
$sheetOk = true;
} catch (Exception $e) {
$sheetOk = false;
$objPHPExcel->createSheet();
}
} while ($sheetOk === false);
if (is_null($sheetName)) {
$objPHPExcel->getActiveSheet()->setTitle("Sheet {$setActiveSheetTo}");
} else {
$objPHPExcel->getActiveSheet()->setTitle($sheetName);
}
// Set basic properties to output spreadsheet
$objPHPExcel->getProperties()->setCreator("Business USA");
$objPHPExcel->getProperties()->setLastModifiedBy("Business USA");
$objPHPExcel->getProperties()->setTitle("Business USA");
$objPHPExcel->getProperties()->setSubject("Business USA");
$objPHPExcel->getProperties()->setDescription("Business USA");
// Debug
if (strpos(request_uri(), '-DEBUG-NOEXCELWRITE-REPORTWRITE-') !== false) {
ob_end_clean();
}
// Write headders
if ($writeArrayKeysAsHeader === true) {
$headders = array();
foreach ($rows[0] as $key => $cell) {
$headders[] = $key;
}
myExcel_WriteValuesToActiveRow($objPHPExcel, $headders, true);
// Set the next row as "active" so the next time myExcel_WriteValuesToActiveRow() is called it will write to the next
myExcel_setActiveRow(myExcel_getActiveRow() + 1);
}
// Write rows
foreach ($rows as $row) {
// Add a row into the spreadsheet
myExcel_WriteValuesToActiveRow($objPHPExcel, $row);
// Set the next row as "active" so the next time myExcel_WriteValuesToActiveRow() is called it will write to the next
myExcel_setActiveRow(myExcel_getActiveRow() + 1);
}
// Debug
if (strpos(request_uri(), '-DEBUG-NOEXCELWRITE-REPORTWRITE-') !== false) {
flush();
exit;
}
myExcel_decideColumnWidths($objPHPExcel, $rows);
return $objPHPExcel;
}
示例9: createWorksheet
/**
* Creates a worksheet with the given name
*
* @param type $name
* @param array $data
*
* @return array \PHPExcelWorksheet
*/
protected function createWorksheet($name, array $data)
{
$worksheet = $this->xls->createSheet();
$worksheet->setTitle($name);
$this->rowIndexes[$name] = $this->options['data_row'];
$this->labels[$name] = [];
return $worksheet;
}
示例10: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
if (!class_exists('\\PHPExcel')) {
$this->markTestSkipped('PHPExcel not available');
}
$phpExcel = new \PHPExcel();
$sheet = $phpExcel->createSheet();
$this->object = new \Aimeos\MW\Container\Content\PHPExcel($sheet, 'test', array());
}
示例11: init
private static function init($data, $headerTitle = [], $headerRGBColor = 'FCFCFC', $borderColor = 'CCC')
{
$phpExcel = new \PHPExcel();
$phpExcel->getProperties()->setCreator('Affiliates Team')->setTitle('Excel Data');
$phpExcelSheet = $phpExcel->createSheet(0);
$phpExcelSheet->getPageSetup()->setOrientation(\PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$phpExcelSheet->getPageSetup()->setPaperSize(\PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3);
if (!empty($headerTitle)) {
$tmpData = [];
$columnKeys = array_keys($headerTitle);
foreach ($data as $dataTmpRow) {
$tmpRow = [];
foreach ($columnKeys as $columnKey) {
$tmpRow[$columnKey] = isset($dataTmpRow[$columnKey]) ? $dataTmpRow[$columnKey] : '';
}
$tmpData[] = $tmpRow;
}
$data = $tmpData;
}
$rowLength = count($data);
if ($rowLength) {
$keys = array_keys($data[0]);
if (!empty($headerTitle)) {
foreach ($keys as &$keysRow) {
$keysRow = isset($headerTitle[$keysRow]) ? $headerTitle[$keysRow] : $keysRow;
}
}
$columnLength = count($keys);
$fromCode = \PHPExcel_Cell::stringFromColumnIndex(0);
$toCode = \PHPExcel_Cell::stringFromColumnIndex($columnLength - 1);
for ($i = 0; $i < $columnLength; $i++) {
$phpExcelSheet->setCellValueByColumnAndRow($i, 1, $keys[$i]);
$phpExcelSheet->getColumnDimension(chr(65 + $i))->setAutoSize(true);
}
// [merging], develop later
// $phpExcelSheet->mergeCells('A1:A2');
// $phpExcelSheet->getStyle('A1:A2')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
$phpExcelSheet->fromArray($data, ' ', 'A3');
for ($i = 0; $i < $rowLength; ++$i) {
$rowIndex = $i + 1;
if ($rowIndex % 3 == 0) {
if ($rowIndex / 3 % 2) {
self::colorRow($phpExcelSheet, $fromCode, $toCode, $i + 3, 'F9F9F9');
} else {
self::colorRow($phpExcelSheet, $fromCode, $toCode, $i + 3, 'F5FMD');
}
} else {
self::colorRow($phpExcelSheet, $fromCode, $toCode, $i + 3, 'FFFFFF');
}
}
self::colorRow($phpExcelSheet, $fromCode, $toCode, 1, $headerRGBColor);
$headerStyle = ['font' => ['bold' => true], 'alignment' => ['horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER]];
$phpExcelSheet->getStyle($fromCode . '1:' . $toCode . '1')->applyFromArray($headerStyle);
self::setBorderStyle($phpExcelSheet, $fromCode, $toCode, $rowLength + 2, $borderColor);
}
return $phpExcel;
}
示例12:
function crear_hoja($nombre = null)
{
$hoja = $this->excel->createSheet();
if (isset($nombre)) {
$hoja->setTitle(utf8_encode(strval($nombre)));
}
$this->excel->setActiveSheetIndex($this->excel->getSheetCount() - 1);
$this->cursor = $this->cursor_base;
}
示例13: excelExport
public function excelExport($project_id)
{
PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized;
$objPHPExcel = new PHPExcel();
$objPHPExcel->createSheet(0);
$objPHPExcel->setActiveSheetIndex(0);
//设置第一个内置表
$objActSheet = $objPHPExcel->getActiveSheet();
// 获取当前活动的表
$objActSheet->setTitle('项目总体数据表');
//获取项目下的所有成员id
$examinee = $this->modelsManager->createBuilder()->columns(array('number', 'id', 'state', 'name'))->from('Examinee')->where('Examinee.type = 0 AND Examinee.project_id = ' . $project_id)->getQuery()->execute()->toArray();
//异常处理
if (empty($examinee)) {
throw new Exception('项目的被试人数为0,无法进行项目数据表生成');
}
$members_not_finished = array();
foreach ($examinee as $value) {
if ($value['state'] < 4) {
$members_not_finished[$value['number']] = $value['name'];
}
}
if (!empty($members_not_finished)) {
$list = '项目中部分成员未完成测评过程,如下:<br/>';
foreach ($members_not_finished as $key => $value) {
$list .= $key . ':' . $value . '<br/>';
}
throw new Exception(print_r($list, true));
}
$i = 0;
$result = new ProjectData();
$start_column = 'D';
$last = 'D';
$last_data = null;
foreach ($examinee as $examinee_info) {
$data = array();
$data = $result->getindividualComprehensive($examinee_info['id']);
if ($i === 0) {
$this->makeTable($data, $objActSheet);
}
$last = $start_column;
$last_data = $data;
$this->joinTable($data, $objActSheet, $start_column++, $examinee_info['number']);
$i++;
}
// 计算平均值
$this->joinAvg($objActSheet, $last_data, 'D', $last);
//根据项目第一人成绩统计打表
//循环写入每个人的成绩
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$file_name = './tmp/' . $project_id . '_project_data.xls';
$objWriter->save($file_name);
return $file_name;
}
示例14: createExcel
/**
* Create excel from document
*
* @return \PHPExcel
*/
protected function createExcel()
{
$this->phpexcel = new \PHPExcel();
$tableNumber = 0;
// Loop over all tables in document
foreach ($this->document->getTables() as $table) {
// Handle worksheets
if ($tableNumber > 0) {
$this->phpexcel->createSheet();
}
$excelWorksheet = $this->phpexcel->setActiveSheetIndex($tableNumber);
if ($sheetTitle = $table->getAttribute('_excel-name')) {
$excelWorksheet->setTitle($sheetTitle);
}
// Loop over all rows
$rowNumber = 1;
foreach ($table->getRows() as $row) {
$excelWorksheet->getStyle($rowNumber . ':' . $rowNumber)->applyFromArray($this->getRowStylesArray($row));
$this->setDimensions($excelWorksheet, $excelWorksheet->getRowIterator($rowNumber)->current(), $row);
// Loop over all cells in row
$cellNumber = 0;
foreach ($row->getCells() as $cell) {
$excelCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber) . $rowNumber;
// Set value
if ($explicitCellType = $cell->getAttribute('_excel-explicit') || ($explicitCellType = $row->getAttribute('_excel-explicit'))) {
$excelWorksheet->setCellValueExplicit($excelCellIndex, $this->changeValueEncoding($cell->getValue()), $this->convertStaticPhpExcelConstantsFromStringsToConstants($explicitCellType), true);
} else {
$excelWorksheet->setCellValue($excelCellIndex, $this->changeValueEncoding($cell->getValue()), true);
}
// Merge cells
$colspan = $cell->getAttribute('colspan');
$rowspan = $cell->getAttribute('rowspan');
if ($colspan || $rowspan) {
if ($colspan) {
$colspan = $colspan - 1;
}
if ($rowspan) {
$rowspan = $rowspan - 1;
}
$mergeCellsTargetCellIndex = \PHPExcel_Cell::stringFromColumnIndex($cellNumber + $colspan) . ($rowNumber + $rowspan);
$excelWorksheet->mergeCells($excelCellIndex . ':' . $mergeCellsTargetCellIndex);
}
// Set styles
$excelWorksheet->getStyle($excelCellIndex)->applyFromArray($this->getCellStylesArray($cell));
$this->setDimensions($excelWorksheet, $excelWorksheet->getCell($excelCellIndex), $cell);
$cellNumber++;
}
$rowNumber++;
}
$tableNumber++;
}
return $this->phpexcel;
}
示例15: excelExport
public function excelExport($project_id)
{
PHPExcel_CachedObjectStorageFactory::cache_in_memory_serialized;
$objPHPExcel = new PHPExcel();
$objPHPExcel->createSheet(0);
$objPHPExcel->setActiveSheetIndex(0);
//设置第一个内置表
$objActSheet = $objPHPExcel->getActiveSheet();
// 获取当前活动的表
$objActSheet->setTitle('综合');
$this->checkoutFirst($objActSheet, $project_id);
//个人信息
//data
//数据
$data = new ProjectComData();
$data->project_check($project_id);
$inquery_data = $data->getInqueryAnsComDetail($project_id);
$objPHPExcel->createSheet(1);
//添加一个表
$objPHPExcel->setActiveSheetIndex(1);
//设置第2个表为活动表,提供操作句柄
$objActSheet = $objPHPExcel->getActiveSheet();
// 获取当前活动的表
$objActSheet->setTitle('人数统计-单项统计');
$this->checkoutSecond($objActSheet, $project_id, $inquery_data);
$objPHPExcel->createSheet(2);
//添加一个表
$objPHPExcel->setActiveSheetIndex(2);
//设置第2个表为活动表,提供操作句柄
$objActSheet = $objPHPExcel->getActiveSheet();
// 获取当前活动的表
$objActSheet->setTitle('人数统计-交叉项统计');
$this->checkoutThird($objActSheet, $project_id, $inquery_data);
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$file_name = './tmp/' . $project_id . '_inqueryans_data.xls';
$objWriter->save($file_name);
return $file_name;
}