question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested object issue read from excel file

See original GitHub issue

Hi There, I’m having issue with nested class to read from excel file.

When i read the file, i’m getting parse error for the class PriceDetail as a list. What is the mistake am i doing? thanks for your help.

I have attached the sample excel file as well.

string excelfilepath = fileDialog.FileName;
 var excel = new ExcelMapper(excelfilepath) { TrackObjects = true };
 excel.AddMapping<Products>("Mainproduct", p => p.Mainproduct);
 excel.AddMapping<Products>("Name", p => p.Name);
 excel.AddMapping<Products>("Visible", p => p.Visible);
 excel.AddMapping<Products>("NameIcon", p => p.NameIcon);
 excel.AddMapping<Products>("SysId", p => p.SysId);
 excel.AddMapping<PriceDetail>("ID", p => p.ID);
 excel.AddMapping<PriceDetail>("FromQuantity", p => p.FromQuantity);
 excel.AddMapping<PriceDetail>("Price", p => p.Price);
 excel.AddMapping<PriceDetail>("ServiceFee", p => p.ServiceFee);
 ProductPriceList = new ObservableCollection<Products>(excel.Fetch<Products>());
 View = CollectionViewSource.GetDefaultView(ProductPriceList);

 private ObservableCollection<Products> productpricelist;

        public ObservableCollection<Products> ProductPriceList
        {
            get { return productpricelist; }
            set
            {
                productpricelist = value;
                OnPropertyChanged("ProductPriceList");
            }
        }
	public class Products
	{
		public string SysId { get; set; }
		public string Mainproduct { get; set; }
		public string Name { get; set; }
		public string Visible { get; set; }
		public string From { get; set; }
		public List<PriceDetail> Prices { get; set; } = new List<PriceDetail>();
		public string NameIcon { get; set; }
	}

	public class PriceDetail
	{
		public string ID { get; set; }
		public string FromQuantity { get; set; }
		public string Price { get; set; }
		public string ServiceFee { get; set; }
	}

Price_202302101509.xlsx

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
krangarajcommented, Feb 13, 2023

HI there, all good with small minor issue when i export the datagrid to excel just an empty col PriceDetail is created as its part of the class. I think i can delete this manually. Thanks so much for your help. Have a good day

0reactions
mgansscommented, Feb 13, 2023

Is there anything that does not work re import/export to/from Excel?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I access and process nested arrays on JSON to ...
So that i can run the code and my end and check the issue. ... a Json(with array and objects) and export the...
Read more >
Read from Multiple Excel Tables to Nested JSON
The data I'm trying to come from is an Excel document with multiple ... I have no problem working with to populate the...
Read more >
Excel to JSON: Multilayer nested arrays/objects
This JSON file will be created out of an Excel file. ... So I tried to repeat the first steps for the next...
Read more >
Importing data from a nested JSON file to Excel
Solved: Hey guys, I am desperately trying to parse the data from a nested JSON file (that has many records and lists in...
Read more >
xlsx to nested JSON · Issue #1591
Is it possible to read a xlsx file and convert it to a nested JSON? (i'm using node.js). For example, this table: Name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found