xlwings

When Excel addin runs 'RunPython()', Workbook.caller() raise an error

孤者浪人 提交于 2019-12-12 05:16:08
问题 I found xlwings is a very exceptional project as a bridge between Excel and Python. So I am applying it to my excel addin development. But I got some problem. When excel addin calls python module, the Workbook.caller() does not return Workbook object(addin workbook itself)! Just Error! Instead of Workbook.caller(), I make use of 'Workbook() passing by 'Current ActiveWorkbook's name'. But in that case, I'm afraid that 'Optimize_connection= true' may raise memory garbage issue! (If 'IsAddin'

Overwriting data to an existing workbook using Python

£可爱£侵袭症+ 提交于 2019-12-12 04:08:44
问题 I am new to Python and working on a project that I could use some help on. So I am trying to modify an existing excel workbook in order to compare stock data. Luckily, there was a program online that retrieved all the data I need and I have successful been able to pull the data and write the data into a new excel file. However, the goal is to pull the data and put it into an existing excel file. Furthermore, I need to overwrite the cell values in the existing file. I believe xlwings is able

how to wait for xlwings to complete python code in vba?

萝らか妹 提交于 2019-12-11 19:23:10
问题 I am calling RunPython in VBA from the xlwings module with the following code: Sub Portfolio_Optimze() RunPython ("import quotes; quotes.get_quote()") SolverAdd CellRef:="$H$18:$H$24", Relation:=1, FormulaText:="$J$18:$J$24" SolverAdd CellRef:="$B$15:$G$15", Relation:=4 SolverOk SetCell:="$H$16", MaxMinVal:=1, ValueOf:=0, ByChange:="$B$15:$G$15", _ Engine:=1, EngineDesc:=" GRG Nonlinear " SolverSolve How do i make the SolverAdd code wait until the RunPython code is completely finished? 回答1:

Find range of filled contents in Excel worksheet

拟墨画扇 提交于 2019-12-11 16:40:09
问题 I have an Excel 2016 Book.xlsm . In the worksheet testsheet , the cells in the range A1:Y150 are filled with text or number contents. The upper-left cell is always A1 . I am using python v3 xlwings to open the Excel file. import xlwings as xw Book_name = 'C:/Users/name/Book.xlsm' sheet_name = 'testsheet' wb = xw.Book(Book_name) sht = wb.sheets[sheet_name] How do I find out the range of cells that are filled with contents using python, which in this case is A1:Y150 ? 回答1: If wb is defined as

ImportError: cannot import name 'Workbook' using from xlwings import Workbook

时间秒杀一切 提交于 2019-12-11 13:20:02
问题 I am using xlwings to write and read data from Excel files using python 3.4 (Anaconda package). I installed xlwings with pip install xlwings Update: I realized that I might not have given enough info about what I am trying to do. So here it is: I am writing my code in the editor called Spyder. What I usually do is, I put the "import commands" at the beginning of my code. However, when I run the code, the "import command" for xlwings would not work and gives me the "ImportError" I am taking

xlwings Workbook() call returns AttributeError: Open.Application

倖福魔咒の 提交于 2019-12-11 10:43:54
问题 Hope you can help me out, first question I ask myself but I am always impressed by the professional answers I find here! I am using xlwings to both read and write data from .xls files. I am not a seasoned programmer, and I make mistakes. From time to time, this means rebooting processes, Python and what-not. Every now and again, I would get the following AttributeError upon calling Workbook() . The real problem is not that I don't have a clue what is happening (I tried reading the modules the

set chart name in Xlwings

徘徊边缘 提交于 2019-12-11 07:36:51
问题 When I plot a chart by xlwings, I can't change chart name. The chart name and legend name are still 'Series 1', but the upper left corner shows 'Feb sales' which is I want import xlwings as xw sht = xw.Book().sheets[0] sht.range('A1').value = list(zip([1, 2, 3, 4])) chart = sht.charts.add() chart.set_source_data(sht.range('A1').expand()) chart.chart_type = 'line_markers' chart.name='Feb sales' #chart.api.ChartTitle.Text = 'Feb sales' #chart.delete() created chart Is this a known issue? How

Differences between xlwings vs openpyxl Reading Excel Workbooks

孤者浪人 提交于 2019-12-11 05:23:30
问题 I've mostly only used xlwings to open ( read-write ) workbooks (since the workbooks I read have complicated macros). But I've recently begun using openpyxl to open ( read-only ) workbooks when I've needed to read thousands of workbooks to scrape some data. I've noticed that there is a considerable difference between how xlwings and openpyxl read workbooks. I believe xlwings relies on pywin32 to read workbooks. When you read a workbook with xlwings.Book(<filename>) the actual workbook opens up

Zombie process using xlwings

冷暖自知 提交于 2019-12-11 05:15:41
问题 When I use xlwings to automate stuff in excel, I still have EXCEL zoombie process running even if I quit the application (with wb.Application(wb).quit()). Thus, when I try to re open my excel file that bugs. I have to manually kill the excel application. edit : I use the xlwings 0.7.0 回答1: The issue is that wb is a global reference to your workbook which still exists even after executing the quit command. Excel sees that it is being referenced (through COM) and thus refuses to shut down

Xlwings take value from defined names

若如初见. 提交于 2019-12-11 05:01:52
问题 I have an excel with a defined name, cell A1 has assigned name "myName" is there a way with xlwings to take its content from its name rather than on its coordinates? It should be the same of title, coord = next(wb.defined_names['myName'].destinations) content = wb[title][coord].value in openpyxls 回答1: Sure, just do: import xlwings as xw xw.sheets[0].range('myName').value See also: http://docs.xlwings.org/en/stable/api.html#name 回答2: Using xlwings, very similarly to VBA, you could use the