Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +46 -51
static/script.js
CHANGED
|
@@ -272,7 +272,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 272 |
} catch(e) { showToast('Gagal export CSV', 'error'); }
|
| 273 |
}
|
| 274 |
|
| 275 |
-
|
| 276 |
try {
|
| 277 |
if (!window.XLSX) return showToast('Library Excel tidak tersedia', 'error');
|
| 278 |
|
|
@@ -283,95 +283,90 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 283 |
const wb = XLSX.utils.book_new();
|
| 284 |
const wsData = [];
|
| 285 |
|
| 286 |
-
// 1.
|
| 287 |
-
wsData.push(["HASIL KALKULASI DISTRIBUSI BINOMIAL"]);
|
| 288 |
-
wsData.push([`Parameter n : ${currentN}`, `Parameter x : ${currentX}`]);
|
| 289 |
-
wsData.push([]); // Baris kosong spacing
|
| 290 |
-
|
| 291 |
-
// 2. Ekstrak Data (Ubah paksa jadi STRING agar anti notasi E)
|
| 292 |
const rows = binomialTable.querySelectorAll('tr');
|
| 293 |
rows.forEach((row) => {
|
| 294 |
const rowArray = [];
|
| 295 |
row.querySelectorAll('th, td').forEach((cell) => {
|
| 296 |
let val = cell.innerText.trim();
|
| 297 |
-
|
| 298 |
-
rowArray.push({ v: val, t: 's' });
|
| 299 |
});
|
| 300 |
wsData.push(rowArray);
|
| 301 |
});
|
| 302 |
|
| 303 |
-
//
|
| 304 |
-
wsData.push([]);
|
| 305 |
wsData.push([{ v: "Created by; M SHEVA R", t: 's' }]);
|
| 306 |
|
| 307 |
-
// Konversi ke
|
| 308 |
const ws = XLSX.utils.aoa_to_sheet(wsData);
|
| 309 |
-
|
| 310 |
-
// 4. Proses Desain & Wrap Text
|
| 311 |
const range = XLSX.utils.decode_range(ws['!ref']);
|
| 312 |
const colWidths = [];
|
| 313 |
|
|
|
|
| 314 |
for (let C = range.s.c; C <= range.e.c; ++C) {
|
| 315 |
-
|
| 316 |
-
colWidths.push({ wch: (C < 2) ? 8 : 16 });
|
| 317 |
}
|
| 318 |
ws['!cols'] = colWidths;
|
| 319 |
|
| 320 |
-
//
|
| 321 |
for (let R = range.s.r; R <= range.e.r; ++R) {
|
| 322 |
for (let C = range.s.c; C <= range.e.c; ++C) {
|
| 323 |
const cellRef = XLSX.utils.encode_cell({ c: C, r: R });
|
| 324 |
if (!ws[cellRef]) continue;
|
| 325 |
|
| 326 |
-
// Pengaturan
|
| 327 |
ws[cellRef].s = {
|
| 328 |
-
alignment: { vertical: "center", horizontal: "center", wrapText: true }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
};
|
| 330 |
|
| 331 |
-
//
|
| 332 |
-
if (R ===
|
| 333 |
-
ws[cellRef].s.font = {
|
| 334 |
-
ws[cellRef].s.
|
| 335 |
-
ws[cellRef].s.alignment
|
|
|
|
| 336 |
}
|
| 337 |
-
|
| 338 |
-
if (R === 1) {
|
| 339 |
-
ws[cellRef].s.
|
| 340 |
-
|
| 341 |
}
|
| 342 |
|
| 343 |
-
//
|
| 344 |
-
if (R ===
|
|
|
|
| 345 |
ws[cellRef].s.font = { bold: true, color: { rgb: "FFFFFF" } };
|
| 346 |
-
ws[cellRef].s.fill = { fgColor: { rgb: "151822" } };
|
| 347 |
-
ws[cellRef].s.border = {
|
| 348 |
-
top: {style: 'medium', color: {rgb: "00F0FF"}},
|
| 349 |
-
bottom: {style: 'medium', color: {rgb: "00F0FF"}},
|
| 350 |
-
left: {style: 'thin', color: {rgb: "333333"}},
|
| 351 |
-
right: {style: 'thin', color: {rgb: "333333"}}
|
| 352 |
-
};
|
| 353 |
}
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
ws[cellRef].s.border = {
|
| 358 |
-
top: {style: 'thin', color: {rgb: "DDDDDD"}},
|
| 359 |
-
bottom: {style: 'thin', color: {rgb: "DDDDDD"}},
|
| 360 |
-
left: {style: 'thin', color: {rgb: "DDDDDD"}},
|
| 361 |
-
right: {style: 'thin', color: {rgb: "DDDDDD"}}
|
| 362 |
-
};
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
ws[cellRef].s.font = { bold: true, color: { rgb: "
|
|
|
|
|
|
|
|
|
|
| 367 |
}
|
| 368 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
}
|
| 370 |
}
|
| 371 |
|
| 372 |
-
// Merge
|
| 373 |
if (!ws['!merges']) ws['!merges'] = [];
|
| 374 |
-
ws['!merges'].push({ s: { r:
|
| 375 |
|
| 376 |
XLSX.utils.book_append_sheet(wb, ws, 'Binomial');
|
| 377 |
|
|
|
|
| 272 |
} catch(e) { showToast('Gagal export CSV', 'error'); }
|
| 273 |
}
|
| 274 |
|
| 275 |
+
function exportToXLSX() {
|
| 276 |
try {
|
| 277 |
if (!window.XLSX) return showToast('Library Excel tidak tersedia', 'error');
|
| 278 |
|
|
|
|
| 283 |
const wb = XLSX.utils.book_new();
|
| 284 |
const wsData = [];
|
| 285 |
|
| 286 |
+
// 1. Ekstrak Data Langsung dari Tabel (Tanpa Judul/Parameter Tambahan)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
const rows = binomialTable.querySelectorAll('tr');
|
| 288 |
rows.forEach((row) => {
|
| 289 |
const rowArray = [];
|
| 290 |
row.querySelectorAll('th, td').forEach((cell) => {
|
| 291 |
let val = cell.innerText.trim();
|
| 292 |
+
rowArray.push({ v: val, t: 's' }); // Format String (Anti Notasi E)
|
|
|
|
| 293 |
});
|
| 294 |
wsData.push(rowArray);
|
| 295 |
});
|
| 296 |
|
| 297 |
+
// 2. Tambahkan Spacing & Watermark di Paling Bawah
|
| 298 |
+
wsData.push([]);
|
| 299 |
wsData.push([{ v: "Created by; M SHEVA R", t: 's' }]);
|
| 300 |
|
| 301 |
+
// Konversi ke Worksheet
|
| 302 |
const ws = XLSX.utils.aoa_to_sheet(wsData);
|
|
|
|
|
|
|
| 303 |
const range = XLSX.utils.decode_range(ws['!ref']);
|
| 304 |
const colWidths = [];
|
| 305 |
|
| 306 |
+
// Atur Lebar Kolom
|
| 307 |
for (let C = range.s.c; C <= range.e.c; ++C) {
|
| 308 |
+
colWidths.push({ wch: (C < 2) ? 8 : 14 });
|
|
|
|
| 309 |
}
|
| 310 |
ws['!cols'] = colWidths;
|
| 311 |
|
| 312 |
+
// 3. Eksekusi Desain Kustom (Cell Styling)
|
| 313 |
for (let R = range.s.r; R <= range.e.r; ++R) {
|
| 314 |
for (let C = range.s.c; C <= range.e.c; ++C) {
|
| 315 |
const cellRef = XLSX.utils.encode_cell({ c: C, r: R });
|
| 316 |
if (!ws[cellRef]) continue;
|
| 317 |
|
| 318 |
+
// Pengaturan Dasar: Center & Wrap Text
|
| 319 |
ws[cellRef].s = {
|
| 320 |
+
alignment: { vertical: "center", horizontal: "center", wrapText: true },
|
| 321 |
+
border: {
|
| 322 |
+
top: {style: 'thin', color: {rgb: "CCCCCC"}},
|
| 323 |
+
bottom: {style: 'thin', color: {rgb: "CCCCCC"}},
|
| 324 |
+
left: {style: 'thin', color: {rgb: "CCCCCC"}},
|
| 325 |
+
right: {style: 'thin', color: {rgb: "CCCCCC"}}
|
| 326 |
+
}
|
| 327 |
};
|
| 328 |
|
| 329 |
+
// Pengecualian Styling untuk Baris Watermark
|
| 330 |
+
if (R === range.e.r) {
|
| 331 |
+
ws[cellRef].s.font = { italic: true, color: { rgb: "888888" }, bold: true };
|
| 332 |
+
ws[cellRef].s.border = {}; // Tanpa border
|
| 333 |
+
ws[cellRef].s.alignment = { horizontal: "left" };
|
| 334 |
+
continue;
|
| 335 |
}
|
| 336 |
+
// Pengecualian Styling untuk Spacing (Baris Kosong)
|
| 337 |
+
if (R === range.e.r - 1) {
|
| 338 |
+
ws[cellRef].s.border = {};
|
| 339 |
+
continue;
|
| 340 |
}
|
| 341 |
|
| 342 |
+
// STYLING: Header (Baris 0)
|
| 343 |
+
if (R === 0) {
|
| 344 |
+
ws[cellRef].s.fill = { fgColor: { rgb: "323232" } };
|
| 345 |
ws[cellRef].s.font = { bold: true, color: { rgb: "FFFFFF" } };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
}
|
| 347 |
+
// STYLING: Kolom n & Kolom x
|
| 348 |
+
else if (C === 0 || C === 1) {
|
| 349 |
+
ws[cellRef].s.fill = { fgColor: { rgb: "323232" } };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
+
if (C === 0) {
|
| 352 |
+
// Teks Kolom n
|
| 353 |
+
ws[cellRef].s.font = { bold: true, color: { rgb: "FFFFFF" } };
|
| 354 |
+
} else if (C === 1) {
|
| 355 |
+
// Teks Kolom x (Warna Accent Biru / Cyan)
|
| 356 |
+
ws[cellRef].s.font = { bold: true, color: { rgb: "00F0FF" } };
|
| 357 |
}
|
| 358 |
}
|
| 359 |
+
// STYLING: Hasil Tabel Utama
|
| 360 |
+
else {
|
| 361 |
+
ws[cellRef].s.fill = { fgColor: { rgb: "E9E9E9" } };
|
| 362 |
+
ws[cellRef].s.font = { color: { rgb: "212121" }, bold: true };
|
| 363 |
+
}
|
| 364 |
}
|
| 365 |
}
|
| 366 |
|
| 367 |
+
// 4. Merge Cells untuk Watermark (Mencegah teks kepotong)
|
| 368 |
if (!ws['!merges']) ws['!merges'] = [];
|
| 369 |
+
ws['!merges'].push({ s: { r: range.e.r, c: 0 }, e: { r: range.e.r, c: 4 } });
|
| 370 |
|
| 371 |
XLSX.utils.book_append_sheet(wb, ws, 'Binomial');
|
| 372 |
|