Generate pivot in excel using Java
Generate pivot in excel using Java
I want to generate pivot column in excel in java. I identifed which out column has to be pivot. Please find the below java code:
In this code: m contains my fetched data from db as
m{2=, 3=, 4=, 5=, 6=, 7=, 8=, 9=First_Name=Gary,
10=Last_Name=xyz, 11=Job=IT
and after iteration str1:contains key(header)
and str2:contains value(means data)
as below:
tr1:contains key(header)
str2:contains value(means data)
Str1:First_Name
Str2:Gary
Str1:First_Name
Str2:xyz
Str1:Job
Str2:IT
......
request you to help me this..
public static void PivotTable(Map m)
System.out.println("m: "+m);
Iterator<Map.Entry<String, LinkedHashMap<String, String>>> itr = resultMap1.entrySet().iterator();
List l = new ArrayList<>();
while(itr.hasNext())
Map.Entry<String, LinkedHashMap<String, String>> entry = itr.next();
LinkedHashMap<String, String> lhmap = entry.getValue();
Iterator<Map.Entry<String, String>> itr1 =lhmap.entrySet().iterator();
while(itr1.hasNext())
Map.Entry<String, String> entry1 = itr1.next();
String str1 =entry1.getKey();
String str2 = entry1.getValue();
//count++;
System.out.println("Str1:"+str1);
System.out.println("Str2:"+str2);
l.add(str2);
rows.add(l);
System.out.println("Rows: "+rows);
CalAverage(1,0,2);
public static void CalAverage(int colIdx, int valueIdx, int... rowIdx)
Map<Object, Map<Object, Long>> myList = rows.stream().collect(
Collectors.groupingBy(r -> r.get(colIdx), Collectors
.groupingBy(r -> new PivotColumns(r, rowIdx),
Collectors.counting())));
System.out.println("Created Average Pivoting");
System.out.println(myList);
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.