david234

david234

Excel Sheet(xslx) Import to Postgres DB in Elixir Phoenix

I am working on one project where I have to import data from an Excel sheet to Postgres DB. In my Previous Project, I have done the CSV File import using nimble_csv | Hex. It works like a charm.

In this Project, I am dealing with Excel files.

  NimbleCSV.define(NimbleCSV.Spreadsheet, [])
  NimbleCSV.define(MyParser,  escape: "\"")

  alias NimbleCSV.RFC4180, as: CSV

  def import_shipments(conn, %{"params" => %{"import_file" => params} }) do

    params.path
      |> File.stream!(read_ahead: 100_000)
      |> MyParser.parse_stream([skip_headers: true])
      |> Stream.map(fn n ->
          case n do
            [name, barcode] ->
                IO.inspect name
                IO.inspect barcode
            _ -> IO.inspect "empty"
          end
        end)
      |> Stream.run


    render(conn, "index.html")
  end

I am getting this error.

** (NimbleCSV.ParseError) unexpected escape character " in <<101, 236, 208, 147, 208, 215, 243, 190, 72, 245, 234, 52, 141, 234, 136, 196, 67, 12, 6, 170, 162, 4, 133, 193, 197, 118, 8, 189, 129, 253, 238, 237, 225, 25, 86, 205, 162, 222, 224, 104, 37, 143, 176, 31, 18, 171, 188, 19, 216, 128, ...>>

Can anyone give me insight on this? Your help is greatly appreciated. Thanks

Most Liked

NobbZ

NobbZ

Is <<0x50, 0x4b, 0x03, 0x04, …>>, which again is the “magic number” for ZIP archives, which again is the envelop format for excel spreadsheets.

nimble_csv can’t work with those, as nimble_csv is a CSV parser, not an Excel Spreadsheet parser.

Please use a library suited to Excel Spreadsheets or open your data in Excel and export it as CSV.

mindok

mindok

Is it a CSV file you are parsing or an excel file?

Edit: It doesn’t look like CSV, in which case NimbleCSV is the wrong tool for the job…

Dusty

Dusty

Did you export the file as CSV? The library assumes that starting format, not XLSX, etc.

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement