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.

unable to convert system string

See original GitHub issue

HI there: im’ using your library to read the excel file as observable class, i’m getting an error message: Message=Unable to convert “(10x8)x2 H Rectangular” from [L:1]:[C:1] to System.String.

This is the code to read the excel file: thanks for your help.

string excelfilepath = fileDialog.FileName;
var excel = new ExcelMapper(excelfilepath) { TrackObjects = true };

excel.AddMapping<Product>("Mainproduct", p => p.Mainproduct) ;
excel.AddMapping<Product>("Name", p => p.Name);
excel.AddMapping<Product>("Price", p => p.Price) ;
excel.AddMapping<Product>("Visible", p => p.Visible) ;
excel.AddMapping<Product>("NameIcon", p => p.NameIcon) ;

Items = new ObservableCollection<Product>(excel.Fetch<Product>().ToList());
foreach (var st in Items)
{
    View = CollectionViewSource.GetDefaultView(st);
    View.Filter = Filter;
    View.Refresh();

}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
krangarajcommented, Jan 26, 2023

Hi There: Monring after rewrtiting the class, i can read the excel file using your library, the view collection also works like a charm, thanks so much. (i yet to figure out write back to the xml file).

var excel = new ExcelMapper(excelfilepath) { TrackObjects = true };
excel.AddMapping<Products>("Mainproduct", p => p.Mainproduct);
excel.AddMapping<Products>("Name", p => p.Name);
excel.AddMapping<Products>("Price", p => p.Price);
excel.AddMapping<Products>("Visible", p => p.Visible);
excel.AddMapping<Products>("NameIcon", p => p.NameIcon);

Items = new ObservableCollection<Products>(excel.Fetch<Products>() );

  View = CollectionViewSource.GetDefaultView(Items );
  View.Filter = Filter;
  View.Refresh();


view collection get, set:

 private ICollectionView cvs;
    public ICollectionView View
    {

        get
        {
            
            return cvs;
        }
        set
        {
            cvs = value;
            OnPropertyChanged("View");
        }
    }

class products:

  public class Products
    {

        string mainproduct;
        string name;
        string price;
        string visible;
        string nameicon;

        public string Mainproduct
        {
            get { return mainproduct; }
            set { mainproduct = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Price
        {
            get { return price; }
            set { price = value; }
        }
        public string Visible
        {
            get { return visible; }
            set { visible = value; }
        }
        public string NameIcon
        {
            get { return nameicon; }
            set { nameicon = value; }
        }
    }



0reactions
mgansscommented, Jan 26, 2023

Glad you got it to work 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell 5 : Cannot convert value To System.String
This answer generally explains under what circumstance you'll see the Cannot convert value to type System.String error when passing an argument ...
Read more >
PowerShell Script, Cannot convert System.String value to ...
The problem I'm running into is, I check $Body | Get-Member it says the TypeName is System.String. So if it's already a System.String,...
Read more >
'Object of type 'System.String' cannot be converted to ...
I got this error System.ArgumentException: 'Object of type 'System.String' cannot be converted to type 'System.String[]'.
Read more >
Failed to convert '4' to type 'System.String' - StudioX
Hello UiPath community. I started today learning RPA on UiPath Academy, and I've started building the first automation.
Read more >
'Unable to cast object of type 'System.String' ...
'Unable to cast object of type 'System.String' to type 'System.Int32'.' Hi,. I'm trying to get a value from a dictionary. The value is...
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