Home > database >  How to write in my excel file by taking data from an HTML form under the previous data in next rows?
How to write in my excel file by taking data from an HTML form under the previous data in next rows?

Time:04-21

@app.route('/home/form', methods=('GET','POST'))
def form():

if request.method == 'POST':
    machine = request.form['machine']
    df = pd.DataFrame([[machine]], columns=["Machine"])
    with pd.ExcelWriter('P:\\Rohaan\\LATEST WEBSITE\\sample.xlsx') as writer:
        df.to_excel(writer)

    if not machine:
        flash('Title is required!')
    else:
        return redirect(url_for('home'))
return render_template('form.html')

if name == "main": app.run(debug=True)

enter image description here

CodePudding user response:

Currently getting this result using this code

@app.route('/home/form', methods=('GET','POST'))
def form():

if request.method == 'POST':
    machine = request.form['machine']
    df = pd.DataFrame([[machine]], columns=["Machine"])
    with pd.ExcelWriter('P:\\Rohaan\\LATEST WEBSITE\\sample.xlsx') as writer:
        df.to_excel(writer)

    if not machine:
        flash('Title is required!')
    else:
        return redirect(url_for('home'))
return render_template('form.html')
if name == "main": app.run(debug=True)

enter image description here

CodePudding user response:

According to documentation you should specify mode = "a" if you want to append and not override (default is mode = "w") inside ExcelWriter, but if it is actually supported is probably dependent on the chosen excel engine.

CodePudding user response:

HTML Code

<form method="post">
  <label for="Machine">Machine</label>
  <br>
  <input type="text" name="machine"
        placeholder="Message machine"
        value=''></input>
  <br>

  <label for="content">Message Content</label>
  <br>
  <textarea name="content"
            placeholder="Message content"
            rows="15"
            cols="60"
            ></textarea>
  <br>
  <button type="submit">Submit</button>
</form>
  • Related