Skip to content

Render LIST, ARRAY, STRUCT, and MAP columns as JSON strings instead of #VALUE!#32

Merged
RusselWebber merged 1 commit into
RusselWebber:mainfrom
pep-sanwer:handle-collection-columns-to-string
Apr 23, 2026
Merged

Render LIST, ARRAY, STRUCT, and MAP columns as JSON strings instead of #VALUE!#32
RusselWebber merged 1 commit into
RusselWebber:mainfrom
pep-sanwer:handle-collection-columns-to-string

Conversation

@pep-sanwer
Copy link
Copy Markdown
Contributor

DuckDB.NET returns .NET collection objects (List<T>, Dictionary<K,V>) for complex column types
Excel-DNA does not marshal these, producing #VALUE! errors

This change JSON-serializes collection-typed columns so they display as readable strings in Excel

Given

FROM (
    VALUES (
        ['apple', 'banana', 'cherry']
        , { 'id': 101, 'status': 'active', 'score': 9.5 }
        , MAP(['color', 'shape', 'material'], ['red', 'circle', 'wood'])
        , '{"meta": {"tags": ["sql", "duckdb"], "version": 1.2}}'::JSON
    )
) AS test (example_list, example_struct, example_map, example_json)
;

Before

example_list example_struct example_map example_json
#VALUE! #VALUE! #VALUE! {"meta": {"tags": ["sql", "duckdb"], "version": 1.2}}

After

example_list example_struct example_map example_json
["apple","banana","cherry"] {"id":101,"status":"active","score":9.5} {"color":"red","shape":"circle","material":"wood"} {"meta": {"tags": ["sql", "duckdb"], "version": 1.2}}

Changes

  • DuckDbHelper.cs — Added jsonSerializeField flag for IList/IDictionary column types, serialized via JsonSerializer.Serialize(); null collections guard via IsDBNull#N/A
  • UnitTestDuckDbQueries.cs — Added tests for LIST, STRUCT, MAP, and null collections (LIST)

Assisted-by: Claude:claude-opus-4-6 [dotnet-test]

@pep-sanwer
Copy link
Copy Markdown
Contributor Author

Hello!

My apologies for this drive by and thank you for the incredible tool and work here!
Please feel free to completely ignore this PR if it isn't suitable

@RusselWebber
Copy link
Copy Markdown
Owner

Hi, thanks very much for the PR! I like the idea, but was wondering if maybe it would be better to return array constants? https://support.microsoft.com/en-gb/office/use-array-constants-in-array-formulas-477443ea-5e71-4242-877d-fcae47454eb8
What do you think?

@pep-sanwer
Copy link
Copy Markdown
Contributor Author

Hello - appreciate the feedback!
That would be interesting functionality, specifically for LIST / ARRAY types, but I'm not sure what native Excel Spill functionality would mean for STRUCT or MAP.

My thoughts were:
I was also hoping to preserve duckdb semantics here (i.e. number of rows returned matches duckdb output).
For example:

image [Fig 1]


is equivalent to:
image


this also allows roundtrip back into duckdb for user controlled "spill" like:
*last two rows in Fig 1. above is xlRange below
image

or
image

or
image

@pep-sanwer pep-sanwer changed the title Render LIST, STRUCT, and MAP columns as JSON strings instead of #VALUE! Render LIST, ARRAY, STRUCT, and MAP columns as JSON strings instead of #VALUE! Apr 17, 2026
@RusselWebber RusselWebber self-assigned this Apr 23, 2026
@RusselWebber RusselWebber self-requested a review April 23, 2026 07:34
Copy link
Copy Markdown
Owner

@RusselWebber RusselWebber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Thank you for the PR!

@RusselWebber RusselWebber merged commit 2873970 into RusselWebber:main Apr 23, 2026
2 checks passed
@pep-sanwer pep-sanwer deleted the handle-collection-columns-to-string branch April 23, 2026 16:45
@pep-sanwer
Copy link
Copy Markdown
Contributor Author

Cheers! Thank you for all your work again!

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

Successfully merging this pull request may close these issues.

2 participants