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

blank cell at end of row isn't filled with blank_value in output #37

Open
bgoosmanviz opened this issue Sep 6, 2024 · 3 comments
Open

Comments

@bgoosmanviz
Copy link

bgoosmanviz commented Sep 6, 2024

e.g.

test.xlsx
a, b, c
1,    , 2
3, 4,

converts to

[
  ["a", "b", "c"],
  ["1", "", "2"]
  ["3", "4"]
]

The last row should have three cells, but it only has two.

@bgoosmanviz
Copy link
Author

I tried some right padding of the rows using my test spreadsheet (unfortunately cannot share this one) using this code.

defmodule BlankValueTest do
  use ExUnit.Case

  test "blank_value" do
    xlsx_file = Path.expand("test/fixtures/blank_value.xlsx")
    {:ok, package} = XlsxReader.open(xlsx_file)

    sheet = XlsxReader.sheet_names(package) |> Enum.at(0)

    rows =
      case XlsxReader.sheet(package, sheet, blank_value: "") do
        {:ok, []} ->
          []

        {:ok, [headers | rows]} ->
          num_columns = length(headers)
          rows = rows |> Enum.map(fn row ->
            if length(row) < num_columns do
              row ++ List.duplicate("", num_columns - length(row))
            else
              row
            end
          end)
          [headers | rows]
      end

    assert length(Enum.at(rows, 1)) == length(Enum.at(rows, 2))
  end
end

which worked well.

@xavier
Copy link
Owner

xavier commented Sep 14, 2024

Thanks for you report. I could not reproduce this issue by creating an file with similar content. Is there anyway you can create an test file? Do you know which software was used to create the file which causes the issue?

@bgoosmanviz
Copy link
Author

Indeed, I admit neither can I with the sample data I provided above (tbh in my rush to close this out was just wishful that simply writing out the test case would cause it to be reproduced, but thanks for trying).

Though I still can reproduce with the client spreadsheet. I think it was created with Excel. Strangely if I import it into Pages, then export again to xlsx, I can't repro. So it's something about the formatting of the original Excel sheet which I cannot reproduce. 🤦🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants