BUG: `df.to_excel` fails for `"border-style: hair"` with `xlsxwriter`

This issue has been created since 2022-09-19.

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({"a": [1]})
styler = df.style.applymap(lambda x: "border-style: hair; border-color: black")

styler.to_excel(r"test_border.xlsx", engine="xlsxwriter")

Issue Description

The CSSToExcelConverter._border_style function does not return any value (i.e., None) when the style string is not recognized. However, "hair" should be a recognized style string in xlsxwriter, corresponding to border index "7". This leads to a crash in xlsxwriter. Moreover, there is no path to actually return the "hair" style for any engine.

Expected Behavior

Use of border-style: hair will export a spreadsheet with the correct formatting.

Installed Versions

INSTALLED VERSIONS

commit : 224458e
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.5.0rc0
numpy : 1.21.6
pytz : 2022.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.1.2
Cython : None
pytest : 7.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : 1.3.5
brotli : None
fastparquet : 0.5.0
fsspec : None
gcsfs : None
matplotlib : None
numba : 0.55.2
numexpr : 2.8.3
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 8.0.0
pyreadstat : 1.1.9
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None

tehunter wrote this answer on 2022-09-19

take

rhshadrach wrote this answer on 2022-09-19

Thanks for the report @tehunter! Your versions indicate 1.5.0rc; do you know if this bug exists in previous versions?

tehunter wrote this answer on 2022-09-19

I know that previous versions also had an inability to use the "hair" style. I'm unsure at the moment if it led to the same error. I think it probably gave the same error identified here and in #45312.

In addition to adding support for the "hair" style, I think we probably need to have a "soft fail" for unrecognized/unimplemented border combinations. I'll work on adding both in a PR.

rhshadrach wrote this answer on 2022-09-20

However, "hair" should be a recognized style string in xlsxwriter, corresponding to border index "1"

Why not index 7? Does weight 0 mean that there is no visible border for index 7?

tehunter wrote this answer on 2022-09-21

Yes, thanks for confirming. I misread the table; "hair" corresponds to index 7.

tehunter wrote this answer on 2022-09-21

Submitted a PR: #48660

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35374
Watcher Count 1122
Fork Count 15034
Issue Count 3579

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Source Control readability 0 2022-03-10 2022-09-10
Error running evaluateK 17 2019-11-25 2022-07-18
importing tensorflow 1.0 models in v3 8 2020-06-29 2022-05-04
add support for light shell/terminal themes 4 2016-02-17 2022-09-12
use correct OASIS URLs in catalog.xml 3 2021-05-26 2022-09-28
Utils not executable on Linux 1 2022-02-05 2022-09-09
"shell.ln" still throws error string "ln: EEXIST" even when running with "-f" 0 2021-07-15 2022-09-22
UC fails when browser window is not in view 0 2022-07-23 2022-09-18
unhashable type: 'numpy.ndarray' 13 2022-02-19 2022-09-13
How to reduce buff / cache occupation? 1 2021-10-15 2022-09-15
When Use "Let's Encrypt certificates" is on, other certificate drop downs should be hidden 8 2021-01-09 2022-09-21
Incremental highlighting 3 2021-12-15 2022-08-31
the code in readme has smme problem 0 2022-07-06 2022-09-19
"check_normality()' does not support models of class 'lmerModLmerTest'. Error in attr(p.val, "object_name") <- .safe_deparse(substitute(x)) : attempt to set an attribute on NULL" 8 2021-05-07 2022-08-14
zsh completions 4 2021-08-13 2022-01-17
Lighthouse parameter passed as string instead of boolean 4 2021-03-31 2022-07-23
Fully Support SSE-C encryption 5 2020-08-01 2022-08-23
i can't see whiteboard in bigbluebutton Whiteboard does not appear in screen 3 2021-10-03 2022-09-19
[BUG] Some old links such as Rest Server are broken 3 2021-11-29 2022-04-20
[Enhancement] Integrate delta_writer_commit span into load_channel span 4 2022-06-17 2022-09-09
query error when update or insert into select on primary table with no data 0 2022-06-17 2022-08-28
[sqlancer] empty json path 1 2022-06-17 2022-08-13
How do we specify which account (s_account) is used for tracking? 0 2022-03-23 2022-09-19
NC19 support 4 2020-06-04 2022-01-14
`selector-class-pattern` pattern does not allow for BEM selector names 1 2021-11-08 2022-09-28
dctm-pj.com 0 2022-01-05 2021-12-29
v.youku.com 1 2021-11-04 2022-01-21
TypeError: Cannot read properties of undefined (reading 'buildMeta') 2 2022-04-01 2022-09-28
Regression: Cross-compilation from macOS to other platforms fails in libc 17 2021-09-09 2022-09-10
stage2: lazy ABI size trips an assertion in codegen 0 2022-08-22 2022-08-28
third-party project "mount.ufs" only builds on self-hosted in debug mode 0 2022-08-22 2022-08-28
Multi Regional Setup 2 2021-10-14 2022-09-10
[DocGen] Allow for the injection of PatternExecutionReporter from external calls 0 2021-03-01 2022-09-15
Rolling operations fail with unknown divisions 1 2022-07-25 2022-09-24
In-place rotation detach not allowed 0 2022-09-06 2022-09-27
classification_report error 0 2020-12-30 2022-09-28
Generate changelog and add PR template 0 2021-01-09 2022-09-07
Consider offering a full jitter backoff policy 3 2022-04-14 2022-09-14
[BUG] Printer doubling movement after print start 13 2021-10-20 2022-09-25
useFieldArray and useField on checkbox component does not work well 4 2022-07-14 2022-09-18
Drag objects to left/ right edge to move objects across workspace 1 2021-11-07 2022-09-16
It seems DeleteOpenIDConnectSession is never called? 14 2020-11-24 2022-09-21
[Security] Workflow tests.yml is using vulnerable action actions/checkout 0 2021-12-20 2022-09-26
Rework the project with the new API 1 2020-12-15 2021-12-26
Curator: Templates: Archive 0 2022-04-25 2022-09-24
Add @DoFn.yields_batches and @DoFn.yields_elements decorators to override defaults 0 2022-06-05 2022-09-18
Any plan to support TF=1.15 and CUDA=11.1? 1 2021-12-15 2022-09-27
[APM] docs: Add documentation for the agent keys API in the APM app 1 2021-12-07 2022-08-02
[elasticsearch] fix a lines order in example values 0 2021-12-14 2022-09-22
"fullpage_redirect_to" is not working 10 2021-06-21 2022-09-14