Initial commit: update
This commit is contained in:
131
backend/target/backend-1/PARTImport.html
Normal file
131
backend/target/backend-1/PARTImport.html
Normal file
@@ -0,0 +1,131 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>Excel PART Import</title>
|
||||
<script src="/backend/xlsx/xlsx.full.min.js"></script>
|
||||
<script src="/backend/handsontable/handsontable/dist/handsontable.full.min.js"></script>
|
||||
<link rel="stylesheet" href="/backend/handsontable/handsontable/dist/handsontable.full.min.css">
|
||||
<link rel="stylesheet" href="/backend/hmi-theme/ios.css">
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
text-align: center;
|
||||
background-color: #f4f4f4;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
display: inline-block;
|
||||
}
|
||||
button {
|
||||
margin: 10px;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
background-color: red;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#import-table {
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h2>Excel Export & Import</h2>
|
||||
<button id="export-button">BOM Excel Export</button>
|
||||
<input type="file" id="file-input" accept=".xlsx">
|
||||
<button id="send-button">Daten Senden</button>
|
||||
<div id="import-table"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
let importedData = [];
|
||||
let hot; // Handsontable instance
|
||||
const url = sessionStorage.getItem("url") ;
|
||||
const stationNumber = sessionStorage.getItem("stationNumber");
|
||||
|
||||
function exportExcel() {
|
||||
const headers = ["Artikelnummer", "Artikelbeschreibung", "Artikelgruppe", "Materialcode", "Einheit", "Produktflag"];
|
||||
const worksheet = XLSX.utils.aoa_to_sheet([headers]);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, "Artikel");
|
||||
XLSX.writeFile(workbook, "ArtikelExport.xlsx");
|
||||
}
|
||||
|
||||
function importExcelData(event) {
|
||||
const fileInput = document.getElementById("file-input");
|
||||
if (!fileInput.files.length) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(event) {
|
||||
const workbook = XLSX.read(event.target.result, { type: "binary" });
|
||||
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||
importedData = XLSX.utils.sheet_to_json(sheet, { header: 1 }).slice(1);
|
||||
|
||||
if (hot) {
|
||||
hot.loadData(importedData); // Update existing Handsontable
|
||||
} else {
|
||||
const container = document.getElementById("import-table");
|
||||
hot = new Handsontable(container, {
|
||||
data: importedData,
|
||||
colHeaders:["MATERIAL_NO", "MATERIAL_DESC", "MATERIAL_GRP_NO", "MATERIAL_GRP_TYPE", "UNIT", "PRODUCT"],
|
||||
rowHeaders: true,
|
||||
width: '100%',
|
||||
height: 300,
|
||||
stretchH: 'all',
|
||||
autoColumnSize: false,
|
||||
manualColumnResize: true,
|
||||
colWidths: 120,
|
||||
wordWrap: false,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
});
|
||||
}
|
||||
};
|
||||
reader.readAsBinaryString(fileInput.files[0]);
|
||||
}
|
||||
|
||||
function sendExcelData() {
|
||||
|
||||
const jsonData = importedData.map(row => ({
|
||||
MATERIAL_NO: ""+row[0],
|
||||
MATERIAL_DESC: ""+row[1],
|
||||
MATERIAL_GRP_NO: ""+row[2],
|
||||
MATERIAL_GRP_TYPE: ""+row[3],
|
||||
UNIT: ""+row[4],
|
||||
PRODUCT: ""+row[5]
|
||||
}));
|
||||
if (!url) {
|
||||
alert("Backend URL is not defined.");
|
||||
return;
|
||||
}
|
||||
fetch(url + '/backend/api/updateParts', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ station: stationNumber, data: jsonData })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(result => alert("Daten erfolgreich gesendet!"))
|
||||
.catch(error => alert("Fehler beim Senden der Daten: " + error.message));
|
||||
}
|
||||
|
||||
// Event Listeners
|
||||
document.getElementById("export-button").addEventListener("click", exportExcel);
|
||||
document.getElementById("file-input").addEventListener("change", importExcelData);
|
||||
document.getElementById("send-button").addEventListener("click", sendExcelData);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user