Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with xw.Book(...) as wb leaves empty Excel instance behind #2414

Open
fzumstein opened this issue Mar 12, 2024 · 2 comments
Open

with xw.Book(...) as wb leaves empty Excel instance behind #2414

fzumstein opened this issue Mar 12, 2024 · 2 comments

Comments

@fzumstein
Copy link
Member

I use the with statement to manipulate Excel objects like this:

with xw.Book("excel股票分表.xlsx") as wb:
    for sheet in wb.sheets:
        print(sheet.name)
        # 设置日期列单元格的格式
        sheet.range("A:A").number_format = "yyyy-mm-dd"
        chart = sheet.charts.add()
        chart.chart_type = 'line'
        chart.set_source_data(sheet.range("A1").expand())
        chart.name = "5/10周期均线图"
        sheet.range("H2").value = "5/10周期均线图"
        # 设置图表位置
        chart.left = sheet.range("F3").left
        chart.top = sheet.range("F3").top
        # 设置坐标轴名称
        chart.api[1].Axes(1).HasTitle = True  # X轴
        chart.api[1].Axes(1).AxisTitle.Text = '日期'
        chart.api[1].Axes(2).HasTitle = True  # Y轴
        chart.api[1].Axes(2).AxisTitle.Text = '价格'
        # 设置坐标轴标签倾斜度
        chart.api[1].Axes(1).TickLabels.Orientation = 30
    wb.save()

Excel does not exit when the with statement is finished, instead, leave an empty Excel program like this:
1710250205306
I can't handle it through use

for app in xw.apps:
    app.quit()

or

xw.apps.active.quit()

the empty Excel program does not appear to be recognized by xlwings,
What should I do?
Looking forward to your reply!

Originally posted by @huapeiyou in #1404 (comment)

@fzumstein
Copy link
Member Author

@huapeiyou in the future, please open a separate issue for each topic. I've come across this myself and I am actually not sure right now if this has to do with a change in recent versions of Excel, so will need to investigate.

@huapeiyou
Copy link

Ok, I hope it can be resolved soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants