Avatar of Michael Lam
Michael Lam
 asked on

how to represent a complex object using Excel

i want to use Excel to load data so i can do bulk insert.  if i have the following class:

class Person
{
List<Address> addresses;
}

what is the best way to represent this data in an Excel file?  currently, we are saving it as a flat structure, i.e. address1, address2, etc.  but this is not flexible.  can someone offer some ideas on how to represent the data in a more flexible way?  thanks.
Microsoft ExcelC#

Avatar of undefined
Last Comment
jmcmunn

8/22/2022 - Mon
jmcmunn

Where are you loading the data?  Is someone manually typing it into excel?

Assuming you are restricted to using Excel...I would make it so there are two columns (PersonName, Address) and that way each "Person" will have one row for each address.  (multiple rows for multiple addresses obviously)

However, it is not clear to me if you are trying to get the data INTO excel, or OUT OF excel?  There are a lot better ways to store the data if you're looking for storage of data that you will be reading and writing to (a database such as SQL for instance). However, a simple spreadsheet as described above would be a suitable place to export some data to I suppose.
Michael Lam

ASKER
both, we use the Excel file so our user can input it, then we will map data from Excel file to a list of objects before saving to DB.  if you are using one row for each address, then the first row will be full, but the subsequent rows will be empty except for the address column.  how are you going to be able to tell when the first set of data end and the second person's data begins?  by person ID or name?  if the user wants to add an additional address to the Person object, he will have to insert an empty row between the first set of data and the beginning of the second set of data?

something like this:

Name1 | ID1 | Address1A
             |       | Address1B
              |       | Address1C
Name2 | ID2| Address2A
ASKER CERTIFIED SOLUTION
jmcmunn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy