-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Html Writer Styles when Using Inline Css (#3680)
* Html Writer Styles when Using Inline Css Fix #3678. Problem introduced by PR #3016. Combining `td` and `th` styles into a single declaration greatly reduces file size when `useInlineCss` is false, which is the default. However, generating code with the non-default option was not changed to use the combined declaration, so styling was lost. This PR rectifies that error. * Apostrophe Rather Than Quote
- Loading branch information
Showing
2 changed files
with
43 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html; | ||
|
||
use PhpOffice\PhpSpreadsheet\Spreadsheet; | ||
use PhpOffice\PhpSpreadsheet\Style\Fill; | ||
use PhpOffice\PhpSpreadsheet\Writer\Html; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue3678Test extends TestCase | ||
{ | ||
public function testInlineAndNot(): void | ||
{ | ||
$spreadsheet = new Spreadsheet(); | ||
$sheet = $spreadsheet->getActiveSheet(); | ||
$sheet->getCell('A1')->setValue(1); | ||
$styleArray = [ | ||
'fill' => [ | ||
'fillType' => Fill::FILL_SOLID, | ||
'color' => ['rgb' => 'FFFF00'], | ||
], | ||
]; | ||
$sheet->getStyle('A1')->applyFromArray($styleArray); | ||
$style1 = "vertical-align:bottom; border-bottom:none #000000; border-top:none #000000; border-left:none #000000; border-right:none #000000; color:#000000; font-family:'Calibri'; font-size:11pt; background-color:#FFFF00"; | ||
$style2 = $style1 . '; text-align:right; width:42pt'; | ||
$writer = new Html($spreadsheet); | ||
$html = $writer->generateHtmlAll(); | ||
self::assertStringContainsString('td.style1, th.style1 { ' . $style1 . ' }', $html); | ||
self::assertStringContainsString('<td class="column0 style1 n">1</td>', $html); | ||
self::assertStringContainsString('table.sheet0 col.col0 { width:42pt }', $html); | ||
self::assertStringContainsString('.n { text-align:right }', $html); | ||
$writer->setUseInlineCss(true); | ||
$html = $writer->generateHtmlAll(); | ||
self::assertStringContainsString('<td style="' . $style2 . '">1</td>', $html); | ||
$spreadsheet->disconnectWorksheets(); | ||
} | ||
} |