pqzx / html2docx

Convert html to docx
MIT License
69 stars 49 forks source link

Background Color is Not working #42

Open Nidesh-Arumugam opened 2 years ago

Nidesh-Arumugam commented 2 years ago

Based on our requirement, when we are converting a HTML to doc we were unable to Get the Background color as expected.

We did run some tests from your test folder https://github.com/pqzx/html2docx/blob/master/tests/text1.html , based on your code on h2d.py even if rgb is present in html the converted doc doesn't show the changes in background color.

code:

        if 'background-color' in style:
            if 'rgb' in style['background-color']:
                color = color = re.sub(r'[a-z()]+', '', style['background-color'])
                colors = [int(x) for x in color.split(',')]
            elif '#' in style['background-color']:
                color = style['background-color'].lstrip('#')
                colors = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
            else:
                colors = [0, 0, 0]
                # TODO map colors to named colors (and extended colors...)
                # For now set color to black to prevent crashing
            self.run.font.highlight_color = WD_COLOR.GRAY_25 #TODO: map colors

Here i will attach a couple of screenshots on how the conversion looks from html to docs

html:

Screenshot 2022-05-05 at 12 23 11 PM

docs:

Screenshot 2022-05-05 at 12 30 03 PM

Can we get to know how this issue can be fixed ?

Is there any work log pending from your side which will be released in the future release ?

Is there any way we can map the colors to the background style ? if yes how it can be done ?