Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last row missed issue(#22) and infinite loop problem #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/exoffice/parser/excel_2003.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Exoffice.Parser.Excel2003 do

"""
def count_rows(pid) do
Xlsxir.get_multi_info(pid, :rows)
:ets.info(pid, :size)
end

@doc """
Expand Down
16 changes: 12 additions & 4 deletions lib/exoffice/parser/excel_2003/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ defmodule Exoffice.Parser.Excel2003.Loader do
loader <- get_stream(ole),
{stream, _pos, excel} <- parse(loader, 0, %Excel2003{data_size: byte_size(loader.data)}),
pids = parse_sheets(loader, excel, sheet) do
Enum.map(pids, fn {status, pid, _} -> {status, pid} end)
Enum.map(pids, fn {status, pid, _} ->
sort_ets_table_by_row(pid)
{status, pid}
end)
else
{:error, reason} -> {:error, reason}
end
Expand Down Expand Up @@ -193,7 +196,7 @@ defmodule Exoffice.Parser.Excel2003.Loader do
# add cell
case :ets.match(pid, {row, :"$1"}) do
[[cells]] ->
:ets.insert(pid, {row, cells ++ [[column_string <> to_string(row), value]]})
:ets.insert(pid, {row, [[column_string <> to_string(row), value]] ++ cells})

_ ->
:ets.insert(pid, {row, [[column_string <> to_string(row), value]]})
Expand All @@ -218,7 +221,7 @@ defmodule Exoffice.Parser.Excel2003.Loader do
# add cell
case :ets.match(pid, {row, :"$1"}) do
[[cells]] ->
:ets.insert(pid, {row, cells ++ [[column_string <> to_string(row), value]]})
:ets.insert(pid, {row, [[column_string <> to_string(row), value]] ++ cells})

_ ->
:ets.insert(pid, {row, [[column_string <> to_string(row), value]]})
Expand All @@ -241,7 +244,7 @@ defmodule Exoffice.Parser.Excel2003.Loader do
# add cell
case :ets.match(pid, {row, :"$1"}) do
[[cells]] ->
:ets.insert(pid, {row, cells ++ [[column_string <> to_string(row), nil]]})
:ets.insert(pid, {row, [[column_string <> to_string(row), nil]] ++ cells})

_ ->
:ets.insert(pid, {row, [[column_string <> to_string(row), nil]]})
Expand Down Expand Up @@ -733,4 +736,9 @@ defmodule Exoffice.Parser.Excel2003.Loader do
new_pos = pos + length + 4
apply(__MODULE__, fun, if(pid, do: [loader, new_pos, excel, pid], else: [loader, new_pos, excel]))
end

def sort_ets_table_by_row(tid) do
rows = :ets.tab2list(tid) |> Enum.map(fn {row, cells} -> {row, Enum.sort(cells)} end)
:ets.insert(tid, rows)
end
end