Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLs generated loses all CSS formatting if setUseInlineCss(true) #3678

Closed
1 of 8 tasks
trishcaburian opened this issue Aug 18, 2023 · 1 comment · Fixed by #3680
Closed
1 of 8 tasks

HTMLs generated loses all CSS formatting if setUseInlineCss(true) #3678

trishcaburian opened this issue Aug 18, 2023 · 1 comment · Fixed by #3680

Comments

@trishcaburian
Copy link

trishcaburian commented Aug 18, 2023

This is:

- [ *] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

generateHTMLAll() should keep the CSS formatting when setUseInlineCss(true)

What is the current behavior?

generateHTMLAll() generates the HTML table but without all CSS styling

What are the steps to reproduce?

I was trying to generate the HTML version of a report with

$this->ApplyStyleArray['Yellowfill'] = array(
            'fill' => array(
                'fillType' => Fill::FILL_SOLID,
                'color' => array('rgb' => 'FFFF00')
            )
        );
$spreadsheet->getActiveSheet()->getStyle('A'.$r)->applyFromArray($this->ApplyStyleArray['Yellowfill']);

$objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html');
            $objWriter->setUseInlineCss(true);
            ob_start();
            $objWriter->save('php://output');
            return ob_get_clean();

and for some reason all the cells that are supposed to have background-colors or additional styling do not.

I did some poking around the Html writer and it seems this part of buildCss is the cause:

//line 976-979
// Calculate cell style hashes
foreach ($this->spreadsheet->getCellXfCollection() as $index => $style) {
     $css['td.style' . $index . ', th.style' . $index] = $this->createCSSStyle($style);
     //$css['th.style' . $index] = $this->createCSSStyle($style);
}

another project is still in version 1.24 and the html generated is

<tr style="height:24.75pt">
    <td style="vertical-align:middle; text-align:center; border-bottom:1px solid #000000 !important; border-top:1px solid #000000 !important; border-left:1px solid #000000 !important; border-right:1px solid #000000 !important; font-weight:bold; color:#FFFFFF; font-family:'Arial'; font-size:14pt; background-color:#7F7F7F; width:831.75pt; height:24.75pt" colspan="13">DATA week 24, 13.06.2023</td>
</tr>

but the one that got upgraded to version 1.29 generates this html instead

<tr style="height:24.75pt">
    <td style="width:831.75pt; height:24.75pt" colspan="13">DATA week 24, 13.06.2023</td>
</tr>

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Only HTML

Which versions of PhpSpreadsheet and PHP are affected?

1.29

@oleibman
Copy link
Collaborator

Confirmed - thank you for the excellent documentation. Expect a fix over the weekend.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 19, 2023
Fix PHPOffice#3678. Problem introduced by PR PHPOffice#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.
oleibman added a commit that referenced this issue Aug 21, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants