| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper; | 
					
						
							|  |  |  | use PhpOffice\PhpSpreadsheet\Spreadsheet; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-01 08:48:59 +00:00
										 |  |  | require __DIR__ . '/../Header.php'; | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Create new Spreadsheet object
 | 
					
						
							|  |  |  | $helper->log('Create new Spreadsheet object'); | 
					
						
							| 
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 |  |  | $spreadsheet = new Spreadsheet(); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Set document properties
 | 
					
						
							|  |  |  | $helper->log('Set document properties'); | 
					
						
							|  |  |  | $spreadsheet->getProperties()->setCreator('Maarten Balliauw') | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->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'); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Add some data
 | 
					
						
							|  |  |  | $helper->log('Add some data'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $html1 = '<font color="#0000ff"> | 
					
						
							|  |  |  | <h1 align="center">My very first example of rich text<br />generated from html markup</h1> | 
					
						
							|  |  |  | <p> | 
					
						
							|  |  |  | <font size="14" COLOR="rgb(0,255,128)"> | 
					
						
							|  |  |  | <b>This block</b> contains an <i>italicized</i> word; | 
					
						
							|  |  |  | while this block uses an <u>underline</u>. | 
					
						
							|  |  |  | </font> | 
					
						
							|  |  |  | </p> | 
					
						
							| 
									
										
											  
											
												Improve Coverage for HTML Reader
Reader/Html is now covered except for 1 statement.
There is some coverage of RichText when you know in advance that the
html will expand into a single cell.
It is a tougher nut, one that I have not yet cracked,
to try to handle rich text while converting unkown html to multiple cells.
The original author left this as a TODO, and so for now must I.
It made sense to restructure some of the code. There are some changes.
- Issue #1532 is fixed (links are now saved when using rowspan).
- Colors can now be specified as html color name. To accomplish this,
  Helper/Html function colourNameLookup was changed from protected
  to public, and changed to static.
- Superfluous empty lines were eliminated in a number of places, e.g.
  <ul><li>A</li><li>B</li><li>C</li></ul>
  had formerly caused a wrapped cell to be created with 2 empty lines
  followed by A, B, and C on separate lines; it will now just have the
  3 A/B/C lines, which seems like a more sensible interpretation.
- Img alt tag, which had been cast to float, is now used as a string.
Private member "encoding" is not used. Functions getEncoding and setEncoding
have therefore been marked deprecated. In fact, I was unable to get
SecurityScanner to pass *any* html which is not UTF-8. There are
possibly ways of getting around this (in Reader/Html - I have no
intention of messing with Security Scanner), as can be seen in my
companion pull request for Excel2003 Xml Reader. Doing this would be
easier for ASCII-compatible character sets (like ISO-8859-1),
than for non-compatible charsets (like UTF-16). I am not
convinced that the effort is worth it, but am willing to investigate
further.
I added a number of tests, creating an Html directory, and moving
HtmlTest to that directory.
											
										 
											2020-06-26 05:42:38 +00:00
										 |  |  | <p align="right"><font size="9" color="red" face="Times New Roman, serif"> | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | I want to eat <ins><del>healthy food</del> <strong>pizza</strong></ins>. | 
					
						
							|  |  |  | </font> | 
					
						
							|  |  |  | '; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $html2 = '<p> | 
					
						
							|  |  |  | <font color="#ff0000"> | 
					
						
							|  |  |  |     100°C is a hot temperature | 
					
						
							|  |  |  | </font> | 
					
						
							|  |  |  | <br> | 
					
						
							|  |  |  | <font color="#0080ff"> | 
					
						
							|  |  |  |     10°F is cold | 
					
						
							|  |  |  | </font> | 
					
						
							|  |  |  | </p>'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $html3 = '2<sup>3</sup> equals 8'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $html4 = 'H<sub>2</sub>SO<sub>4</sub> is the chemical formula for Sulphuric acid'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $html5 = '<strong>bold</strong>, <em>italic</em>, <strong><em>bold+italic</em></strong>'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 |  |  | $wizard = new HtmlHelper(); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | $richText = $wizard->toRichTextObject($html1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setCellValue('A1', $richText); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->getColumnDimension('A') | 
					
						
							|  |  |  |     ->setWidth(48); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->getRowDimension(1) | 
					
						
							|  |  |  |     ->setRowHeight(-1); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | $spreadsheet->getActiveSheet()->getStyle('A1') | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->getAlignment() | 
					
						
							|  |  |  |     ->setWrapText(true); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $richText = $wizard->toRichTextObject($html2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setCellValue('A2', $richText); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->getRowDimension(1) | 
					
						
							|  |  |  |     ->setRowHeight(-1); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->getStyle('A2') | 
					
						
							|  |  |  |     ->getAlignment() | 
					
						
							|  |  |  |     ->setWrapText(true); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->setActiveSheetIndex(0) | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setCellValue('A3', $wizard->toRichTextObject($html3)); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->setActiveSheetIndex(0) | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setCellValue('A4', $wizard->toRichTextObject($html4)); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $spreadsheet->setActiveSheetIndex(0) | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setCellValue('A5', $wizard->toRichTextObject($html5)); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Rename worksheet
 | 
					
						
							|  |  |  | $helper->log('Rename worksheet'); | 
					
						
							|  |  |  | $spreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2018-01-28 06:59:38 +00:00
										 |  |  |     ->setTitle('Rich Text Examples'); | 
					
						
							| 
									
										
										
										
											2016-08-31 16:15:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Save
 | 
					
						
							|  |  |  | $helper->write($spreadsheet, __FILE__); |