简体   繁体   English

使用 Python xlsxwriter 在工作簿中运行 VBA 宏

[英]Run VBA macro in workbook using Python xlsxwriter

I am a Python beginner so please have some patience.我是 Python 初学者,所以请耐心等待。

I wonder is there a way that I can open and run a macro Excel code in a opened workbook before I close it ?我想知道有没有一种方法可以在关闭之前在打开的工作簿中打开和运行宏 Excel 代码?

Here is a part of the code :这是代码的一部分:

workbook = xlsxwriter.Workbook('Somedata.xlsx')
worksheet = workbook.add_worksheet()

# Write some numbers, with row/column notation.
# "save","identifier", "ISIN" "name" are just lists with data

worksheet.write_column(0, 1, save * number_of_rows)
worksheet.write_column(0, 2, identifier * number_of_rows)
worksheet.write_column(0, 3, ISIN)
worksheet.write_column(0, 4, name)


# Set coulmns width

worksheet.set_column('A:A', 15)
worksheet.set_column('B:C', 4)
worksheet.set_column('D:D', 13)
worksheet.set_column('E:E', 55)


workbook.close()

Thanks:)谢谢:)

This link explains it https://xlsxwriter.readthedocs.io/working_with_macros.html这个链接解释了https://xlsxwriter.readthedocs.io/working_with_macros.html

You have to extract vbaProject.bin file and than add it to the XlsxWriter workbook using the add_vba_project() method:您必须提取 vbaProject.bin 文件,然后使用 add_vba_project() 方法将其添加到 XlsxWriter 工作簿:

workbook.add_vba_project('./vbaProject.bin') workbook.add_vba_project('./vbaProject.bin')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM