java - Writing Excel using maps in groovy -


i trying write excel file using maps in groovy. in java entering values in map given below

  //writing data in map    map < string, object[] > empinfo = new treemap < string, object[] >();   empinfo.put( "1", new object[] {"emp id", "emp name", "designation" });   empinfo.put( "2", new object[] {"", "gopal", "technical manager" });   empinfo.put( "7", new object[] {"tp02", "manisha", "proof reader" });   empinfo.put( "4", new object[] {"tp03", "", "technical writer" });   empinfo.put( "5", new object[] {"tp04", "satish", "technical writer" });   empinfo.put( "6", new object[] {"tp05", "krishna", "" });    //iterate on data , write sheet   set < string > keyid = empinfo.keyset();   int rowid = 0;   (string key : keyid)   {      row = spreadsheet.createrow(rowid++);      object [] objectarr = empinfo.get(key);      int cellid = 0;      (object obj : objectarr)      {         cell cell = row.createcell(cellid++);         cell.setcellvalue((string)obj);      }   } 

how can done in groovy? new groovy , highly appreciated.

you groovy.lang.missingmethodexception because groovy not support such array declaration syntax.

groovy array declaration

groovy map declaration

here how can declare treemap

def empinfo = new treemap<string, object[]>();  empinfo["1"] = ["emp id", "emp name", "designation"] object[]; empinfo["2"] = ["", "gopal", "technical manager"] object[]; empinfo["7"] = ["tp02", "manisha", "proof reader"] object[]; empinfo["4"] = ["tp03", "", "technical writer"] object[]; empinfo["5"] = ["tp04", "satish", "technical writer"] object[]; empinfo["6"] = ["tp05", "krishna", ""] object[]; 

or

treemap empinfo = [     "1": ["emp id", "emp name", "designation"] object[],     "2": ["", "gopal", "technical manager"] object[],     "7": ["tp02", "manisha", "proof reader"] object[],     "4": ["tp03", "", "technical writer"] object[],     "5": ["tp04", "satish", "technical writer"] object[],     "6": ["tp05", "krishna", ""] object[] ]; 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -