2024年12月5日 星期四

Python: openpyxl.utils.exceptions.IllegalCharacterError

久未更動的程式, 突然出現error:


  File "C:\Users\XXX\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\cell\cell.py", line 159, in check_string

    raise IllegalCharacterError

openpyxl.utils.exceptions.IllegalCharacterError


原因是有範圍為8進制 [\000-\010]|[\013-\014]|[\016-\037] 的字元.

查了查, 最終發現應是使用者貼資料到系統時, 字串第1個字元是 HEX 16 , 不知從哪複製來的.


治標方式:


from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE

...

v_item = ILLEGAL_CHARACTERS_RE.sub(r'', v_item)


治本, 還是要修正源頭資料.


Ref:

1.openpyxl.utils.exceptions.IllegalCharacterError报错原因及解决办法

  https://www.cnblogs.com/hengdin/p/16996512.html


2.openpyxl.utils.exceptions.IllegalCharacterError 错误原因分析及解决办法

  https://blog.csdn.net/javajiawei/article/details/97147219


3.pandas写入excel时报错openpyxl.utils.exceptions.IllegalCharacterError解决

https://blog.csdn.net/koxb/article/details/131718681



2024年12月3日 星期二

Python: 畫甘特圖

Python: 畫甘特圖

1.使用 Matplotlib , 主要是 broken_barh()

2.使用plotly.express


Ref:

1.Python | Basic Gantt chart using Matplotlib

https://www.geeksforgeeks.org/python-basic-gantt-chart-using-matplotlib/


2.plotting job scheduling chart in Python

https://stackoverflow.com/questions/65183169/plotting-job-scheduling-chart-in-python


3.Gantt Charts in Python

https://plotly.com/python/gantt/