1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <?php
ini_set("max_input_time","20000");
ini_set("max_execution_time","20000");
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';
$path="templates/testing_macro.xlsm";
$objPHPExcel = PHPExcel_IOFactory::load($path);
$sheet = $objPHPExcel-> getActiveSheet();
$rowCount =5;
$worksheetTitle = $sheet->getTitle();
$highestRow = $sheet->getHighestRow(); // e.g. 10
$highestColumn = $sheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
$sheet->setCellValue('B1', 'RetailerChannel');
$sheet->setCellValue('B2', 'filterby');
$sheet->setCellValue('B3', 'totalsite');
$sheet->setCellValue('B4', 'totalfires');
$sheet->setCellValue('B5', 'totaldevice');
$sheet = $objPHPExcel->getActiveSheet();
$baseRow = 3;
$i = 0;
$r = 0;
$sheet->insertNewRowBefore($baseRow,2);
for($a=6; $a<9; $a++){
$row = $baseRow + $a;
$b = 10 - $a;
$sheet->setCellValue('A'.$row, '200'.$b)
->setCellValue('B'.$row, '400'.$b)
->setCellValue('C'.$row, '600'.$b)
->setCellValue('D'.$row, '800'.$b)
->setCellValue('E'.$row, '100'.$b)
->setCellValue('F'.$row, '300'.$b);
}
$sheet->removeRow($baseRow-1,1);
echo date('H:i:s') , " Write to Excel2007 format" , PHP_EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsm', __FILE__) , PHP_EOL;
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , PHP_EOL;
// Echo done
echo date('H:i:s') , " Done writing file" , PHP_EOL;
exit;
?> |
Partager