Archive

How To Set Legend Using xlwings? 3

【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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.HasLegend=True
leg=cht.Legend
leg.Position=xw.constants.LegendPosition.xlLegendPositionBottom
leg.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((0,200,0))
leg.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,255))
leg.Format.TextFrame2.TextRange.Font.Name='Arial'
leg.Format.TextFrame2.TextRange.Font.Italic=True
      
set_style(cht)

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

#wb.save()
#app.kill()

How To Set Legend Using xlwings? 2

【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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.HasLegend=True
leg=cht.Legend
leg.Position=xw.constants.LegendPosition.xlLegendPositionRight
leg.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))
leg.Format.Line.ForeColor.RGB=xw.utils.rgb_to_int((0,0,0))
leg.Format.Line.Weight=2
     
set_style(cht)

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

#wb.save()
#app.kill()

How To Set Legend Using xlwings?

【Method】

The legend is represented by the `Legend` object. You can use the `HasLegend` property of the `Chart` object to show or hide the legend, and the `Legend` property to return the `Legend` object. Using the properties and methods of the `Legend` object, you can modify the appearance, font, and position of the legend.

The `Format` property of the `Legend` object returns a `ChartFormat` object, which can be used to set the background and border of the legend. The `Font` property returns a `Font` object to set the font. The `Position` property determines the position of the legend. The values for the `Position` property are shown in the table below.

Name

Value

Description

xlLegendPositionBottom

-4107

Display legend at the bottom

xlLegendPositionCorner

2

Display legend at the top-right corner of the chart

xlLegendPositionCustom

-4161

Display legend at a custom position

xlLegendPositionLeft

-4131

Display legend on the left side

xlLegendPositionRight

-4152

Display legend on the right side

xlLegendPositionTop

-4160

Display legend at the top

sht.api.Range(‘A1:B7’).Select()

sht.api.Range(‘A1:B7’).Select()    #Data

cht=sht.api.Shapes.AddChart().Chart    #Add chart

cht.Legend.Font.Italic=True    #Legend font italicized

cht.Legend.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))

cht.Legend.Format.Line.ForeColor.RGB=xw.utils.rgb_to_int((0,0,255))

cht.Legend.Position=-4107    #Legend positioned below the chart

 

【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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.HasLegend=True
leg=cht.Legend
leg.Position=xw.constants.LegendPosition.xlLegendPositionBottom
leg.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))
      
set_style(cht)

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

#wb.save()
#app.kill()

How To Set Chart Area Using xlwings?

【Method】

The chart area is the rectangular area that contains the entire chart, while the plot area is the rectangular area defined by the two axes. In Excel, the chart area is represented by the `ChartArea` object, and the plot area is represented by the `PlotArea` object. You can access these areas using the `ChartArea` and `PlotArea` properties of the `Chart` object.

 

By continuously referencing the `ChartArea` and `PlotArea` objects’ `Format.Fill` property, you can set the fill properties of both areas, such as their color, transparency, gradient fills, pattern fills, picture fills, texture fills, etc.

 

Using the `Format.Shadow` property of the `ChartArea` and `PlotArea` objects, you can set additional shadow properties for these areas. The `Format.Shadow` property returns a `ShadowFormat` object with the following main properties:

– **Visible**: Determines whether the shadow is visible.

– **Blur**: Gets or sets the blur radius of the shadow.

– **Transparency**: Gets or sets the transparency of the shadow (from 0.0 for opaque to 1.0 for fully transparent).

– **OffsetX**: Gets or sets the horizontal offset of the shadow in points. Positive values shift the shadow to the right, while negative values shift it to the left.

– **OffsetY**: Gets or sets the vertical offset of the shadow in points. Positive values shift the shadow downward, while negative values shift it upward.

 

sht.api.Range(‘A1:B7’).Select()

cht=sht.api.Shapes.AddChart().Chart

cha=cht.ChartArea    #Chart Area

cha.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((155,255,0))

cha.Shadow=True    #Plot area shows shadow

pla=cht.PlotArea    #Plot area

pla.Format.Fill.UserPicture(root+r’/picpy2.jpg’)    #Picture fill

cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))

cht.Axes(2).HasMajorGridlines=False

cha.Shadow=False

pla.Format.Shadow.Visible=True    #Plot area shows shadow

pla.Format.Shadow.OffsetX=3    #Horizontal offset of the shadow

pla.Format.Shadow.OffsetY=3    #Vertical offset of the shadow

 

【Example】

【Code】

import xlwings as xw
import os

def set_style(cht):
    cht.ChartArea.Format.Line.Visible=False
    cht.PlotArea.Format.Fill.Visible=True
    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.AxisTitle.Font.Color = xw.utils.rgb_to_int((255,255,255))
    ax1.TickLabels.Font.Size=8
    ax1.TickLabels.Font.Color = xw.utils.rgb_to_int((255,255,255))
    #ax1.TickLabels.NumberFormat='0.00'
    ax1.HasMajorGridlines=False
    ax2.HasTitle=True
    ax2.AxisTitle.Text='Values'
    ax2.AxisTitle.Font.Size=10
    ax2.AxisTitle.Font.Color = xw.utils.rgb_to_int((255,255,255))
    ax2.TickLabels.Font.Size=8
    ax2.TickLabels.Font.Color = xw.utils.rgb_to_int((255,255,255))
    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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.ChartArea.Format.Fill.UserPicture('d:/pic.jpg')
cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))

set_style(cht)
cht.Legend.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,255))

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

#wb.save()
#app.kill()

How To Set Plot Area Using xlwings? 2

【Method】

The chart area is the rectangular area that contains the entire chart, while the plot area is the rectangular area defined by the two axes. In Excel, the chart area is represented by the `ChartArea` object, and the plot area is represented by the `PlotArea` object. You can access these areas using the `ChartArea` and `PlotArea` properties of the `Chart` object.

By continuously referencing the `ChartArea` and `PlotArea` objects’ `Format.Fill` property, you can set the fill properties of both areas, such as their color, transparency, gradient fills, pattern fills, picture fills, texture fills, etc.

Using the `Format.Shadow` property of the `ChartArea` and `PlotArea` objects, you can set additional shadow properties for these areas. The `Format.Shadow` property returns a `ShadowFormat` object with the following main properties:

– **Visible**: Determines whether the shadow is visible.

– **Blur**: Gets or sets the blur radius of the shadow.

– **Transparency**: Gets or sets the transparency of the shadow (from 0.0 for opaque to 1.0 for fully transparent).

– **OffsetX**: Gets or sets the horizontal offset of the shadow in points. Positive values shift the shadow to the right, while negative values shift it to the left.

– **OffsetY**: Gets or sets the vertical offset of the shadow in points. Positive values shift the shadow downward, while negative values shift it upward.

sht.api.Range(‘A1:B7’).Select()

cht=sht.api.Shapes.AddChart().Chart

cha=cht.ChartArea    #Chart Area

cha.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((155,255,0))

cha.Shadow=True    #Plot area shows shadow

pla=cht.PlotArea    #Plot area

pla.Format.Fill.UserPicture(root+r’/picpy2.jpg’)    #Picture fill

cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))

cht.Axes(2).HasMajorGridlines=False

cha.Shadow=False

pla.Format.Shadow.Visible=True    #Plot area shows shadow

pla.Format.Shadow.OffsetX=3    #Horizontal offset of the shadow

pla.Format.Shadow.OffsetY=3    #Vertical offset of the shadow

 

【Example】

【Code】

import xlwings as xw
import os

def set_style(cht):
    cht.ChartArea.Format.Line.Visible=False
    cht.PlotArea.Format.Fill.Visible=True
    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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))
cht.PlotArea.Format.Fill.UserPicture('d:/picpy2.jpg')

set_style(cht)

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

#wb.save()
#app.kill()

How To Set Plot Area Using xlwings?

【Method】

The chart area is the rectangular area that contains the entire chart, while the plot area is the rectangular area defined by the two axes. In Excel, the chart area is represented by the `ChartArea` object, and the plot area is represented by the `PlotArea` object. You can access these areas using the `ChartArea` and `PlotArea` properties of the `Chart` object.

By continuously referencing the `ChartArea` and `PlotArea` objects’ `Format.Fill` property, you can set the fill properties of both areas, such as their color, transparency, gradient fills, pattern fills, picture fills, texture fills, etc.

Using the `Format.Shadow` property of the `ChartArea` and `PlotArea` objects, you can set additional shadow properties for these areas. The `Format.Shadow` property returns a `ShadowFormat` object with the following main properties:

– **Visible**: Determines whether the shadow is visible.

– **Blur**: Gets or sets the blur radius of the shadow.

– **Transparency**: Gets or sets the transparency of the shadow (from 0.0 for opaque to 1.0 for fully transparent).

– **OffsetX**: Gets or sets the horizontal offset of the shadow in points. Positive values shift the shadow to the right, while negative values shift it to the left.

– **OffsetY**: Gets or sets the vertical offset of the shadow in points. Positive values shift the shadow downward, while negative values shift it upward.

sht.api.Range(‘A1:B7’).Select()

cht=sht.api.Shapes.AddChart().Chart

cha=cht.ChartArea    #Chart Area

cha.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((155,255,0))

cha.Shadow=True    #Plot area shows shadow

pla=cht.PlotArea    #Plot area

pla.Format.Fill.UserPicture(root+r’/picpy2.jpg’)    #Picture fill

cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))

cht.Axes(2).HasMajorGridlines=False

cha.Shadow=False

pla.Format.Shadow.Visible=True    #Plot area shows shadow

pla.Format.Shadow.OffsetX=3    #Horizontal offset of the shadow

pla.Format.Shadow.OffsetY=3    #Vertical offset of the shadow

 

【Example】

import xlwings as xw
import os

def set_style(cht):
    cht.ChartArea.Format.Line.Visible=False
    cht.PlotArea.Format.Fill.Visible=True
    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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1, \
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.PlotArea.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,26))
cht.PlotArea.Format.Fill.OneColorGradient(1,1,1)    #msoGradientHorizontal
      
set_style(cht)

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

#wb.save()
#app.kill()

How To Set Chart Title 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('A1:B7').Select()    #
cht=sht.api.Shapes.AddChart2(-1,\
          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart
cht.HasTitle=True
cht.ChartTitle.Caption='Chart Title'
cht.ChartTitle.Characters.Font.Name='Times New Roman'
cht.ChartTitle.Characters.Font.Size=16
cht.ChartTitle.Characters.Font.Bold=True
cht.ChartTitle.Characters.Font.Color=xw.utils.rgb_to_int((255,0,0))
      
set_style(cht)

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

#wb.save()
#app.kill()

How To Use SetElement Method Using xlwings?

【Method】

The `SetElement` method of the `Chart` object allows you to set chart elements for the specified chart. The method has one parameter that provides options for setting. The possible values of the parameter are shown in the table below.

Name

Value

Description

msoElementChartFloorNone

1200

Do not display chart floor

msoElementChartFloorShow

1201

Display chart floor

msoElementChartTitleAboveChart

2

Display title above the chart

msoElementChartTitleCenteredOverlay

1

Display title centered as overlay

msoElementChartTitleNone

0

Do not display chart title

msoElementChartWallNone

1100

Do not display chart background wall

msoElementChartWallShow

1101

Display chart background wall

msoElementDataLabelBestFit

210

Use best fit data labels

msoElementDataLabelBottom

209

Display data labels at the bottom

msoElementDataLabelCallout

211

Display data labels as callouts

msoElementDataLabelCenter

202

Centered data labels

msoElementDataLabelInsideBase

204

Display data labels inside the base

msoElementDataLabelInsideEnd

203

Display data labels inside the end

msoElementDataLabelLeft

206

Display data labels on the left

msoElementDataLabelNone

200

Do not display data labels

msoElementDataLabelOutSideEnd

205

Display data labels outside the end

msoElementDataLabelRight

207

Display data labels on the right

msoElementDataLabelShow

201

Display data labels

msoElementDataLabelTop

208

Display data labels at the top

msoElementDataTableNone

500

Do not display data table

msoElementDataTableShow

501

Display data table

msoElementDataTableWithLegendKeys

502

Display data table with legend keys

msoElementErrorBarNone

700

Do not display error bars

msoElementErrorBarPercentage

702

Display percentage error bars

msoElementErrorBarStandardDeviation

703

Display standard deviation error bars

msoElementErrorBarStandardError

701

Display standard error error bars

msoElementLegendBottom

104

Display legend at the bottom

msoElementLegendLeft

103

Display legend on the left

msoElementLegendLeftOverlay

106

Overlay legend on the left

msoElementLegendNone

100

Do not display legend

msoElementLegendRight

101

Display legend on the right

msoElementLegendRightOverlay

105

Overlay legend on the right

msoElementLegendTop

102

Display legend at the top

msoElementLineDropHiLoLine

804

Display drop line and high/low lines

msoElementLineDropLine

801

Display drop line

msoElementLineHiLoLine

802

Display high/low line

msoElementLineNone

800

Do not display lines

msoElementLineSeriesLine

803

Display series lines

msoElementPlotAreaNone

1000

Do not display plot area

msoElementPlotAreaShow

1001

Display plot area

How To Set Axis Reversing Using xlwings?

【Method】

axs.ReversePlotOrder=True

axs2.ReversePlotOrder=True

【Example】

【Code】

import xlwings as xw
import os

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

sht.api.Range('A1:B7').Select()    #
shp=sht.api.Shapes.AddChart()    #
shp.Left=20
cht=shp.Chart
axs=cht.Axes(1)    #
axs.Border.ColorIndex=3    #
axs.Border.Weight=3    #
axs2=cht.Axes(2)    #
axs.ReversePlotOrder=True
axs2.ReversePlotOrder=True

#wb.save()
#app.kill()

How To Set Crosses Using xlwings?

【Method】

Use the **AxisBetweenCategories** property of the **Axis** object to set the intersection point between the value axis and the category axis. If the value is `True`, the intersection occurs in the middle of the categories; if it is `False`, the intersection occurs at the middle point of the categories.

 

The **Crosses** property of the **Axis** object returns or sets the point at which the axis intersects with another axis. The possible values for this property are as follows:

 

Name

Value

Description

xlAxisCrossesAutomatic

-4105

Automatically set by Excel

xlAxisCrossesCustom

-4114

Set by **CrossesAt** property

xlAxisCrossesMaximum

2

Axis crosses at maximum value

xlAxisCrossesMinimum

4

Axis crosses at minimum value

 

sht.api.Range(‘A1:B7’).Select()

cht=sht.api.Shapes.AddChart().Chart

axs2=cht.Axes(2)

axs2.Crosses=2

#axs2.Crosses=-4114

#axs2.CrossesAt=50

 

【Example】

【Code】

import xlwings as xw
import os

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

sht.api.Range('A1:B7').Select()    #
shp=sht.api.Shapes.AddChart()    #
shp.Left=20
cht=shp.Chart
axs=cht.Axes(1)    #
axs.Border.ColorIndex=3    #
axs.Border.Weight=3    #
axs2=cht.Axes(2)    #
axs.Crosses=xw.constants.AxisCrosses.xlAxisCrossesMaximum
axs2.CrossesAt=10

#wb.save()
#app.kill()