mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-24 23:09:23 +08:00
Add drag-and-drop for xls[x|m]-format (#2577)
Dragging an xlsx-file onto a livebook should load the code-snipplet. In order for the DataTable to load the code assumes that the first row contains column-labels.
This commit is contained in:
parent
d4752ebd52
commit
c458a06a05
1 changed files with 25 additions and 0 deletions
|
@ -65,6 +65,11 @@ defmodule Livebook.Runtime.Definitions do
|
||||||
dependency: %{dep: {:stb_image, "~> 0.6.2"}, config: []}
|
dependency: %{dep: {:stb_image, "~> 0.6.2"}, config: []}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xlsx_reader = %{
|
||||||
|
name: "xlsx_reader",
|
||||||
|
dependency: %{dep: {:xlsx_reader, "~> 0.8.3"}, config: []}
|
||||||
|
}
|
||||||
|
|
||||||
windows? = match?({:win32, _}, :os.type())
|
windows? = match?({:win32, _}, :os.type())
|
||||||
nx_backend_package = if(windows?, do: torchx, else: exla)
|
nx_backend_package = if(windows?, do: torchx, else: exla)
|
||||||
|
|
||||||
|
@ -411,6 +416,26 @@ defmodule Livebook.Runtime.Definitions do
|
||||||
Exqlite.query!(conn, "PRAGMA table_list", [])\
|
Exqlite.query!(conn, "PRAGMA table_list", [])\
|
||||||
""",
|
""",
|
||||||
packages: [kino_db, exqlite]
|
packages: [kino_db, exqlite]
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
type: :file_action,
|
||||||
|
file_types: [".xlsx",".xlsm"],
|
||||||
|
description: "Read sheets",
|
||||||
|
source: """
|
||||||
|
xlsx_file = Kino.FS.file_path("{{NAME}}")
|
||||||
|
{:ok, package} = XlsxReader.open(xlsx_file)
|
||||||
|
|
||||||
|
tabs =
|
||||||
|
for sheet <- XlsxReader.sheet_names(package) do
|
||||||
|
# Assume the first row contains column names
|
||||||
|
{:ok, [header | rows]} = XlsxReader.sheet(package, sheet)
|
||||||
|
maps = Enum.map(rows, fn row -> header |> Enum.zip(row) |> Map.new() end)
|
||||||
|
{sheet, Kino.DataTable.new(maps)}
|
||||||
|
end
|
||||||
|
|
||||||
|
Kino.Layout.tabs(tabs)
|
||||||
|
""",
|
||||||
|
packages: [kino, xlsx_reader]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue