Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cell with text formated in HTML #2742

Open
Seykotron opened this issue Jul 13, 2022 · 1 comment
Open

Cell with text formated in HTML #2742

Seykotron opened this issue Jul 13, 2022 · 1 comment

Comments

@Seykotron
Copy link

We are trying to export an excel that comes from an array of objects, in example:

{ "success": true, "hojas": { "Imputaciones": { "columnas": [ [ "Id", "Email", "Nombre Completo", "Puesto", "Equipos", "Áreas de Práctica", "Socio Referencia", "Manager Referencia", "Fecha Grabación", "Fecha Imputacion", "Centro de Facturación", "Cliente", "Exp. Referencia Antigua", "Exp. Referencia Actual", "Expediente", "Asunto", "Descripcion", "Tiempo", "Horas", "Minutos", "Estado" ] ], "columnas_con_fechas": [ [ "Fecha Grabación", "Fecha Imputacion" ] ], "columnas_con_html": [ [ "Descripcion" ] ], "valores": [ [ 292195, "xxxxx@xxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", null, null, "2022-07-13T07:17:40.173", "2022-07-13", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", null, "<p>Reporte trimestral de los casos en FinRep.&nbsp;</p>\r\n\r\n<p>FPCE. Revisi&oacute;n de los m&oacute;dulos mandatory con sus responsables. Redacci&oacute;n de las respuestas y recopilaci&oacute;n de evidencias.&nbsp;</p>", 7, 7, 0, "Pendiente de revisar" ], ], "total": 8, "title": "Imputaciones" } }, "sheet": "Imputaciones", "title": "imputaciones_todas", "filas_por_pagina": 1000, "pagina": 1 }

The thing is that in excel the colum "Descripcion" its not showing as html but showing the html tags, etc.

I tried to fill the "h" property of the cell but it does not change the output.

I've search a lot and didnt see any issue like this,

can you help me please?

@ljluestc
Copy link

const XLSX = require('xlsx');
const htmlToText = require('html-to-text'); // This library helps to convert HTML to plain text

// Sample data
const data = {
    "success": true,
    "hojas": {
        "Imputaciones": {
            "columnas": [
                ["Id", "Email", "Nombre Completo", "Puesto", "Equipos", "Áreas de Práctica", "Socio Referencia", "Manager Referencia", "Fecha Grabación", "Fecha Imputacion", "Centro de Facturación", "Cliente", "Exp. Referencia Antigua", "Exp. Referencia Actual", "Expediente", "Asunto", "Descripcion", "Tiempo", "Horas", "Minutos", "Estado"]
            ],
            "columnas_con_fechas": [
                ["Fecha Grabación", "Fecha Imputacion"]
            ],
            "columnas_con_html": [
                ["Descripcion"]
            ],
            "valores": [
                [292195, "xxxxx@xxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", null, null, "2022-07-13T07:17:40.173", "2022-07-13", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", "xxxxxxx", null, "<p>Reporte trimestral de los casos en FinRep.&nbsp;</p>\r\n\r\n<p>FPCE. Revisi&oacute;n de los m&oacute;dulos mandatory con sus responsables. Redacci&oacute;n de las respuestas y recopilaci&oacute;n de evidencias.&nbsp;</p>", 7, 7, 0, "Pendiente de revisar"]
            ],
            "total": 8,
            "title": "Imputaciones"
        }
    },
    "sheet": "Imputaciones",
    "title": "imputaciones_todas",
    "filas_por_pagina": 1000,
    "pagina": 1
};

// Extract data for the worksheet
const sheetData = [data.hojas.Imputaciones.columnas[0]];
data.hojas.Imputaciones.valores.forEach(row => {
    // Convert HTML content to plain text
    row[16] = htmlToText.convert(row[16]);
    sheetData.push(row);
});

// Create a new workbook and a worksheet
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet(sheetData);

// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, data.sheet);

// Write the workbook to a file
XLSX.writeFile(wb, `${data.title}.xlsx`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants