JSP (Java Server Page) - PROBLEMA EXPORTANDO A EXCEL

 
Vista:

PROBLEMA EXPORTANDO A EXCEL

Publicado por Ansel (1 intervención) el 30/09/2019 10:35:49
Buenas,
he programado la exportación al excel de una tabla de una página web y las cabeceras las toma perfectamente (las coloca bien en el Excel) pero los datos de la tabla los coge todos seguidos, es decir, cuando termina una fila no mete un salto de línea si no que escribe todos los campos de la tabla seguidos.

Alguien puede echarle un ojo al código y decirme cómo puedo conseguir ese salto de línea?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function TableToExcel(tableid)
{
var id = $('[id$="' + tableid + '"]');
var strCopy = $('<div></div>').html(id.clone()).html();
var wb = XLSX.utils.book_new();
wb.Props = {
        Title: "Export",
        Subject: "Table",
        Author: "Ansel"
};
 
var myTableArray = [];
 
var arrayOfThisRow = [];
var tableDataHeaders = $('#cabeceras').find('th');
//Ideas ANSEL para escribir en negrita las cabeceras:
//OPCIÓN 1: intentar la instalación de la API Apache POI
//OPCIÓN 2: String.prototype.bold(#cabeceras)
//OPCIÓN 3: String.prototype.bold(tableDataHeaders)
 
if (tableDataHeaders.length > 0)
{
	tableDataHeaders.each(function() { arrayOfThisRow.push($(this).text()); });
	myTableArray.push(arrayOfThisRow);
}
 
var arrayOfThisRowDatos = [];
var tableDataDatos = $('#datos1').find('td');
if (tableDataDatos.length > 0)
{
	tableDataDatos.each(function() { arrayOfThisRowDatos.push($(this).text()); });
        //AQUI ES DONDE HAY QUE METER ALGUNA LÍNEA PARA SALTO DE LINEA
	myTableArray.push(arrayOfThisRowDatos);
}
 
wb.SheetNames.push("Export");
var ws_data = myTableArray;
var ws = XLSX.utils.aoa_to_sheet(ws_data);
wb.Sheets["Export"] = ws;
var wbout = XLSX.write(wb, {bookType:'xlsx',  type: 'binary'});
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), 'RRHH.xlsx');
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder