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

187
Vistas
# character breaks content for CSV file during download

I have code for downloading CSV file from some data.

  const rows = [ ["Html", "Css", "JavaScript"], ["C #", "C++", "Python"] ];

   let csvContent = "data:text/csv;charset=utf-8," 
          + rows.map(e => e.join(",")).join("\n"); 
 const encodedUri = encodeURI(csvContent);
 const link = document.createElement("a");
 link.setAttribute("href", encodedUri);
 link.setAttribute("download", "my_data.csv");
 document.body.appendChild(link); // Required for FF
 link.click();     

WITH # character

When I remove # character from data everything works fine

Without # character

As I understand encodeURL is not encode special symbols that is why href atribute includes # symbhol and ignore all after it.

I tryied to use Blob too but no result.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI?retiredLocale=it :

encodeURI() escapes all characters except:

A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #

Use encodeURIComponent instead, but only on the data part, not the whole url. Also note that to let Excel split the fields I have to use the semicolon, the comma doesn't work, but this could be because my locale settings.

const rows = [ ["Html", "Css", "JavaScript"], ["C #", "C++", "Python"] ];
let csvContent = rows.map(e => e.join(";")).join("\n");
const encodedUri = "data:text/csv;charset=utf-8," + encodeURIComponent(csvContent);
const link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
document.body.appendChild(link); // Required for FF
link.click();
about 4 years ago · Juan Pablo Isaza Denunciar
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