Estoy tratando de insertar ciertos valores en un archivo xls o xlsx, que se han obtenido en JavaScript para la función python. ¿Cómo puedo insertar los valores de la función de JavaScript en la función de python?
Este es mi código Python:
import xlwt from xlwt import Workbook @app.route('/Import_to_excel', methods=['GET', 'POST']) def Import_to_excel(): x = request.args.get('id0') y = request.args.get('id1') z = request.args.get('id2') array = [ ip, app, ver] wb = Workbook() sheet1 = wb.add_sheet('Sheet 1') sheet1.write(0, 0, array[0]) sheet1.write(0, 1, array[1]) sheet1.write(0, 2, array[2]) wb.save('xlwt example.xls') return "success"También he estado tratando de publicar una lista con los valores, en lugar de publicar individualmente los valores uno por uno. Pero tengo algunos problemas con request.args.getlist() en el lado de Python.
Esta es mi función JavaScript
function Import_to_excel() { id0 = document.getElementById("x").text id1 = document.getElementById("y").value id2 = document.getElementById("z").value const input_values = [ id0, id1, id2]; fetch('http://127.0.0.1:5000/Import_to_excel?id0='+id0 ).then(resp => resp.json()) fetch('http://127.0.0.1:5000/Import_to_excel?id1='+id1 ).then(resp => resp.json()) fetch('http://127.0.0.1:5000/Import_to_excel?id2='+id2 ).then(resp => resp.json()) }La salida en mi archivo xls está en blanco.
código pitón
id = request.args.get('ID') x = id.split('_*_')[0] y = id.split('_*_')[1] z = id.split('_*_')[2]JavaScript
var x = document.getElementById("x").value; var y = document.getElementById("y").value; var z = document.getElementById("z").value; var a = 'http://127.0.0.1:5000/initiate_excel_corvert?ID='x+'_*_'+y+'_*_'+z+'_*_' fetch(a) .then(res => res.json()) .then(res => console.log(res)); }