rs-excel-lite
v2.0.0
Published
Complete standalone Excel export library for browser with JSZip included
Downloads
325
Maintainers
Readme
RsExcelLite v2.0.0
Complete standalone Excel export library for browser with JSZip included.
✨ Características
- ✅ Completamente standalone – JSZip incluido (~60KB minificado)
- ✅ Soporte para múltiples hojas – Organiza tus datos en varias hojas
- ✅ Cero configuración – Solo incluye y usa
- ✅ Ajuste automático de columnas – Ancho inteligente según contenido
- ✅ Auto-filtros – Activación con una sola opción
- ✅ Protección de hojas – Con soporte para contraseña (hasheada compatible con Excel)
- ✅ Congelar paneles – Soporte para freezePane
- ✅ Estilos de cabecera automáticos – Negrita en primera fila si se define
- ✅ Soporte completo de tipos – Texto, números, fechas (Date), booleanos
- ✅ Conversión automática de objetos – Con objectsToArrays()
- ✅ Solo navegador – No requiere Node.js
- ✅ Excelente compatibilidad – Funciona en todos los navegadores modernos
📦 Instalación
NPM
npm install rs-excel-liteCDN (Recomendado)
<!-- Versión standalone completa (JSZip incluido) -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rs-excel-lite.standalone.min.js"></script>Descarga directa
rs-excel-lite.standalone.min.js
🚀 Uso en 30 segundos
<!DOCTYPE html>
<html>
<head>
<title>Exportar Excel</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/rs-excel-lite.standalone.min.js"></script>
</head>
<body>
<button onclick="exportarExcel()">Exportar a Excel</button>
<script>
function exportarExcel() {
const datos = [
['Nombre', 'Edad', 'Email', 'Fecha de registro'],
['Juan Pérez', 30, '[email protected]', new Date('2024-01-15')],
['María López', 25, '[email protected]', new Date()],
['Carlos Ruiz', 35, '[email protected]', new Date('2024-02-20')]
];
RsExcelLite.exportToExcel(datos, 'empleados.xlsx', 'Hoja1', {
autoFit: true,
headerRow: true,
headerStyle: true,
enableFilters: true,
freezePane: 'A2'
});
}
</script>
</body>
</html>📖 API Completa
Método principal
// Exportar hoja única
RsExcelLite.exportToExcel(aoa, filename?, sheetName?, options?)
// Exportar múltiples hojas
RsExcelLite.exportSheets(sheets, filename?)
// Compatibilidad retrocedida
RsExcelLite.export(aoa, filename?, sheetName?)Parámetros comunes
- aoa: Array<Array> – Datos en formato array de arrays
- filename: string – Nombre del archivo (por defecto: 'export.xlsx')
- sheetName: string – Nombre de la hoja (por defecto: 'Sheet1')
- sheets: Array<{ name: string; data: Array<Array>; options?: Object }> – Configuración de múltiples hojas
Opciones de exportación
La siguiente tabla describe las opciones disponibles para configurar el comportamiento del componente:
| Opción | Tipo | Por defecto | Descripción |
|--------|------|-------------|-------------|
| autoFit | boolean | false | Ajusta el ancho de columnas automáticamente |
| headerRow | boolean | false | Trata la primera fila como encabezado |
| headerStyle | boolean | true | Aplica estilo de negrita al encabezado |
| enableFilters | boolean | false | Habilita autofiltros |
| protectSheet | boolean | false | Protege la hoja de cálculo |
| protectPassword | string | '' | Contraseña para la protección (hasheada en Excel) |
| freezePane | string | null | Celda de referencia para congelar paneles (ej. 'A2') |
Métodos auxiliares
// Convertir índice de columna (0-based) a letra Excel
RsExcelLite.getColumnLetter(0); // 'A'
RsExcelLite.getColumnLetter(26); // 'AA'
// Calcular ancho óptimo de columnas
const widths = RsExcelLite.getColumnWidths(datos);
// Escapar texto para XML
const escaped = RsExcelLite.escapeXml('<span>texto</span>');
// Convertir objetos a arrays
const aoa = RsExcelLite.objectsToArrays(data, headers, { includeHeaders: true });
// Validar nombre de hoja
const validation = RsExcelLite.isValidSheetName('Nombre Hoja');
// Helper para crear configuración de hojas
const sheet = RsExcelLite.createSheetConfig('Hoja1', datos, { autoFit: true });📊 Ejemplos prácticos
Ejemplo 1: Múltiples hojas
const sheets = [
RsExcelLite.createSheetConfig('Clientes', [
['ID', 'Nombre', 'Email'],
[1, 'Ana', '[email protected]']
], { autoFit: true, headerRow: true }),
RsExcelLite.createSheetConfig('Ventas', [
['Producto', 'Total'],
['Laptop', 1200]
], { enableFilters: true })
];
RsExcelLite.exportSheets(sheets, 'reporte.xlsx');Ejemplo 2: Protección con contraseña
RsExcelLite.exportToExcel(datos, 'confidencial.xlsx', 'Datos', {
protectSheet: true,
protectPassword: 'miClaveSegura',
autoFit: true
});Ejemplo 3: Conversión desde objetos
const data = [
{ id: 1, name: 'Juan', active: true },
{ id: 2, name: 'María', active: false }
];
const aoa = RsExcelLite.objectsToArrays(data, [['ID', 'id'], ['Nombre', 'name'], ['Activo', 'active']]);
RsExcelLite.exportToExcel(aoa, 'usuarios.xlsx', 'Usuarios', { headerRow: true });🔧 Builds disponibles
Archivos de la Biblioteca
La siguiente tabla describe los diferentes archivos disponibles y sus características:
| Archivo | Tamaño | Descripción | Uso recomendado |
|---------|--------|-------------|-----------------|
| rs-excel-lite.standalone.min.js | ~60KB | Todo incluido (JSZip + RsExcelLite) | Navegador (CDN) |
| rs-excel-lite.min.js | ~15KB | Solo RsExcelLite | Si ya tienes JSZip |
| index.esm.js | ~15KB | Módulo ES | Webpack, Vite, Rollup |
| index.cjs.js | ~15KB | CommonJS | Node.js (con jsdom) |
🌐 Compatibilidad
- Chrome 60+
- Firefox 55+
- Safari 10.1+
- Edge 79+
- iOS Safari 10.3+
- Android Chrome 60+
📄 Licencias
RsExcelLite - MIT License
Copyright (c) 2025 Rogelio Urieta Camacho (RojeruSan)
MIT License - Ver archivo LICENSEJSZip - MIT/GPLv3 License
Copyright (c) 2009-2016 Stuart Knightley, David Duponchel, Franz Buchinger, António Afonso
Dual licensed under MIT or GPLv3 - Ver archivo LICENSE-JSZIP.md🤝 Contribuir
- Haz fork del repositorio
- Crea una rama: git checkout -b feature/nueva-funcion
- Haz commit: git commit -am 'Añade nueva función'
- Push: git push origin feature/nueva-funcion
- Abre un Pull Request
