Created
August 13, 2015 18:30
Revisions
-
mikehaertl created this gist
Aug 13, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ <?php /** * writeToExcelFiles * * $messages is an array of this format: * [ * 'de' => [ * 'categoryA' => * 'text in line 1', * 'text in line 2', * ], * 'categoryB' => * 'text in line 1', * 'text in line 2', * ], * ], * 'en' => [ ... ], * ] */ protected function writeToExcelFiles($messages, $excelDir) { foreach ($messages as $language => $categories) { $excel = new PHPExcel(); $index = 0; foreach ($categories as $category => $sources) { $sheet = new PHPExcel_Worksheet($excel, $category); $excel->addSheet($sheet, $index++); $sheet->getColumnDimension('A')->setWidth(60); $sheet->getColumnDimension('B')->setWidth(60); $sheet->setCellValue('A1', 'Source', PHPExcel_Cell_DataType::TYPE_STRING); $sheet->setCellValue('B1', 'Translation', PHPExcel_Cell_DataType::TYPE_STRING); $sheet->getStyle('A1:B1')->applyFromArray([ 'font' => [ 'bold' => true, ] ]); $row = 2; foreach ($sources as $source) { $sheet->setCellValue('A'.$row, $source, PHPExcel_Cell_DataType::TYPE_STRING); $sheet->getRowDimension($row)->setRowHeight(-1); $row++; } $sheet->getStyle('A2:B'.$row)->getAlignment()->setWrapText(true); } $excel->removeSheetByIndex($index); $excel->setActiveSheetIndex(0); $writer = new PHPExcel_Writer_Excel5($excel); $writer->save($excelDir.DIRECTORY_SEPARATOR.$language.'.xls'); } }