38 lines
1.9 KiB
JavaScript
38 lines
1.9 KiB
JavaScript
const xlsx = require('xlsx');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
// Create a realistic sample Excel file with multiple sheets
|
|
const wb = xlsx.utils.book_new();
|
|
|
|
// Sheet 1: Employee Directory
|
|
const employeesData = [
|
|
['Employee ID', 'Full Name', 'Department', 'Job Title', 'Hire Date', 'Salary (USD)', 'Status'],
|
|
['EMP-001', 'Alice Johnson', 'Engineering', 'Lead Architect', '2021-03-15', 145000, 'Active'],
|
|
['EMP-002', 'Bob Smith', 'Marketing', 'Content Strategist', '2022-06-01', 82000, 'Active'],
|
|
['EMP-003', 'Carlos Ruiz', 'Engineering', 'Senior Backend Dev', '2020-11-20', 125000, 'Active'],
|
|
['EMP-004', 'Diana Prince', 'Finance', 'Financial Analyst', '2023-01-10', 95000, 'Active'],
|
|
['EMP-005', 'Evan Wright', 'Human Resources', 'HR Manager', '2019-08-05', 88000, 'Active'],
|
|
['EMP-006', 'Fiona Gallagher', 'Design', 'UI/UX Designer', '2022-09-14', 92000, 'Active'],
|
|
['EMP-007', 'George Clark', 'Operations', 'Logistics Coordinator', '2021-12-01', 74000, 'On Leave'],
|
|
['EMP-008', 'Hannah Lee', 'Engineering', 'Frontend Engineer', '2023-04-18', 105000, 'Active']
|
|
];
|
|
const ws1 = xlsx.utils.aoa_to_sheet(employeesData);
|
|
xlsx.utils.book_append_sheet(wb, ws1, 'Employees');
|
|
|
|
// Sheet 2: Quarterly Sales
|
|
const salesData = [
|
|
['Region', 'Representative', 'Q1 Target', 'Q1 Actual', 'Q2 Target', 'Q2 Actual', 'Total Actual'],
|
|
['North America', 'Sarah Connor', 100000, 115000, 120000, 128000, 243000],
|
|
['Europe', 'Jean-Luc Picard', 90000, 87000, 95000, 102000, 189000],
|
|
['Asia-Pacific', 'Akira Sato', 110000, 125000, 130000, 142000, 267000],
|
|
['Latin America', 'Elena Gomez', 75000, 78000, 80000, 85000, 163000]
|
|
];
|
|
const ws2 = xlsx.utils.aoa_to_sheet(salesData);
|
|
xlsx.utils.book_append_sheet(wb, ws2, 'Quarterly Sales');
|
|
|
|
const testFilePath = path.join(__dirname, 'sample_company_data.xlsx');
|
|
xlsx.writeFile(wb, testFilePath);
|
|
console.log('Sample test Excel file created at:', testFilePath);
|
|
|