c# - Assign Custom property name in Aspose ImportCustomObjects -


i using aspose importcustomobjects method export data excel file. have following c# class:-

public class childaccountdetails {      public string name{ get; set; }      public string phone{get; set; }      ...other properties } 

i setting ispropertynameshown parameter true because want these property names imported first row, @ same time don't want name displayed instead want full name header added displayname attribute property this:-

[displayname("first name")] public string name{ get; set; } 

but still importing name instead of first name. doing correct?

using different attribute not change row title in excel. can use different approach.

  1. set ispropertynameshown false
  2. set title manually

i took original code http://www.aspose.com/docs/display/cellsnet/importing+data+to+worksheets , updated scenario.

string dst = datadir + @"importedcustomobjects.xlsx";  // instantiate new workbook workbook book = new workbook(); // clear worksheets book.worksheets.clear(); // add new sheet "data"; worksheet sheet = book.worksheets.add("data");  // define list of custom objects list<childaccountdetails> list = new list<childaccountdetails>(); // add data list of objects list.add(new childaccountdetails() { name = "saqib", phone = "123-123-1234" }); list.add(new childaccountdetails() { name = "john", phone = "111-000-1234" });  // manually add row titles sheet.cells["a1"].putvalue("first name"); sheet.cells["b1"].putvalue("phone number");  // pick few columns not import worksheet sheet.cells.importcustomobjects((system.collections.icollection)list, new string[] { "name", "phone" }, // field name must match property name in class false, // don't show field names 1, // start @ second row 0, list.count, true, "dd/mm/yyyy", false);  // save book.worksheets[0].autofitcolumns(); book.save(dst); 

i work aspose developer evangelist.


Comments