ik probeer resultaten van mijn berekening te exporteren naar Excel (d.m.v Download button) maar het lukte mij niet. Ik heb ook een simpele code die op jullie doc. staat getest maar toch niets opgeleverd.
Ik krijg de volgende foutmelding:
Traceback (most recent call last):
File "viktor_connector/connector.pyx", line 636, in connector.Job.execute
File "viktor/core.pyx", line 1513, in viktor.core._handle_job
File "/usr/src/app/app/viktor_code/concrete/krimpwapening/controller.py", line 187, in download_spreadsheet_krimpwap_pdf
result = self.get_spreadsheet_krimpwapening(params, entity_id)
File "/usr/src/app/app/viktor_code/concrete/krimpwapening/controller.py", line 170, in get_spreadsheet_krimpwapening
result = template.render()
File "viktor/external/spreadsheet.pyx", line 503, in viktor.external.spreadsheet.SpreadsheetTemplate.render
File "viktor/external/spreadsheet.pyx", line 593, in viktor.external.spreadsheet._call_fill_spreadsheet_addon
File "/usr/local/lib/python3.7/base64.py", line 80, in b64decode
s = _bytes_from_decode_data(s)
File "/usr/local/lib/python3.7/base64.py", line 46, in _bytes_from_decode_data
"string, not %r" % s.__class__.__name__) from None
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
Graag hoor ik van jullie hoe ik dit probleem kan oplossen.
Grt, Mohamed
Iāll answer in English if you donāt mind! The error occurs because the function is working with a NoneType (or an empty variable). Can you show what happens in the self.get_spreadsheet_krimpwapening function? There is probably something wrong with how you set up the template object. If you use the code shown in the docs, try to print file and cells, and check of they look like what you expect.
Instead of your template, the variable āfileā only contains the bytes content for the text āmy_templateā. You need to replace that with the bytes-content from your spreadsheet. You can do that as follows:
with open(template_path, 'rb') as f:
template_as_bytes = BytesIO(f.read())
Also your ācellsā variable is just an empty list as everything is commented out, but I a assume that just happened with debugging
I would advise to use the (newer) render_spreadsheet function. It results in cleaner/shorter code. Also you donāt have to convert to BytesIO but can immediately pass the opened binary file handle. An example can be found here:
Hello, I am trying the same* and I keep getting these kind of errors:
File "viktor\external\spreadsheet.pyx", line 510, in viktor.external.spreadsheet.render_spreadsheet
File "viktor\external\spreadsheet.pyx", line 563, in viktor.external.spreadsheet._call_fill_spreadsheet_addon
File "viktor\core.pyx", line 1184, in viktor.core._post_on_addon_endpoint
viktor.errors.InternalError: An unexpected error occurred
the code in my app is the following:
# in parametrization:
general.download_btn = DownloadButton("Download file", "get_download_result", longpoll=True)
# in controller:
def get_download_result(self):
cells = [
DirectInputCell('sheet1', 'A', 1, 5)
]
template_path = Path(__file__).parent / 'Export_test.xlsx'
with open(template_path, 'rb') as template:
filled_spreadsheet = render_spreadsheet(template, cells)
return DownloadResult(file_content=filled_spreadsheet, file_name='Export_test_INGEVULD.xlsx')
These seem like the steps as described in the docs and in this topic. What should I do to make it work?
The code indeed seems to be correct. One thing I cannot check is that the name of your sheet corresponds to the name you are using the DirectInputCell (i.e. sheet1 is present in your Excel workbook). I would expect a similar error if the sheet name isnāt present in your Excel workbook.