Hallo, I have a map, such that I have for-each for rows and columns. I want to have one sum per column. That is for each game I want to have one sum over the results of all players (D6). And the division in D7 should also be one for each column. How can I do this?
Thanks and best Regards, Jana
package net.sf.jxls.sample; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.jxls.exception.ParsePropertyException; import net.sf.jxls.transformer.XLSTransformer; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; public class MyDynamicColumnsSample { private static String templateFileName = "templates/my-dynamicolumns.xls"; private static String destFileName = "build/my-dynamiccolumns_output.xls"; public static void main(String[] args) throws IOException, ParsePropertyException, InvalidFormatException { if(args.length >= 2) { templateFileName = args[0]; destFileName = args[1]; } Game chess = new Game("chess"); Game poker = new Game("poker"); Game solitaire = new Game("solitaire"); List<Game> games = Arrays.asList(chess, poker, solitaire); Player elsa = new Player("Elsa", 2); Player oleg = new Player("Oleg", 6); Player neil = new Player("Neil", 4); Player maria = new Player("Maria", 3); Player john = new Player("John", 6); List<Player> players = new ArrayList<Player>(); players.add(elsa); players.add(oleg); players.add(neil); players.add(maria); players.add(john); Map<Player, Map<Game, Integer>> results = new HashMap<Player, Map<Game, Integer>>(); Map<Game, Integer> resultsElsa = new HashMap<Game, Integer>(); resultsElsa.put(chess, 1); resultsElsa.put(poker, 0); resultsElsa.put(solitaire, 1); results.put(elsa, resultsElsa); Map<Game, Integer> resultsOleg = new HashMap<Game, Integer>(); resultsOleg.put(chess, 2); resultsOleg.put(poker, 2); resultsOleg.put(solitaire, 0); results.put(oleg, resultsOleg); Map<Game, Integer> resultsNeil = new HashMap<Game, Integer>(); resultsNeil.put(chess, 0); resultsNeil.put(poker, 0); resultsNeil.put(solitaire, 0); results.put(neil, resultsNeil); Map<Game, Integer> resultsMaria = new HashMap<Game, Integer>(); resultsMaria.put(chess, 1); resultsMaria.put(poker, 1); resultsMaria.put(solitaire, 1); results.put(maria, resultsMaria); Map<Game, Integer> resultsJohn = new HashMap<Game, Integer>(); resultsJohn.put(chess, 2); resultsJohn.put(poker, 2); resultsJohn.put(solitaire, 2); results.put(john, resultsJohn); Map beans = new HashMap(); beans.put("games", games); beans.put("players", players); beans.put("results", results); XLSTransformer transformer = new XLSTransformer(); transformer.transformXLS(templateFileName, beans, destFileName); } public static class Game { private String _name; public Game(String name) { super(); _name = name; } public String getName() { return _name; } public void setName(String name) { _name = name; } @Override public String toString() { return getName(); } } public static class Player { private String _name; private int _numGames; public Player(String name, int numGames) { super(); _name = name; _numGames = numGames; } public String getName() { return _name; } public int getGamesCount() { return _numGames; } @Override public String toString() { return getName(); } } }
my-dynamicolumns.xls
Description: MS-Excel spreadsheet
------------------------------------------------------------------------------
_______________________________________________ jXLS-user mailing list jXLS-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jxls-user