Import Anonymous Types

Last post 02-24-2009, 12:29 AM by Amjad Sahi. 17 replies.
Page 1 of 2 (18 items)   1 2 Next >
Sort Posts: Previous Next
  •  01-21-2008, 6:49 PM 109861

    Import Anonymous Types

    Hi,

    Will you guys be implementing a Worksheet.Cells.Import method that takes anonymous types as its source?

    -Michael

    Michael Aparicio
     
  •  01-21-2008, 7:33 PM 109864 in reply to 109861

    Re: Import Anonymous Types

    You can use ImportArray method or ImportObjectArray and ImportTwoDimensionArray method.
    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
  •  01-21-2008, 9:25 PM 109880 in reply to 109864

    Re: Import Anonymous Types

    Thank you Laurence. I'll play around with these import methods and see if I get the results I'm looking for.

    Thanks again,
    Michael

    Michael Aparicio
     
  •  01-22-2008, 10:55 AM 109960 in reply to 109880

    Re: Import Anonymous Types

    ClassT {
     public Int32 ID { get; set; }
     public String Name { get; set; }
    }


    If I have an array of type ClassT and I want to import it to a worksheet, what would be the best way for me to do this?

    I noticed that if I just use ImportObjectArray, I only get the object type to be displayed in the worksheet. Do I have to override the ToString method in order for the actual data within the data members to be displayed?

    Thank you for your help,
    Michael

    Michael Aparicio
     
  •  01-22-2008, 6:54 PM 110016 in reply to 109960

    Re: Import Anonymous Types

    Hi Michael,

    Import method won't work on your custom defined classes. You can retrieve data from your classes to a two-dimension array and use ImportTwoDimensionArray method.


    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
  •  02-04-2009, 12:35 PM 163468 in reply to 110016

    Re: Import Anonymous Types or Custom Object

    Hi Laurence, long time fan of Aspose!

    I have a similar problem and I've been away for a while and not sure if you have built anything that can take a custom object and use the smart marker approach to importing data.  I'm sure a lot of developers would need this now with LINQ.

    Here's what I want to do.... similar to the class above, I want to take a IList<T> and inport it into the spreadsheet using the smart marker approach with reflection against the object type.

    For example:

    class Person
    {
       public string Name { get; set; }
       public int Age { get; set; }
    }

    .
    .
    .
    IEnumberable<Person> list  = new List<Person>() { "Marty", 43 };  //

    w.Cells.ImportObjectArray (list);

    I want to use &=Person.Name and &=Person.Age in the template to place where the data goes.

    How can I achieve this?   Any ideas ? 

    thanks
    Marty



     
     
  •  02-04-2009, 7:56 PM 163517 in reply to 163468

    Re: Import Anonymous Types or Custom Object

    Hi Marty,

    This feature is not supported yet, but we have put it on our task list. Hopefully we will make it in one week.


    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
  •  02-04-2009, 8:00 PM 163518 in reply to 163468

    Re: Import Anonymous Types or Custom Object

    By the way, do you need the ImportObjectArray method first or smart marker feature first? We will set the priority according to your need. I think we can provide a new version for you before the end of next week.


    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
  •  02-04-2009, 9:10 PM 163531 in reply to 163518

    Re: Import Anonymous Types or Custom Object

    Hi Laurence, thanks for the quick reply.

    Let me think a little more about how this would work.  Or maybe you can think about the best way to implement it knowing the internals of how importing and smart markers work.

    One suggestion might be to come up with a new method,

    w.Cells.ImportCollection (IEnumerable collection, ....),

    This way you can now say that you support collection types, i.e. collections that support IEnumerable, and IEnumerator.

    And the real need is to be able to use the smart marker technique approach in the cells (or maybe this method only applies to row, i.e. w.Rows.ImportCollection (..). 

    And then process &=Type.Property for each column in the row, ignore and delete markers that are not used for that Type only (so you can use another Inport on the same row for a different collection).

    something like

    IEnumerable<Person>() listPeople = new IList<Person>();
    listPeople.Add (new Person = { "Marty", 43 });

    w.Cells.ImportCollection ("A1", listPeople, ImportType.UseSmartMarkers);

    // Something like that would be cool!  Feel free to send me a personal email.

    Marty

    p.s you would have to make sure it does not break your current smart marker .Process() approach - maybe you might need to come up with another escape sequence.... &+ or something.





     
  •  02-04-2009, 9:20 PM 163535 in reply to 163531

    Re: Import Anonymous Types or Custom Object

    Hi Marty,

    I understand your need now. We will support it in smart marker and won't break current smart marker processing.


    Laurence Chen
    Chief Architect
    Aspose Nanjing Team
    About Us
    Contact Us
     
  •  02-05-2009, 12:59 PM 163724 in reply to 163535

    Re: Import Anonymous Types or Custom Object

    Hi Laurence, my client is excited to use this new feature.  Let me know when you have a version to test - I'll try it out... I assume my client will need to renew the license since I think the current one expires on
    <SubscriptionExpiry>20081126</SubscriptionExpiry>.

    They renewed the Aspose.Excel for .NET 1.1 - that is in the works.

    Looking forward to what you will have.

    thanks again
    Marty
     
  •  02-10-2009, 1:59 AM 164309 in reply to 163724

    Re: Import Anonymous Types or Custom Object

    Attachment: Present (inaccessible)
    Hi Marty,

    Please try the attached version. We have supported custom objects in SmartMarker. See the following codes:

    class Person
          {

                public String Name;
                public int Age;
                internal Person(string name,int age)
                {
                      this.Name = name;
                      this.Age = age;
                }

          }
    WorkbookDesigner designer = new WorkbookDesigner();
                      Cells cells = designer.Workbook.Worksheets[0].Cells;
                      cells["A1"].PutValue("&=Person.Name");
                      cells["B1"].PutValue("&=Person.Age");
                      ArrayList list = new ArrayList();
                      list.Add(new Person("Simon", 30));
                      list.Add(new Person("Johnson", 33));
                      designer.SetDataSource("Person", list);
                      designer.Process(false);

                      designer.Save(@"F:\FileTemp\dest.xls");


    And we add Cells.ImportCustomObjects(
                      ICollection list, string[] fieldNames,
                      bool isFieldNameShown,
                      int firstRow, int firstColumn,
                      int rowNumber,
                      bool insertRows,
                      string dateFormatString,
                      bool convertStringToNumber) method to import custom objects.



    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  02-10-2009, 9:19 AM 164409 in reply to 164309

    Re: Import Anonymous Types or Custom Object

    Thanks!  I'll try it in demo mode.  I had a license expiration exception when I tried to use this version with my client's current license.  I'll have to ask them to get the paperwork going for the upgrade.
    thanks - I'll try to get back to you shortly - thanks for doing this!
    Marty
     
  •  02-10-2009, 10:13 AM 164425 in reply to 164309

    Re: Import Anonymous Types or Custom Object


    Hi, here's what I tried but I got empty results in the worksheet (smartmarkers were removed on process).

    My guess is that when you are using reflection, maybe you are not getting the public properties ?

    Note: report object below is a class that creates the designer workbook and opens a template.  Everything else works okay.  So, maybe you can take a look at my example and see if you can copy and paste the code where I create a list and call setdatasource, process....

    thanks
    Marty

    public class MyProduct
    {
       public string Name { get; set; }
      public int Age { get;  set; }
    }

    private void TestImportCustomObject(
    ExcelOutputReport report)
            {
                Aspose.Cells.Worksheet w = report.Workbook.Worksheets["Custom"];

                w.Cells["A1"].PutValue("Test");
                w.Cells["A2"].PutValue("&=MyProduct.Name");

                List<MyProduct> plist = new List<MyProduct>();
                plist.Add (new MyProduct { age = 43, Name = "Marty" });
                plist.Add(new MyProduct { age = 41, Name = "Ellen" });

                report.WorkbookDesigner.SetDataSource("MyProduct", plist);
                report.WorkbookDesigner.Process(false);
            }

     
  •  02-13-2009, 1:29 AM 165051 in reply to 164425

    Re: Import Anonymous Types or Custom Object

    Attachment: Present (inaccessible)
    Hi,

    Please try the attached version (4.6.0.12). We have supported to import the properties of a Custom object in processing the smart markers. And, currently, we only support importing the properties of a Custom object as we do not support the fields of the Custom object, we may look into it though.

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
Page 1 of 2 (18 items)   1 2 Next >
View as RSS news feed in XML