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
Add empty cells used by ranges into the ExcelModel #42
Comments
cc @vinci1it2000 Any light on this issue? still there I think |
The problem is the input data names. The convention is that they have to be UPPERCASE. I replicated your problem using a sample excel named book.xlsx. The following code is the solution:
The resulting excel output file (i.e., ./outputs/BOOK.XLSX) has the cell
I hope that this explanation can be useful for your development by using formulas. |
So, I think the uppercase thing is an issue, but it's not the real issue in the example. I have everything uppercase and it still doesn't work. However, I think it's due to the fact that I don't have all the cells pre-defined in my excel. Some of them are empty so they are not initialized. Your example assumes that whatever inputs you give are also in the initial XLS file (book.xls in your example). Somehow the cells should be created if you provide an input that's not already in the initial input file. Does this make sense? |
I tested the previous code cleaning the prefilled cells and it is working. Probably you have some range with empty values in your formulas, so in this case, the excel file is compiled differently. I made a change in the library that can solve your problem. You can temporarily use the commit 5a4f132 (I will release soon a new official release). I made a simple test case using a new sample excel partially pre-filled named new_book.xlsx. The following code shows how to use the library:
|
Close with the new release v1.0.0. |
I downloaded the latest code from github and wrote a very simple test. I have a formula in an excel spreadsheet BOOK1.XLS with
Result = X+Y+Bias stored in excel in 3 tabs Inputs, Data, Outputs as:
Outputs!B3 = Inputs!B3 + Inputs!B4 + Data!B5
I wrote a piece of code based on the README.rst file. I load the excel file, I supply my own inputs, calculate but when I call write() I get an error in line 264 of the file /formulas/excel/init.py:
Exception has occurred: AttributeError
'int' object has no attribute 'ranges'
The line in question is:
rng = r.ranges[0]
I debugged into the write() function of init.py and found that r has the last value of my inputs which is 8 and k for whatever is worth has "'[BOOK1.XLSX]Data'!B5"
It looks to me like r should contain a dictionary with the keys 'excel' and 'sheet' but based on the sample code in README.rst I don't understand how are these being passed. So either there's a bug in the write() function or the sample code in README doesn't work.
The test code is below:
import formulas
fpath = '
/formula_test/Book1.xlsx'/formula_test/output'dir_output = '
xl_model = formulas.ExcelModel().loads(fpath).finish()
xl_model.calculate(
inputs={
"'[BOOK1.XLSX]Inputs'!B3": 6, # Value X.
"'[BOOK1.XLSX]Inputs'!B4": 8, # Value Y.
"'[BOOK1.XLSX]Data'!B5": 8 # Value Y.
},
outputs=[
"'[BOOK1.XLSX]Outputs'!B3"
]
# To define the outputs that you want to calculate.
)
xl_model.write()
The text was updated successfully, but these errors were encountered: