You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在xlsxwriter中设置文本下划线格式并创建对应格式变量?

在XlsxWriter中创建下划线格式变量

和你创建加粗格式的方式一致,只需在workbook.add_format()的参数字典里添加underline键,它支持多种下划线类型:

  • 单下划线:赋值为True或1
  • 双下划线:赋值为2
  • 会计专用单下划线:赋值为3
  • 会计专用双下划线:赋值为4

示例代码

创建基础单下划线格式:

underline_format = workbook.add_format({'underline': True})

创建双下划线格式:

double_underline_format = workbook.add_format({'underline': 2})

使用示例

将格式应用到单元格:

worksheet.write('A1', '这是单下划线文本', underline_format)
worksheet.write('A2', '这是双下划线文本', double_underline_format)

内容的提问来源于stack exchange,提问作者BenDeagle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 10:45:47