xlwings

Replicating YEARFRAC() function from Excel in Python

谁说我不能喝 提交于 2019-12-09 13:19:02
问题 So I am using python in order to automate some repetitive tasks I must do in excel. One of the calculations I need to do requires the use of yearfrac(). Has this been replicated in python? I found this but it is incorrect for the value I tried. (From 12/19/2011 to 3/31/17, yearfrac() gives 5.2833333333333300000, but the python function in the link gives 5.2807978099335156.) 回答1: I found an e-mail thread from actual Office developers providing a VBA implementation of the YEARFRAC algorithm.

Running xlwings on a server

ε祈祈猫儿з 提交于 2019-12-08 12:15:45
问题 Solved the problem by making sure that python27.dll and win32api into the PYTHON_WIN directory. The two files with an arrow were missing in the server folder (P:/) I am using udf module of xlwings and setting xlwings.bas configuration into a server. (I have my personal disk C:/ however other users need to run this macro and the file must be stored in P:/) I have python, xlwings and other modules installed in P:/, but I get some strange error about importing os lib. Does any one have ever

Passing a variable from Excel to Python with XLwings

旧巷老猫 提交于 2019-12-08 07:26:51
问题 I am trying write a simple user defined function in Python that I pass a value to from Excel via Xlwings . I ran across some examples with an Add-in that you need to import user defined functions, but that seems overly complex. Why isn't my example working? VBA: Function Hello(name As String) As String RunPython ("import Test; Test.sayhi(name)") End Function Python ( Test.py ): from xlwings import Workbook, Range def sayhi(name): wb = Workbook.caller() return 'Hello {}'.format(name) Error:

Xlwings UDFs while using frozen Python file

拜拜、爱过 提交于 2019-12-07 12:48:26
问题 I am trying to integrate xlwings with an excel spreadsheet that we use on our network drive. However, I do not want to install Python, Xlwings, or any other modules on any computer except for the developers. In addition, I would like to use UDFs only, we do not have an interest in using Macros. I read here (https://www.reddit.com/r/Python/comments/22i4a1/xlwings_the_easiest_way_to_deploy_your_python/) that there is a way to freeze your python script which would prevent the need for all users

How do I save a workbook using xlwings?

江枫思渺然 提交于 2019-12-07 01:40:27
问题 I have an excel worksheet, some buttons and some macros. I use xlwings to make it work. Is there a way to save the workbook through xlwings ? I want to extract a specific sheet after doing an operation, but the saved sheet is the extracted sheet before the operation without the generated data. My code for extracting the sheet I need is the following: Set objFSO = CreateObject("Scripting.FileSystemObject") src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(0)) sheet_name = Wscript

Passing a variable from Excel to Python with XLwings

烈酒焚心 提交于 2019-12-06 15:53:05
I am trying write a simple user defined function in Python that I pass a value to from Excel via Xlwings . I ran across some examples with an Add-in that you need to import user defined functions, but that seems overly complex. Why isn't my example working? VBA: Function Hello(name As String) As String RunPython ("import Test; Test.sayhi(name)") End Function Python ( Test.py ): from xlwings import Workbook, Range def sayhi(name): wb = Workbook.caller() return 'Hello {}'.format(name) Error: NameError: name 'name' is not defined Make sure you're supplying the argument correctly: RunPython (

xlwings UDFS: how to set PythonPath/ UDF_Modules correctly?

爱⌒轻易说出口 提交于 2019-12-06 13:16:45
问题 Thank you for your time first! Recently I have been trying to build my own excel functions by using Xlwings. Unlike using $ xlwings quickstart myproject which would create a python script in the same directory as the excel xlsm file, I would love to put the python script anywhere I want, like "D:\test0.py", so I did this on VBA Function Settings: PYTHONPATH = "D:\test0.py" UDF_MODULES = "test0" Except the two lines above, I didn't change anything in Function Settings. However, what I got is

xlwings - Delete a range of rows

江枫思渺然 提交于 2019-12-06 12:19:46
I can't seem to find a way to be able to delete a range of rows starting at row x and going to the bottom of the sheet For example in VBA code I would do Rows(CStr(currRow) & ":65536").Select Selection.Delete Shift:=xlUp where currRow could be anything - i.e I don't necessarily want to delete everything from the sheet Is there an equivalent in xlwings? There's an open issue to take care of that. In the meantime, as usual, you can work around as explained in the docs . In your case, something like the following should do (using v0.9 syntax): import xlwings as xw from xlwings.constants import

xlwings: Save and Close

∥☆過路亽.° 提交于 2019-12-06 07:28:48
I am trying to find out how to save and close to an existing workbook using xlwings after writing in it: import xlwings as xw list_of_values = [1, 2, 3] workbook_path = 'abc.xlsx' wb = xw.Book(workbook_path) ws = wb.sheets['sheet1'] ws.range('E35').value = list_of_values wb.save() wb.close() When I get to wb.save(workbook_path) , there is a prompt stating: 'A file named abc.xlsx' already exists in this location. Do you want to replace it?' I want to overwrite the file immediately without the prompt coming up. According to the docs, wb.save() should automatically overwrite (see: https://docs

Xlwings UDFs while using frozen Python file

时光总嘲笑我的痴心妄想 提交于 2019-12-06 03:38:18
I am trying to integrate xlwings with an excel spreadsheet that we use on our network drive. However, I do not want to install Python, Xlwings, or any other modules on any computer except for the developers. In addition, I would like to use UDFs only, we do not have an interest in using Macros. I read here ( https://www.reddit.com/r/Python/comments/22i4a1/xlwings_the_easiest_way_to_deploy_your_python/ ) that there is a way to freeze your python script which would prevent the need for all users to have Python installed. As a result, I used cx_Freeze to freeze my script. Assume I have these