E
E
Egor Rublev2016-03-09 19:37:55
JavaScript
Egor Rublev, 2016-03-09 19:37:55

How to parse from xlsx to js objects?

Hello friends, there is a table in the form of XLSX, 6 columns and many rows.
Model, year, engine, link, cost of repair, cost of parts
Need to be brought into the form:

models: [{
        model: 'модель',
        years: [{
            year: 'год',
            engines: [
                { engine: 'движок', image: 'ссылка', work: 'стоимость работ', parts: 'стоимость деталей' },
            ]
        }, {
        model: 'модель',
        years: [{
            year: 'год',
            engines: [
                { engine: 'движок', image: 'ссылка', work: 'стоимость работ', parts: 'стоимость деталей' },
            ]
        }]
    }]

What is the best way to parse and bring to the desired form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2016-03-09
@FaloSun

In CSV and process line by line. You can just do it in Notepad++))
UPD#1:
1. Open the CSV file in Sublime Text
2. Press Ctrl+H
3. Paste this regular expression into the top field:

([^;]*)?;([^;]*)?;([^;]*)?;([^;]*)?;([^;]*)?;([^;\r\n]*)?\n*

4. Insert this regular expression into the bottom field:
\{\n\tmodel: '$1',\n\tyears: \[\{\n\t\tyear: '$2',\n\t\tengines: \[\n\t\t\t\{ engine: '$3', image: '$4', work: '$5', parts: '$6' \}\n\t\t\]\n\},\n

5. We set the options as in the screenshot
6. Click the "Replace All" button
7. We get the result and rejoice))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question