log('Create new Spreadsheet object'); $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); // Set document properties $helper->log('Set document properties'); $spreadsheet->getProperties()->setCreator('Maarten Balliauw') ->setLastModifiedBy('Maarten Balliauw') ->setTitle('PhpSpreadsheet Test Document') ->setSubject('PhpSpreadsheet Test Document') ->setDescription('Test document for PhpSpreadsheet, generated using PHP classes.') ->setKeywords('office PhpSpreadsheet php') ->setCategory('Test result file'); // Add some data $helper->log('Add some data'); $html1 = '

My very first example of rich text
generated from html markup

This block contains an italicized word; while this block uses an underline.

I want to eat healthy food pizza. '; $html2 = '

100°C is a hot temperature
10°F is cold

'; $html3 = '23 equals 8'; $html4 = 'H2SO4 is the chemical formula for Sulphuric acid'; $html5 = 'bold, italic, bold+italic'; $wizard = new \PhpOffice\PhpSpreadsheet\Helper\HTML(); $richText = $wizard->toRichTextObject($html1); $spreadsheet->getActiveSheet() ->setCellValue('A1', $richText); $spreadsheet->getActiveSheet() ->getColumnDimension('A') ->setWidth(48); $spreadsheet->getActiveSheet() ->getRowDimension(1) ->setRowHeight(-1); $spreadsheet->getActiveSheet()->getStyle('A1') ->getAlignment() ->setWrapText(true); $richText = $wizard->toRichTextObject($html2); $spreadsheet->getActiveSheet() ->setCellValue('A2', $richText); $spreadsheet->getActiveSheet() ->getRowDimension(1) ->setRowHeight(-1); $spreadsheet->getActiveSheet() ->getStyle('A2') ->getAlignment() ->setWrapText(true); $spreadsheet->setActiveSheetIndex(0) ->setCellValue('A3', $wizard->toRichTextObject($html3)); $spreadsheet->setActiveSheetIndex(0) ->setCellValue('A4', $wizard->toRichTextObject($html4)); $spreadsheet->setActiveSheetIndex(0) ->setCellValue('A5', $wizard->toRichTextObject($html5)); // Rename worksheet $helper->log('Rename worksheet'); $spreadsheet->getActiveSheet() ->setTitle('Rich Text Examples'); // Save $helper->write($spreadsheet, __FILE__);