xlwings

使用xlwings拆分excel并调用outlook进行邮件发送

自古美人都是妖i 提交于 2020-02-03 03:57:31
写这段代码的起因是因为公司要下发一个销售日报表,但是由于不同部门的销售区域老总看到的只能是自己区域的数据,每个工作簿有10多个工作表,如果靠手工来做工作量极大,因此,有迫切的需求要对报表做一些自动化操作,并能自动发送邮件。在做到以上的基础上,还要顾及美观。 表格的截图如下: 可以看到这个表格处理的几个关键点: 1、有组合,要取消组合,目前python还没法实现(我没找到办法),所以必须要调用VBA 2、有隐藏的sheet,其实是3级组合,要展示出来 3、要根据2级组合里的区域,分别发给对应的区域 4、要保留原格式 import xlwings as xw import win32com.client as win32 程序运行的时候不显示在前端,也不新建Excel窗口 app = xw.App(visible=False,add_book=False) ywb = ["浙江部","河南部","KA部","黑龙江部","广西部","江西部","海南部","广东部"] for i in range(0,len(ywb)): # 这是循环的开始,读取业务部的数量,每个业务部作为一个最大的循环 # print(i) iw = app.books.open(r'E:\Documnet\工作\07_数据分析\临时文件\副本.xlsm') sheet_count = iw.sheets

Does xlwings support “Wrap Text” property?

≯℡__Kan透↙ 提交于 2020-01-25 00:13:05
问题 Can I control the "Wrap Text" property of a cell using Python+xlwings? 回答1: It's currently not implemented but I've opened a feature request here. In the meantime, you can always work around by accessing the underlying COM object on Windows: Range('A1').xl_range.WrapText = True or appscript object on Mac: Range('A1').xl_range.wrap_text.set(True) . 回答2: For anybody like me who comes to this now and doesn't find these solutions are working, I found accessing the pywin32 API directly with work

Possible bug? xlwings cannot run an Excel macro? [duplicate]

南楼画角 提交于 2020-01-15 01:51:10
问题 This question already has answers here : How do I call an Excel macro from Python using xlwings? (3 answers) Closed 3 years ago . I am having a problem getting xlwings to run a macro from Python. Despite following the code from xlwings documentation, I cannot get xlwings to execute an Excel macro. For instance, in Excel workbook named "Book.xlsm": ' in Excel workbook Book.xlsm Sub Test() Set ws = Worksheets("ABC") ws.Range("A1").Value = 10 End Sub This macro runs OK within Excel. But when I

xlwings和openpyxl的区别

旧街凉风 提交于 2020-01-06 21:58:32
摘自 https://stackoverflow.com/questions/58328776/differences-between-xlwings-vs-openpyxl-reading-excel-workbooks xlwings:依赖于pywin32,需要安装有excel软件,支持.xls和.xlsx格式 openpyxl:不需要excel软件,仅支持.xlsx格式 You are correct in that xlwings relies on pywin32 , whereas openpyxl does not. openpyxl A ".xlsx" excel file is essentially a zip-file containing multiple XML files formatted according to Microsoft's OOXML specification . With this specification it's possible to create a program capable of directly reading/writing excel files in just about any programming language. This is the approach applied in openpyxl :

Can I Have xlwings Display Console Output?

痴心易碎 提交于 2020-01-06 09:01:46
问题 Is it possible for xlwings to pop up a console while running a script from VBA and show stdout? I know xlwings writes the stdout to a logfile which is useful, but I'd like to give users some updates while they are waiting for their calculation to finish. The debugger kind of does this but seems like overkill. 回答1: If you are using UDFs, then there is a simple possibility: By default xlwings uses the pythonw interpreter. Just change it to python and the console window will pop up. For

Read Excel Table headers with xlwings

孤者浪人 提交于 2020-01-05 07:31:09
问题 How can I use xlwings to read a "table" in excel, into a pandas DataFrame, where the table "headers" become the DataFrame column names? Every way I have tried to read the table, the header row is always excluded from the read! Here is what I've tried, where "b" is my xlwings workbook object: b.sheets['Sheet1'].range('Table1').options(pd.DataFrame) b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=False) b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=True) 回答1:

Read Excel Table headers with xlwings

ε祈祈猫儿з 提交于 2020-01-05 07:30:50
问题 How can I use xlwings to read a "table" in excel, into a pandas DataFrame, where the table "headers" become the DataFrame column names? Every way I have tried to read the table, the header row is always excluded from the read! Here is what I've tried, where "b" is my xlwings workbook object: b.sheets['Sheet1'].range('Table1').options(pd.DataFrame) b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=False) b.sheets['Sheet1'].range('Table1').options(pd.DataFrame, headers=True) 回答1:

Copying a worksheet with xlwings and python

萝らか妹 提交于 2020-01-02 00:44:09
问题 I have been using xlwings in Python, but have not been able to figure out how to copy a worksheet. I want to treat a particular worksheet as a template, and copy that worksheet each time before making modifications. I am using version 0.11.4 of xlwings. If such functionality is not built in, I am okay with going outside of xlwings to use pywin32 functions in order to accomplish this. 回答1: After poking around in several places and reading the pywin32 documentation, I found a solution to copy

Kill xlwings Python process on workbook close when using optimized connection

a 夏天 提交于 2019-12-24 18:31:11
问题 I want to start using "optimized connection" feature of xlwings (v 0.11.4), but I would like to be able to kill Python process when I close the workbook (even if Excel instance is still running). I couldn't find any information on this in topic in xlwings documentation. Anyone had a similar problem and found a solution? 回答1: The link below might be helpful where you can quit app directly (which will close and kill excel application). I cannot close Excel 2016 after executing a xlwings

xlwings wipes out my EXCEL addin

倖福魔咒の 提交于 2019-12-24 14:34:18
问题 I own a professional Addin for EXCEL called Valuesoft. It performs several calculations related to equity (stockmarket) data. It is a 160K dll file and works fine from EXCEL including from VBA scripts. However, as soon as an EXCEL file (Workbook) is opened using xlwings from Python the dll disappears (along with the Addins tag on the EXCEL menu). 回答1: This question or this msdn article seem to explain what's happening and give you a workaround. Since you are using an xll add-in, adopting msdn