VincentBlackdot
How to import data from Excel files?
I am trying to upload information into the system from excel files
. i can’t make out most of the things ive read online
Most Liked
patrickdm
Hello Vincent,
I’ve used Xlsxir — Xlsxir v1.6.4 to parse excel files and store their rows as database records.
Here is a maybe oversimplified example of its usage, hth:
defmodule MyApp.Utils.ImportXlsx do
def import_xlsx(input_xlsx) do
with {:ok, table_id} <- Xlsxir.multi_extract(input_xlsx, 0),
:ok <-
Xlsxir.get_list(table_id)
|> List.delete_at(0) # to remove header's row
|> insert_records() do
Xlsxir.close(table_id)
else
{:error, reason} -> {:error, reason}
end
end
defp insert_records([]), do: :ok
defp insert_records([r | rs]) do
{:ok, _} =
MyApp.MyContext.create_record(%{
field1: Enum.at(r, 0),
field2: Enum.at(r, 1),
field3: Enum.at(r, 2)
})
insert_records(rs)
end
end
7
dimitarvp
Let’s start with what have you tried, what do you want to import, and an example Excel file?
1
Popular in Questions
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
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
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
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 record...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New







