Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
# 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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!