|
|
@@ -23,13 +23,27 @@ private URL: string = environments.baseUrl;
|
|
|
|
|
|
|
|
|
// 🔹 Exportar todo
|
|
|
- exportAll(tabla: string) {
|
|
|
- const url = `${this.URL}/exportar-excel?tabla=${tabla}`;
|
|
|
- this.http.get(url, { responseType: 'blob', withCredentials: true }).subscribe({
|
|
|
- next: (blob) => this.descargarArchivo(blob, `${this.nombreArchivo(tabla)}.xlsx`),
|
|
|
- error: (error) => this.manejarError(error)
|
|
|
- });
|
|
|
- }
|
|
|
+exportAll(tabla: string) {
|
|
|
+ const url = `${this.URL}/exportar-excel?tabla=${tabla}`;
|
|
|
+ this.http.get(url, { responseType: 'blob', withCredentials: true }).subscribe({
|
|
|
+ next: (blob) => {
|
|
|
+ console.log('👉 Tipo MIME recibido:', blob.type, 'Tamaño:', blob.size);
|
|
|
+
|
|
|
+ // Si no es Excel, mostrar el contenido como texto
|
|
|
+ if (blob.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
|
|
|
+ blob.text().then(texto => {
|
|
|
+ console.error('⚠️ El servidor no devolvió Excel, devolvió:', texto);
|
|
|
+ Swal.fire('Error', 'El servidor devolvió un error en lugar del Excel', 'error');
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.descargarArchivo(blob, `${this.nombreArchivo(tabla)}.xlsx`);
|
|
|
+ },
|
|
|
+ error: (error) => this.manejarError(error)
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
// Helpers
|
|
|
private nombreArchivo(tabla: string): string {
|