Dateien nach "backend/src/main/webapp" hochladen
This commit is contained in:
@@ -5,8 +5,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||||
<title>Excel Contact Import & Export</title>
|
<title>Excel Contact Import & Export</title>
|
||||||
<script src="/backend/xlsx/xlsx.full.min.js"></script>
|
<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/ios.css">
|
<link rel="stylesheet" href="/backend/ios.css">
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -33,6 +31,41 @@
|
|||||||
}
|
}
|
||||||
#import-table {
|
#import-table {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
|
max-width: min(1200px, calc(100vw - 80px));
|
||||||
|
max-height: 420px;
|
||||||
|
overflow: auto;
|
||||||
|
border: 1px solid var(--ios-border, rgba(255,255,255,.14));
|
||||||
|
border-radius: 14px;
|
||||||
|
}
|
||||||
|
#import-table table {
|
||||||
|
width: max-content;
|
||||||
|
min-width: 100%;
|
||||||
|
border-collapse: separate;
|
||||||
|
border-spacing: 0;
|
||||||
|
}
|
||||||
|
#import-table th,
|
||||||
|
#import-table td {
|
||||||
|
min-width: 120px;
|
||||||
|
padding: 9px 12px;
|
||||||
|
border-right: 1px solid var(--ios-separator, rgba(255,255,255,.1));
|
||||||
|
border-bottom: 1px solid var(--ios-separator, rgba(255,255,255,.1));
|
||||||
|
text-align: left;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
#import-table th {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
background: var(--ios-surface-strong, #151b2c);
|
||||||
|
}
|
||||||
|
#import-table td[contenteditable="true"]:focus {
|
||||||
|
outline: 2px solid var(--ios-blue, #4f7cff);
|
||||||
|
outline-offset: -2px;
|
||||||
|
background: rgba(79,124,255,.12);
|
||||||
|
}
|
||||||
|
.empty-preview {
|
||||||
|
padding: 18px;
|
||||||
|
color: var(--ios-muted, rgba(255,255,255,.6));
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
@@ -48,7 +81,7 @@
|
|||||||
<script>
|
<script>
|
||||||
document.addEventListener("DOMContentLoaded", function () {
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
let importedData = [];
|
let importedData = [];
|
||||||
let hot; // Handsontable instance
|
let importedHeaders = [];
|
||||||
const url = sessionStorage.getItem("url");
|
const url = sessionStorage.getItem("url");
|
||||||
const stationNumber = sessionStorage.getItem("stationNumber");
|
const stationNumber = sessionStorage.getItem("stationNumber");
|
||||||
|
|
||||||
@@ -76,49 +109,84 @@
|
|||||||
.catch(error => alert("Fehler beim Exportieren: " + error.message));
|
.catch(error => alert("Fehler beim Exportieren: " + error.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
function importExcelData(event) {
|
function renderImportTable() {
|
||||||
|
const container = document.getElementById("import-table");
|
||||||
|
container.replaceChildren();
|
||||||
|
|
||||||
|
if (!importedHeaders.length || !importedData.length) {
|
||||||
|
const empty = document.createElement("div");
|
||||||
|
empty.className = "empty-preview";
|
||||||
|
empty.textContent = "Keine Importdaten vorhanden.";
|
||||||
|
container.appendChild(empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const table = document.createElement("table");
|
||||||
|
const thead = document.createElement("thead");
|
||||||
|
const headerRow = document.createElement("tr");
|
||||||
|
importedHeaders.forEach(header => {
|
||||||
|
const th = document.createElement("th");
|
||||||
|
th.textContent = header == null ? "" : String(header);
|
||||||
|
headerRow.appendChild(th);
|
||||||
|
});
|
||||||
|
thead.appendChild(headerRow);
|
||||||
|
table.appendChild(thead);
|
||||||
|
|
||||||
|
const tbody = document.createElement("tbody");
|
||||||
|
importedData.forEach((row, rowIndex) => {
|
||||||
|
const tr = document.createElement("tr");
|
||||||
|
importedHeaders.forEach((_, colIndex) => {
|
||||||
|
const td = document.createElement("td");
|
||||||
|
td.contentEditable = "true";
|
||||||
|
td.textContent = row[colIndex] == null ? "" : String(row[colIndex]);
|
||||||
|
td.addEventListener("input", () => {
|
||||||
|
if (!importedData[rowIndex]) importedData[rowIndex] = [];
|
||||||
|
importedData[rowIndex][colIndex] = td.textContent.trim();
|
||||||
|
});
|
||||||
|
tr.appendChild(td);
|
||||||
|
});
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
});
|
||||||
|
table.appendChild(tbody);
|
||||||
|
container.appendChild(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
function importExcelData() {
|
||||||
const fileInput = document.getElementById("file-input");
|
const fileInput = document.getElementById("file-input");
|
||||||
if (!fileInput.files.length) return;
|
if (!fileInput.files.length) return;
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function(event) {
|
reader.onload = function(event) {
|
||||||
const workbook = XLSX.read(event.target.result, { type: "binary" });
|
try {
|
||||||
|
const workbook = XLSX.read(event.target.result, { type: "array" });
|
||||||
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||||
const jsonData = XLSX.utils.sheet_to_json(sheet, { header: 1 });
|
const jsonData = XLSX.utils.sheet_to_json(sheet, { header: 1, defval: "" });
|
||||||
|
if (jsonData.length < 2) {
|
||||||
if (jsonData.length < 2) return;
|
importedHeaders = [];
|
||||||
|
importedData = [];
|
||||||
const headers = jsonData[0];
|
renderImportTable();
|
||||||
importedData = jsonData.slice(1);
|
alert("Die Excel-Datei enthält keine Datenzeilen.");
|
||||||
|
return;
|
||||||
if (hot) {
|
}
|
||||||
hot.loadData(importedData);
|
importedHeaders = jsonData[0].map(value => value == null ? "" : String(value).trim());
|
||||||
hot.updateSettings({ colHeaders: headers });
|
importedData = jsonData.slice(1).filter(row => row.some(value => String(value ?? "").trim() !== ""));
|
||||||
} else {
|
renderImportTable();
|
||||||
const container = document.getElementById("import-table");
|
} catch (error) {
|
||||||
hot = new Handsontable(container, {
|
console.error("Excel-Import fehlgeschlagen:", error);
|
||||||
data: importedData,
|
alert("Fehler beim Einlesen der Excel-Datei: " + error.message);
|
||||||
colHeaders: headers,
|
|
||||||
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]);
|
reader.readAsArrayBuffer(fileInput.files[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendExcelData() {
|
function sendExcelData() {
|
||||||
|
if (!importedHeaders.length || !importedData.length) {
|
||||||
|
alert("Keine importierten Daten zum Senden vorhanden.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const jsonData = importedData.map(row => {
|
const jsonData = importedData.map(row => {
|
||||||
let obj = {};
|
const obj = {};
|
||||||
hot.getColHeader().forEach((header, index) => {
|
importedHeaders.forEach((header, index) => {
|
||||||
obj[header] = row[index] || "";
|
obj[header] = row[index] ?? "";
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user