How To Set Edge Softening Using xlwings?

Example

Code

import xlwings as xw
import os

def set_style(cht):
    cht.ChartArea.Format.Line.Visible=False
    cht.PlotArea.Format.Fill.Visible=False
    cht.PlotArea.Format.Line.Visible=True
    cht.PlotArea.Format.Line.ForeColor.RGB=xw.utils.rgb_to_int((200,200,200))
    #cht.PlotArea.Format.Line.ForeColor.ObjectThemeColor = msoThemeColorText1
    ax1=cht.Axes(1)
    ax2=cht.Axes(2)
    ax1.HasTitle=True
    ax1.AxisTitle.Text='Categories'
    ax1.AxisTitle.Font.Size=10
    ax1.TickLabels.Font.Size=8
    #ax1.TickLabels.NumberFormat='0.00'
    ax1.HasMajorGridlines=False
    ax2.HasTitle=True
    ax2.AxisTitle.Text='Values'
    ax2.AxisTitle.Font.Size=10
    ax2.TickLabels.Font.Size=8
    ax2.HasMajorGridlines=False
    cht.HasTitle=True
    #cht.ChartTitle.Caption='Plot'
    #cht.ChartTitle.Font.Size=12

root=os.getcwd()
app=xw.App(visible=True,add_book=False)
wb=app.books.open(root+r'/data.xlsx',read_only=False)
sht=wb.sheets('Sheet1')

sht.api.Range('A2:B7').Select()  #数据
shp=sht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,20,20,350,250,True)
cht=shp.Chart  #添加图表
glow=cht.SeriesCollection(1).Format.Glow
glow.Color.ObjectThemeColor=1    #msoThemeColorAccent1
#glow.Color.TintAndShade=0
glow.Color.Brightness=0
glow.Transparency=0.6000000238
glow.Radius=8

sht.api.Range('A2:C11').Select()  #数据
shp2=sht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlLine,30,20,350,250,True)
cht2=shp2.Chart  #添加图表
glow2=cht2.SeriesCollection(1).Format.Glow
glow2.Color.ObjectThemeColor=1    #msoThemeColorAccent1
#glow2.Color.TintAndShade=0
glow2.Color.Brightness=0
glow2.Transparency=0.6000000238
glow2.Radius=5
glow3=cht2.SeriesCollection(2).Format.Glow
glow3.Color.ObjectThemeColor=1    #msoThemeColorAccent1
#glow3.Color.TintAndShade=0
glow3.Color.Brightness=0
glow3.Transparency=0.6000000238
glow3.Radius=8

set_style(cht)
set_style(cht2)

cht.Export(root+'/cht.jpg')
cht.Export(root+'/cht.svg')
cht.ExportAsFixedFormat(0,root+'/cht.pdf')
cht2.Export(root+'/cht2.jpg')
cht.Export(root+'/cht2.svg')
cht2.ExportAsFixedFormat(0,root+'/cht2.pdf')

#wb.save()
#app.kill()
March 29, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *