From 4e2cf857f828e6212370281121c44692b7ec4d9c Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 22 Jan 2026 08:53:20 +0100 Subject: [PATCH] feat: add Excel export and improve table layout in Weekly Sales - Added Export Excel button to download filtered data as .xlsx - Increased table container height to maximize visible rows - Headers remain sticky at viewport top during scroll --- components/WeeklyGrid.tsx | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/components/WeeklyGrid.tsx b/components/WeeklyGrid.tsx index 31f39ca..724a085 100644 --- a/components/WeeklyGrid.tsx +++ b/components/WeeklyGrid.tsx @@ -1,4 +1,5 @@ import React, { useMemo, useState, useEffect } from 'react'; +import * as XLSX from 'xlsx'; import { CombinedKPIs } from '../types'; import { pivotWeeklySalesData, WeeklyPivotRow } from '../services/dataProcessor'; @@ -143,6 +144,29 @@ const WeeklyGrid: React.FC = ({ data }) => { ); }; + // Export to Excel + const handleExportExcel = () => { + // Prepare data for export + const exportData = filteredRows.map(row => { + const rowData: { [key: string]: string | number } = { + SKU: row.sku, + ASIN: row.asin, + Title: row.title, + Line: row.line, + }; + weeks.forEach(week => { + rowData[`${week} Units`] = row.unitsByWeek[week] || 0; + rowData[`${week} Spend`] = row.spendByWeek[week] || 0; + }); + return rowData; + }); + + const ws = XLSX.utils.json_to_sheet(exportData); + const wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, 'Weekly Sales'); + XLSX.writeFile(wb, `Weekly_Sales_Export_${new Date().toISOString().slice(0, 10)}.xlsx`); + }; + return (
{/* Toolbar: Search & Pagination */} @@ -188,6 +212,17 @@ const WeeklyGrid: React.FC = ({ data }) => {
)} + + {/* Export Button */} +
@@ -216,8 +251,8 @@ const WeeklyGrid: React.FC = ({ data }) => {
-
-
+
+