Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to export multiple values in data table to excel separated by a comma (using HTML, JQuery, JSON)

As the title states, I am trying to export a data table created in a web app to excel carrying the format. The main issue is that multiple values selected from a datalist create a string in excel (ex. 10, 11, 12 in app converts to 101112 in excel).

The code below was used before, and separated the values in excel, but it would not allow the html multiple datalist to display correctly. (ex. Instead of display the full list it would only display 10,11,12 etc., in the drop down after selecting 10, instead of a name and value originally in the list.)

 //For Selecting Multiple Events
    document.addEventListener("DOMContentLoaded", function () {
        const separator = ',';
        for (const input of document.getElementsByTagName("input")) {
            if (!input.multiple) {
                continue;
            }
            if (input.list instanceof HTMLDataListElement) {
                const optionsValues = Array.from(input.list.options).map(opt => opt.value);
                let valueCount = input.value.split(separator).length;
                input.addEventListener("input", () => {
                    const currentValueCount = input.value.split(separator).length;
                    if (valueCount !== currentValueCount) {
                        const lsIndex = input.value.lastIndexOf(separator);
                        const str = lsIndex !== -1 ? input.value.substr(0, lsIndex) + separator : "";
                        filldatalist(input, optionsValues, str);
                        valueCount = currentValueCount;
                    }
                });
            }
        } 
        function filldatalist(input, optionValues, optionPrefix) {
            const list = input.list;
            if (list && optionValues.length > 0) {
                list.innerHTML = "";
                const usedOptions = optionPrefix.split(separator).map(value => value.trim());
                for (const optionsValue of optionValues) {
                    if (usedOptions.indexOf(optionsValue) < 0) {
                        const option = document.createElement("option");
                        option.value = optionPrefix + optionsValue;
                        list.append(option);
                    }
                }
            }
        }
    });

This is how the App should process the data during selection. Desired selection within App

This is how the App should display the data. Desired display in App datatable

This is how the data displays in Excel Values not separated by commas

This is the result using the code above. Undesired selection within the App

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda