Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
Add manually entered data into javascript

A simple question here: I have the following subset of my data in Javascript. My application works, but I need a simple way to bring in an expanded version of that same data, but taken from an Excel file rather than manually entered into this script. What is the simplest and easiest solution to do so with few steps in between?

    const countryData={
        australia: {
        countryName: "France",
        fsnNarrative: "aus fsn lorem ipsum dolor sit amet",
        otherNarrative: "lorem ipsum dolor",
        marketLink: "http://www.google.com",
        center: [65, 34],
        zoom:4
    },
    france: {
        countryName: "France",
        fsnNarrative: "bgd fsn lorem ipsum dolor sit amet",
        otherNarrative: "lorem ipsum dolor",
        marketLink: "http://www.youtube.com",
        center: [90, 24],
        zoom: 5
    }
}

I tried to convert it in from a JSON, but had trouble also a) converting excel to JSON and b) assigning external local JSON to a constant (trying to follow this guidance but am not clear. I also use R, in case anyone has a solution with that.

Optimally, I'd be able to just link from the Javascript to an external JSON or some other file type, like this. const data = (path to some URL)

Working with just Javascript, HTML and CSS for now.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I use the SheetJS library to process and export XLS data. Please check snippet below

    var json_data;
(async() => {
  // fetch xls file
  const url = "https://www.lucasroquilly.com/stack_overflow_samples/workbook.xls";
  // store data
  const data = await (await fetch(url)).arrayBuffer();
  // convert to workbook
  const workbook = XLSX.read(data);
  //get first sheet
  const worksheet = workbook.Sheets[workbook.SheetNames[0]]
  //convert sheet to json
  json_data = XLSX.utils.sheet_to_json(worksheet);
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.5/xlsx.min.js"></script>
<button onclick="console.log(json_data)">Log json</button>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda