pridane export body

This commit is contained in:
navry 2025-08-05 12:21:05 +02:00
parent 00ab98c9cc
commit 503d7724b4
5 changed files with 136 additions and 38 deletions

BIN
body_easy_exported.xlsx Normal file

Binary file not shown.

14
excel_labels.py Normal file
View File

@ -0,0 +1,14 @@
import pandas as pd
df = pd.read_excel('body_easy.xlsx', sheet_name='List1')
df_deduplicated = df.drop_duplicates(subset=['Název'], keep='first')
df_final = pd.concat([df, df_deduplicated]).sort_values(by=['x', 'y'])
df_final = df_final['Název'].reset_index(drop=True)
print(df_final)
df_final.to_excel('body_easy_exported.xlsx', sheet_name='List1', index=False, header=False)

View File

@ -7,8 +7,14 @@ importlib-metadata==8.5.0
itsdangerous==2.2.0
jinja2==3.1.6
markupsafe==2.1.5
numpy==1.24.4
openpyxl==3.1.5
pandas==2.0.3
pyparsing==3.1.4
python-dateutil==2.9.0.post0
pytz==2025.2
six==1.17.0
typing-extensions==4.13.2
tzdata==2025.2
werkzeug==3.0.6
zipp==3.20.2

View File

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -11,32 +12,72 @@
</head>
<body>
<header class="container"><h1>XLSX to DXF Converter</h1></header>
<header class="container">
<h1>XLSX to DXF Converter</h1>
</header>
<main class="container">
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file-input" name="file" accept=".xls, .csv, .xlsx" required>
<div class="grid">
<label for="range">Velikost textu
</label>
<input type="range" min="0.5" max="10" value="1" step="0.5" id="range" name="range">
<label id="font_size">1</label>
</div>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="file-input" name="file" accept=".xls, .csv, .xlsx" required>
<hr>
<div class="grid">
<div>
<label for="file-name">Název výstupního DXF</label>
<input type="text" id="file-name" name="output_file" placeholder="název výstupního DXF:" value="vystupni_body">
<input type="submit" id="submit-button" value="Nahrát a stáhnout hotový">
<div class="grid">
<label for="range">Velikost textu
</label>
<input type="range" min="0.5" max="10" value="1" step="0.5" id="range" name="range">
<label id="font_size">1</label>
</div>
</form>
<label for="file-name">Název výstupního DXF</label>
<input type="text" id="file-name" name="output_file" placeholder="název výstupního DXF:"
value="vystupni_body">
<button name="btn" type="submit" id="submit-button" value="dxf">Nahrát a stáhnout DXF</button>
<br>
<br>
</div>
<div>
<div>
<label for="range">Štítky nachystat pro:
</label>
<select id="select" name="select" required>
<option value="0" selected>praváka</option>
<option value="1">leváka</option>
</select>
</div>
<label for="file-name">Název souboru s popisky</label>
<input type="text" id="file-name" name="excel_output_file" placeholder="název výstupního DXF:"
value="popisy_vystup">
<button name="btn" id="excel-download" type="submit" value="excel">Nahrát a stáhnout
popisky</button>
</div>
</div>
</form>
</main>
</body>
<script>
document.getElementById('range').addEventListener('input', function() {
document.getElementById('font_size').innerText = this.value;
});
document.getElementById('range').addEventListener('input', function () {
document.getElementById('font_size').innerText = this.value;
});
</script>
<style>
#excel-download {
background-color: #34C759;
/* green background */
color: #033009;
font-weight: bold;
}
#font_size {
margin-left: 10px;
padding-bottom: 5px;
@ -46,4 +87,3 @@
</style>
</html>

74
test.py
View File

@ -1,9 +1,10 @@
from flask import Flask, request, render_template, send_file
from flask import Flask, request, render_template, send_file, make_response
from io import BytesIO, StringIO
import ezdxf
import openpyxl
import os
import sys
import pandas as pd
app = Flask(__name__)
@ -11,28 +12,65 @@ app = Flask(__name__)
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file.filename.endswith('.xls') or file.filename.endswith('.csv') or file.filename.endswith('.xlsx'):
# Create a text file with the uploaded file name
if request.form['btn'] == 'dxf':
if file.filename.endswith('.xls') or file.filename.endswith('.csv') or file.filename.endswith('.xlsx'):
# Create a text file with the uploaded file name
velikost = request.form['range']
nazev_souboru = request.form['output_file']
print(velikost)
velikost = request.form['range']
nazev_souboru = request.form['output_file']
print(velikost)
body = nacti_data_z_excelu(file)
#print(body)
body = nacti_data_z_excelu(file)
#print(body)
dxf_file = exportuj_do_dxf(body, velikost)
dxf_file.seek(0)
return send_file(
path_or_file=dxf_file,
as_attachment=True,
download_name= nazev_souboru+".dxf" or 'hotovson.dxf',
mimetype='application/octet-stream'
)
dxf_file = exportuj_do_dxf(body, velikost)
dxf_file.seek(0)
return send_file(
path_or_file=dxf_file,
as_attachment=True,
download_name= nazev_souboru+".dxf" or 'hotovson.dxf',
mimetype='application/octet-stream'
)
else:
return render_template('upload_form.html', no_file=True)
else:
return render_template('upload_form.html', no_file=True)
# Generate the download file
file_data = BytesIO(b"necum")
file_name = request.form['excel_output_file']
df = pd.read_excel(file, sheet_name='List1')
df_deduplicated = df.drop_duplicates(subset=['Název'], keep='first')
df_final = pd.concat([df, df_deduplicated]).sort_values(by=['x', 'y'], ascending=request.form.get('select')== '1')
df_final = df_final['Název'].reset_index(drop=True)
df_final.to_excel(file_data, sheet_name='List1', index=False, header=False)
file_data.seek(0)
return send_file(
path_or_file=file_data,
as_attachment=True,
download_name= file_name+".xlsx" or 'hotovson.xlsx',
mimetype='application/octet-stream'
)
return render_template('upload_form.html')
@app.route('/excel_labels', methods=['GET', 'POST'])
def excel_labels():
# Generate the download file
file_data = BytesIO(b"necum")
file_name = 'download_file.xlsx'
response = make_response(send_file(file_data, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'))
response.headers['Content-Disposition'] = f'attachment; {file_name}'
return response
def nacti_data_z_excelu(soubor, listname="List1"):
wb = openpyxl.load_workbook(soubor, data_only=True)
sheet = wb[listname]
@ -76,4 +114,4 @@ def exportuj_do_dxf(body, velikost) -> BytesIO:
if __name__ == '__main__':
app.run(debug=False, port=5003, host='0.0.0.0')
app.run(debug=True, port=5003, host='0.0.0.0')