List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getSheetAt
@Override public XSSFSheet getSheetAt(int index)
From source file:MonsterStatIndexer.java
License:Open Source License
public static void run() { FileInputStream stream = null; try {//from ww w . ja va2 s . c o m long startIndex = Starts.MONSTER; int ch; stream = new FileInputStream("Dominions4.exe"); stream.skip(startIndex); XSSFWorkbook wb = MonsterStatIndexer.readFile("BaseU.xlsx"); FileOutputStream fos = new FileOutputStream("NewBaseU.xlsx"); XSSFSheet sheet = wb.getSheetAt(0); XSSFRow titleRow = sheet.getRow(0); int cellNum = 0; XSSFCell titleCell = titleRow.getCell(cellNum); Set<String> skip = new HashSet<String>(Arrays.asList(SkipColumns)); while (titleCell != null) { String stringCellValue = titleCell.getStringCellValue(); if (!skip.contains(stringCellValue)) { columnsUsed.put(cellNum, stringCellValue); } cellNum++; titleCell = titleRow.getCell(cellNum); } // Name InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1"); Reader in = new BufferedReader(isr); int rowNumber = 1; while ((ch = in.read()) > -1) { StringBuffer name = new StringBuffer(); while (ch != 0) { name.append((char) ch); ch = in.read(); } if (name.length() == 0) { continue; } if (name.toString().equals("end")) { break; } in.close(); stream = new FileInputStream("Dominions4.exe"); startIndex = startIndex + 256l; stream.skip(startIndex); isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); //System.out.println(name); XSSFRow row = sheet.getRow(rowNumber); XSSFCell cell1 = row.getCell(0, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(rowNumber); rowNumber++; XSSFCell cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(name.toString()); } in.close(); stream.close(); // AP doit1(40, 31, sheet); // MM doit1(42, 30, sheet); // Size doit1(44, 19, sheet); // ressize doit1(44, 20, sheet); doit2(sheet, "0901", 20, new CallbackAdapter() { @Override public String notFound() { return null; } }); // HP doit1(46, 21, sheet); // Prot doit1(48, 22, sheet); // STR doit1(50, 25, sheet); // ENC doit1(52, 29, sheet); // Prec doit1(54, 28, sheet); // ATT doit1(56, 26, sheet); // Def doit1(58, 27, sheet); // MR doit1(60, 23, sheet); // Mor doit1(62, 24, sheet); // wpn1 doit1(208, 2, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn2 doit1(210, 3, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn3 doit1(212, 4, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn4 doit1(214, 5, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn5 doit1(216, 6, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn6 doit1(218, 7, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // wpn7 doit1(220, 8, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // armor1 doit1(228, 9, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // armor2 doit1(230, 10, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // armor3 doit1(232, 11, sheet, new CallbackAdapter() { @Override public String found(String value) { if (Integer.parseInt(value) == 0) { return ""; } return value; } }); // basecost doit1(234, 15, sheet); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER); rowNumber = 1; // res int i = 0; byte[] c = new byte[2]; stream.skip(236); while ((stream.read(c, 0, 2)) != -1) { String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); //System.out.println(Integer.decode("0X" + high + low)); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(18, Row.CREATE_NULL_AS_BLANK); int tmp = new BigInteger(high + low, 16).intValue(); if (tmp < 1000) { cell.setCellValue(Integer.decode("0X" + high + low)); } else { cell.setCellValue(new BigInteger("FFFF" + high + low, 16).intValue()); } stream.skip(254l); i++; if (i >= Starts.MONSTER_COUNT) { break; } } stream.close(); // additional leadership doit2(sheet, "9D00", 35, new Callback() { @Override public String notFound() { return "40"; } @Override public String found(String value) { return Integer.toString(Integer.parseInt(value) + 40); } }); // itemslots defaults doit2(sheet, "B600", 40, new CallbackAdapter() { // hand @Override public String notFound() { return "2"; } }); doit2(sheet, "B600", 41, new CallbackAdapter() { // head @Override public String notFound() { return "1"; } }); doit2(sheet, "B600", 42, new CallbackAdapter() { // body @Override public String notFound() { return "1"; } }); doit2(sheet, "B600", 43, new CallbackAdapter() { // foot @Override public String notFound() { return "1"; } }); doit2(sheet, "B600", 44, new CallbackAdapter() { // misc @Override public String notFound() { return "2"; } }); // Large bitmap for (String[] pair : DOTHESE) { columnsUsed.remove(Integer.parseInt(pair[1])); rowNumber = 1; boolean[] boolArray = largeBitmap(pair[0]); for (boolean found : boolArray) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(Integer.parseInt(pair[1]), Row.CREATE_NULL_AS_BLANK); if (found) { if (pair[0].equals("slow_to_recruit")) { cell.setCellValue(2); } else if (pair[0].equals("heat")) { cell.setCellValue(3); } else if (pair[0].equals("cold")) { cell.setCellValue(3); } else if (pair[0].equals("stealthy40")) { String additional = getAttr("6C00", rowNumber - 1); boolean glamour = false; if (largeBitmap("illusion")[rowNumber - 2]) { glamour = true; } cell.setCellValue(40 + Integer.parseInt(additional.equals("") ? "0" : additional) + (glamour ? 25 : 0)); } else if (pair[0].equals("coldres15")) { String additional = getAttr("C900", rowNumber - 1); boolean cold = false; if (largeBitmap("cold")[rowNumber - 2] || getAttr("DC00", rowNumber - 1).length() > 0) { cold = true; } cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional) + (cold ? 10 : 0)); } else if (pair[0].equals("fireres15")) { String additional = getAttr("C600", rowNumber - 1); boolean heat = false; if (largeBitmap("heat")[rowNumber - 2] || getAttr("3C01", rowNumber - 1).length() > 0) { heat = true; } cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional) + (heat ? 10 : 0)); } else if (pair[0].equals("poisonres15")) { String additional = getAttr("C800", rowNumber - 1); boolean poisoncloud = false; if (largeBitmap("undead")[rowNumber - 2] || largeBitmap("inanimate")[rowNumber - 2] || getAttr("6A00", rowNumber - 1).length() > 0) { poisoncloud = true; } cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional) + (poisoncloud ? 10 : 0)); } else if (pair[0].equals("shockres15")) { String additional = getAttr("C700", rowNumber - 1); cell.setCellValue(15 + Integer.parseInt(additional.equals("") ? "0" : additional)); } else if (pair[0].equals("noleader")) { String additional = getAttr("9D00", rowNumber - 1); XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK); baseLeaderCell.setCellValue("0"); if (!"".equals(additional)) { cell.setCellValue(additional); } else { cell.setCellValue("0"); } } else if (pair[0].equals("poorleader")) { String additional = getAttr("9D00", rowNumber - 1); XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK); baseLeaderCell.setCellValue("10"); if (!"".equals(additional)) { cell.setCellValue(Integer.toString(10 + Integer.parseInt(additional))); } else { cell.setCellValue("10"); } } else if (pair[0].equals("goodleader")) { String additional = getAttr("9D00", rowNumber - 1); XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK); baseLeaderCell.setCellValue("80"); if (!"".equals(additional)) { cell.setCellValue(Integer.toString(80 + Integer.parseInt(additional))); } else { cell.setCellValue("80"); } } else if (pair[0].equals("expertleader")) { String additional = getAttr("9D00", rowNumber - 1); XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK); baseLeaderCell.setCellValue("120"); if (!"".equals(additional)) { cell.setCellValue(Integer.toString(120 + Integer.parseInt(additional))); } else { cell.setCellValue("120"); } } else if (pair[0].equals("superiorleader")) { String additional = getAttr("9D00", rowNumber - 1); XSSFCell baseLeaderCell = row.getCell(248, Row.CREATE_NULL_AS_BLANK); baseLeaderCell.setCellValue("160"); if (!"".equals(additional)) { cell.setCellValue(Integer.toString(160 + Integer.parseInt(additional))); } else { cell.setCellValue("160"); } } else if (pair[0].equals("poormagicleader")) { cell.setCellValue("10"); } else if (pair[0].equals("okmagicleader")) { cell.setCellValue("40"); } else if (pair[0].equals("goodmagicleader")) { cell.setCellValue("80"); } else if (pair[0].equals("expertmagicleader")) { cell.setCellValue("120"); } else if (pair[0].equals("superiormagicleader")) { cell.setCellValue("160"); } else if (pair[0].equals("poorundeadleader")) { cell.setCellValue("10"); } else if (pair[0].equals("okundeadleader")) { cell.setCellValue("40"); } else if (pair[0].equals("goodundeadleader")) { cell.setCellValue("80"); } else if (pair[0].equals("expertundeadleader")) { cell.setCellValue("120"); } else if (pair[0].equals("superiorundeadleader")) { cell.setCellValue("160"); } else if (pair[0].equals("misc2")) { XSSFCell handCell = row.getCell(40, Row.CREATE_NULL_AS_BLANK); handCell.setCellValue(0); XSSFCell headCell = row.getCell(41, Row.CREATE_NULL_AS_BLANK); headCell.setCellValue(0); XSSFCell bodyCell = row.getCell(42, Row.CREATE_NULL_AS_BLANK); bodyCell.setCellValue(0); XSSFCell footCell = row.getCell(43, Row.CREATE_NULL_AS_BLANK); footCell.setCellValue(0); XSSFCell miscCell = row.getCell(44, Row.CREATE_NULL_AS_BLANK); miscCell.setCellValue(2); } else if (pair[0].equals("mounted")) { XSSFCell footCell = row.getCell(43, Row.CREATE_NULL_AS_BLANK); footCell.setCellValue(0); } else { cell.setCellValue(1); } } else { if (pair[0].equals("slow_to_recruit")) { cell.setCellValue(1); } else if (pair[0].equals("heat")) { cell.setCellValue(getAttr("3C01", rowNumber - 1)); } else if (pair[0].equals("cold")) { cell.setCellValue(getAttr("DC00", rowNumber - 1)); } else if (pair[0].equals("coldres15")) { boolean cold = false; if (largeBitmap("cold")[rowNumber - 2] || getAttr("DC00", rowNumber - 1).length() > 0) { cold = true; } String additional = getAttr("C900", rowNumber - 1); int coldres = Integer.parseInt(additional.equals("") ? "0" : additional) + (cold ? 10 : 0); cell.setCellValue(coldres == 0 ? "" : Integer.toString(coldres)); } else if (pair[0].equals("fireres15")) { boolean heat = false; if (largeBitmap("heat")[rowNumber - 2] || getAttr("3C01", rowNumber - 1).length() > 0) { heat = true; } String additional = getAttr("C600", rowNumber - 1); int coldres = Integer.parseInt(additional.equals("") ? "0" : additional) + (heat ? 10 : 0); cell.setCellValue(coldres == 0 ? "" : Integer.toString(coldres)); } else if (pair[0].equals("poisonres15")) { boolean poisoncloud = false; if (largeBitmap("undead")[rowNumber - 2] || largeBitmap("inanimate")[rowNumber - 2] || getAttr("6A00", rowNumber - 1).length() > 0) { poisoncloud = true; } String additional = getAttr("C800", rowNumber - 1); int poisonres = Integer.parseInt(additional.equals("") ? "0" : additional) + (poisoncloud ? 10 : 0); cell.setCellValue(poisonres == 0 ? "" : Integer.toString(poisonres)); } else if (pair[0].equals("shockres15")) { String additional = getAttr("C700", rowNumber - 1); int shockres = Integer.parseInt(additional.equals("") ? "0" : additional); cell.setCellValue(shockres == 0 ? "" : Integer.toString(shockres)); } else if (pair[0].equals("stealthy40")) { String additional = getAttr("6C00", rowNumber - 1); cell.setCellValue(additional == null || additional.equals("") ? "" : additional); } else if (pair[0].equals("immobile") || pair[0].equals("teleport") || pair[0].equals("float") || pair[0].equals("bluntres") || pair[0].equals("slashres") || pair[0].equals("pierceres")) { cell.setCellValue(""); } else if (pair[0].equals("noleader") || pair[0].equals("poorleader") || pair[0].equals("goodleader") || pair[0].equals("expertleader") || pair[0].equals("superiorleader") || pair[0].equals("poormagicleader") || pair[0].equals("okmagicleader") || pair[0].equals("goodmagicleader") || pair[0].equals("expertmagicleader") || pair[0].equals("superiormagicleader") || pair[0].equals("poorundeadleader") || pair[0].equals("okundeadleader") || pair[0].equals("goodundeadleader") || pair[0].equals("expertundeadleader") || pair[0].equals("superiorundeadleader") || pair[0].equals("misc2")) { } else { cell.setCellValue(0); } } } } /*stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER); i = 0; c = new byte[16]; stream.skip(240); while ((stream.read(c, 0, 16)) != -1) { boolean found = false; System.out.print("(" + (i+1) + ") "); String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); //System.out.print(high + low + " "); int val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print("1:{"); for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value1[j].equals("")?("*****"+(j+1)+"*****"):value1[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[3]); low = String.format("%02X", c[2]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 2:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value2[j].equals("")?("*****"+(j+1)+"*****"):value2[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[5]); low = String.format("%02X", c[4]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 3:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value3[j].equals("")?("*****"+(j+1)+"*****"):value3[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[7]); low = String.format("%02X", c[6]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 4:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value4[j].equals("")?("*****"+(j+1)+"*****"):value4[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[9]); low = String.format("%02X", c[8]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 5:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value5[j].equals("")?("*****"+(j+1)+"*****"):value5[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[11]); low = String.format("%02X", c[10]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 6:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value6[j].equals("")?(j+1):value6[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[13]); low = String.format("%02X", c[12]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 7:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value7[j].equals("")?(j+1):value7[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[15]); low = String.format("%02X", c[14]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 8:{"); found = false; for (int j=0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found?",":"") + (value8[j].equals("")?(j+1):value8[j])); found = true; } } System.out.print("}"); } if (!found) { //System.out.println(""); } System.out.println(" "); stream.skip(240l); i++; if (i >= Starts.MONSTER_COUNT) { break; } } stream.close();*/ // realm stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER); i = 0; int k = 0; Set<Integer> posSet = new HashSet<Integer>(); long numFound = 0; c = new byte[2]; stream.skip(64); while ((stream.read(c, 0, 2)) != -1) { String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); int weapon = Integer.decode("0X" + high + low); if (weapon == 0) { stream.skip(46l - numFound * 2l); int numRealms = 0; // Values for (int x = 0; x < numFound; x++) { byte[] d = new byte[4]; stream.read(d, 0, 4); String high1 = String.format("%02X", d[3]); String low1 = String.format("%02X", d[2]); high = String.format("%02X", d[1]); low = String.format("%02X", d[0]); //System.out.print(low + high + " "); if (posSet.contains(x)) { int fire = new BigInteger(high1 + low1 + high + low, 16).intValue();//Integer.decode("0X" + high + low); //System.out.print(i+1 + "\t" + fire); //System.out.println(""); XSSFRow row = sheet.getRow(i + 1); XSSFCell cell = row.getCell(233 + numRealms, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(fire); numRealms++; } //stream.skip(2); } // System.out.println(""); stream.skip(254l - 46l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("AA01")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.MONSTER_COUNT) { break; } } stream.close(); // patience doit2(sheet, "CD01", 104); // stormimmune doit2(sheet, "AF00", 94, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // regeneration doit2(sheet, "BD00", 151); // secondshape doit2(sheet, "C200", 210); // firstshape doit2(sheet, "C300", 209); // shapechange doit2(sheet, "C100", 208); // secondtmpshape doit2(sheet, "C400", 211); // landshape doit2(sheet, "F500", 212); // watershape doit2(sheet, "F600", 213); // forestshape doit2(sheet, "4201", 214); // plainshape doit2(sheet, "4301", 215); // damagerev doit2(sheet, "CA00", 144, new CallbackAdapter() { @Override public String found(String value) { return Integer.toString(Integer.parseInt(value) - 1); } }); // bloodvengeance doit2(sheet, "9E01", 231); // nobadevents doit2(sheet, "EB00", 178); // bringeroffortune doit2(sheet, "E400", 232); // darkvision doit2(sheet, "1901", 133); // fear doit2(sheet, "B700", 138); // voidsanity doit2(sheet, "1501", 132); // standard doit2(sheet, "6700", 117); // formationfighter doit2(sheet, "6E01", 115); // undisciplined doit2(sheet, "6F01", 114); // bodyguard doit2(sheet, "9801", 121); // summon doit2(sheet, "A400,A500,A600", 223); doit2(sheet, "A400", 224, new CallbackAdapter() { @Override public String found(String value) { return "1"; } @Override public String notFound() { return null; } }); doit2(sheet, "A500", 224, new CallbackAdapter() { @Override public String found(String value) { return "2"; } @Override public String notFound() { return null; } }); doit2(sheet, "A600", 224, new CallbackAdapter() { @Override public String found(String value) { return "3"; } @Override public String notFound() { return null; } }); doit2(sheet, "A400,A500,A600", 224, new CallbackAdapter() { @Override public String found(String value) { return null; } }); // inspirational doit2(sheet, "7001", 118); // pillagebonus doit2(sheet, "8300", 187); // berserk doit2(sheet, "BE00", 139); // pathcost doit2(sheet, "F300", 45); // default startdom doit2(sheet, "F300", 46, new CallbackAdapter() { @Override public String found(String value) { return "1"; } }); // startdom doit2(sheet, "F200", 46, new CallbackAdapter() { @Override public String notFound() { return null; } }); // waterbreathing doit2(sheet, "6F00", 122); // batstartsum1 doit2(sheet, "B401", 227); // batstartsum2 doit2(sheet, "B501", 228); // batstartsum3 doit2(sheet, "B601", 236); // batstartsum4 doit2(sheet, "B701", 237); // batstartsum5 doit2(sheet, "B801", 238); // batstartsum1d6 doit2(sheet, "B901", 239); // batstartsum2d6 doit2(sheet, "BA01", 240); // batstartsum3d6 doit2(sheet, "BB01", 241); // batstartsum4d6 doit2(sheet, "BC01", 242); // batstartsum5d6 doit2(sheet, "BD01", 243); // batstartsum6d6 doit2(sheet, "BE01", 244); // autosummon (#summon1-5) doit2(sheet, "F100,6B00,8F00", 225); doit2(sheet, "F100", 226, new CallbackAdapter() { @Override public String found(String value) { return "?"; } @Override public String notFound() { return null; } }); doit2(sheet, "6B00", 226, new CallbackAdapter() { @Override public String found(String value) { return "?"; } @Override public String notFound() { return null; } }); doit2(sheet, "8F00", 226, new CallbackAdapter() { @Override public String found(String value) { return "?"; } @Override public String notFound() { return null; } }); doit2(sheet, "F100,6B00,8F00", 226, new CallbackAdapter() { @Override public String found(String value) { return null; } }); // domsummon doit2(sheet, "A101,DB00", 229); doit2(sheet, "A101", 230, new CallbackAdapter() { @Override public String found(String value) { return "?"; } @Override public String notFound() { return null; } }); doit2(sheet, "DB00", 230, new CallbackAdapter() { @Override public String found(String value) { return "?"; } @Override public String notFound() { return null; } }); doit2(sheet, "A101,DB00", 230, new CallbackAdapter() { @Override public String found(String value) { return null; } }); // turmoil summon doit2(sheet, "AD00", 245); // cold summon doit2(sheet, "9200", 246); // stormpower doit2(sheet, "AE00", 161); // firepower doit2(sheet, "B100", 162); // coldpower doit2(sheet, "B000", 163); // darkpower doit2(sheet, "2501", 164); // chaospower doit2(sheet, "A001", 165); // magicpower doit2(sheet, "4401", 166); // winterpower doit2(sheet, "EA00", 167); // springpower doit2(sheet, "E700", 168); // summerpower doit2(sheet, "E800", 169); // fallpower doit2(sheet, "E900", 170); // nametype doit2(sheet, "FB00", 219); // blind doit2(sheet, "AB00", 134, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // eyes doit2(sheet, "B200", 279, new CallbackAdapter() { @Override public String found(String value) { return Integer.toString((Integer.parseInt(value) + 2)); } }); // supplybonus doit2(sheet, "7A00", 192); // slave doit2(sheet, "7C01", 116); // awe doit2(sheet, "6900", 136); // siegebonus doit2(sheet, "7D00", 190); // researchbonus doit2(sheet, "7900", 195); // chaosrec doit2(sheet, "CA01", 186); // invulnerability doit2(sheet, "7E01", 124); // iceprot doit2(sheet, "BF00", 123); // reinvigoration doit2(sheet, "7500", 34, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // ambidextrous doit2(sheet, "D900", 32, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // spy doit2(sheet, "D600", 102, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // scale walls doit2(sheet, "E301", 247); // dream seducer (succubus) doit2(sheet, "D200", 106, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // seduction doit2(sheet, "2A01", 105, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // assassin doit2(sheet, "D500", 103, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // explode on death doit2(sheet, "2901", 249); // taskmaster doit2(sheet, "7B01", 119); // unique doit2(sheet, "1301", 216, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // poisoncloud doit2(sheet, "6A00", 145); // startaff doit2(sheet, "B900", 250); // uwregen doit2(sheet, "DD00", 251); // patrolbonus doit2(sheet, "AA00", 188); // castledef doit2(sheet, "D700", 189); // sailsz doit2(sheet, "7000", 98, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // maxsailsz doit2(sheet, "9A01", 99); // incunrest doit2(sheet, "DF00", 193, new CallbackAdapter() { @Override public String found(String value) { double val = Double.parseDouble(value) / 10d; if (val < 1 && val > -1) { return Double.toString(val); } return Integer.toString((int) val); } }); // barbs doit2(sheet, "BC00", 153, new CallbackAdapter() { @Override public String found(String value) { return "1"; } @Override public String notFound() { return "0"; } }); // inn doit2(sheet, "4E01", 47); // stonebeing doit2(sheet, "1801", 80, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // shrinkhp doit2(sheet, "5001", 252); // growhp doit2(sheet, "4F01", 253); // transformation doit2(sheet, "FD01", 254); // heretic doit2(sheet, "B800", 206); // popkill doit2(sheet, "2001", 194, new CallbackAdapter() { @Override public String found(String value) { return Integer.toString(Integer.parseInt(value) * 10); } }); // autohealer doit2(sheet, "6201", 175); // fireshield doit2(sheet, "A300", 142); // startingaff doit2(sheet, "E200", 255); // fixedresearch doit2(sheet, "F800", 256); // divineins doit2(sheet, "C201", 257); // halt doit2(sheet, "4701", 137); // crossbreeder doit2(sheet, "AF01", 201); // reclimit doit2(sheet, "7D01", 14); // fixforgebonus doit2(sheet, "C501", 172); // mastersmith doit2(sheet, "6B01", 173); // lamiabonus doit2(sheet, "A900", 258); // homesick doit2(sheet, "FD00", 113); // banefireshield doit2(sheet, "DE00", 143); // animalawe doit2(sheet, "A200", 135); // autodishealer doit2(sheet, "6301", 176); // shatteredsoul doit2(sheet, "4801", 181); // voidsum doit2(sheet, "CE00", 205); // makepearls doit2(sheet, "AE01", 202); // inspiringres doit2(sheet, "5501", 197); // drainimmune doit2(sheet, "1101", 196); // diseasecloud doit2(sheet, "AC00", 146); // inquisitor doit2(sheet, "D300", 74, new CallbackAdapter() { @Override public String notFound() { return "0"; } }); // beastmaster doit2(sheet, "7101", 120); // douse doit2(sheet, "7400", 198); // preanimator doit2(sheet, "6C01", 259); // dreanimator doit2(sheet, "6D01", 260); // mummify doit2(sheet, "FF01", 261); // onebattlespell doit2(sheet, "D100", 262); // fireattuned doit2(sheet, "F501", 263); // airattuned doit2(sheet, "F601", 264); // waterattuned doit2(sheet, "F701", 265); // earthattuned doit2(sheet, "F801", 266); // astralattuned doit2(sheet, "F901", 267); // deathattuned doit2(sheet, "FA01", 268); // natureattuned doit2(sheet, "FB01", 269); // bloodattuned doit2(sheet, "FC01", 270); // magicboost F doit2(sheet, "0A00", 271); // magicboost A doit2(sheet, "0B00", 272); // magicboost W doit2(sheet, "0C00", 273); // magicboost E doit2(sheet, "0D00", 274); // magicboost S doit2(sheet, "0E00", 275); // magicboost D doit2(sheet, "0F00", 276); // magicboost N doit2(sheet, "1000", 277); // magicboost ALL doit2(sheet, "1600", 278); // heatrec doit2(sheet, "EA01", 280, new CallbackAdapter() { @Override public String found(String value) { return "1"; } }); // coldrec doit2(sheet, "EB01", 281, new CallbackAdapter() { @Override public String found(String value) { return "1"; } }); // spread chaos doit2(sheet, "D801", 282, new CallbackAdapter() { @Override public String found(String value) { if (value.equals("100")) { return "1"; } return ""; } }); // spread death doit2(sheet, "D801", 283, new CallbackAdapter() { @Override public String found(String value) { if (value.equals("103")) { return "1"; } return ""; } }); // corpseeater doit2(sheet, "EC00", 284); // poisonskin doit2(sheet, "0602", 285); // bug doit2(sheet, "AB01", 286); // uwbug doit2(sheet, "AC01", 287); // gemprod fire doit2(sheet, "1E00", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "F"; } }); // gemprod air doit2(sheet, "1F00", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "A"; } @Override public String notFound() { return null; } }, true); // gemprod water doit2(sheet, "2000", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "W"; } @Override public String notFound() { return null; } }, true); // gemprod earth doit2(sheet, "2100", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "E"; } @Override public String notFound() { return null; } }, true); // gemprod astral doit2(sheet, "2200", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "S"; } @Override public String notFound() { return null; } }, true); // gemprod death doit2(sheet, "2300", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "D"; } @Override public String notFound() { return null; } }, true); // gemprod nature doit2(sheet, "2400", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "N"; } @Override public String notFound() { return null; } }, true); // gemprod blood doit2(sheet, "2500", 185, new CallbackAdapter() { @Override public String found(String value) { return value + "B"; } @Override public String notFound() { return null; } }, true); // itemslots doit2(sheet, "B600", 40, new CallbackAdapter() { // hand @Override public String found(String value) { int numHands = 0; int val = Integer.parseInt(value); if ((val & 0x0002) != 0) { numHands++; } if ((val & 0x0004) != 0) { numHands++; } if ((val & 0x0008) != 0) { numHands++; } if ((val & 0x0010) != 0) { numHands++; } return Integer.toString(numHands); } @Override public String notFound() { return null; } }); doit2(sheet, "B600", 41, new CallbackAdapter() { // head @Override public String found(String value) { int numHeads = 0; int val = Integer.parseInt(value); if ((val & 0x0080) != 0) { numHeads++; } if ((val & 0x0100) != 0) { numHeads++; } if ((val & 0x0200) != 0) { numHeads++; } return Integer.toString(numHeads); } @Override public String notFound() { return null; } }); doit2(sheet, "B600", 42, new CallbackAdapter() { // body @Override public String found(String value) { int numBody = 0; int val = Integer.parseInt(value); if ((val & 0x0400) != 0) { numBody++; } return Integer.toString(numBody); } @Override public String notFound() { return null; } }); doit2(sheet, "B600", 43, new CallbackAdapter() { // foot @Override public String found(String value) { int numFoot = 0; int val = Integer.parseInt(value); if ((val & 0x0800) != 0) { numFoot++; } return Integer.toString(numFoot); } @Override public String notFound() { return null; } }); doit2(sheet, "B600", 44, new CallbackAdapter() { // misc @Override public String found(String value) { int numMisc = 0; int val = Integer.parseInt(value); if ((val & 0x1000) != 0) { numMisc++; } if ((val & 0x2000) != 0) { numMisc++; } if ((val & 0x4000) != 0) { numMisc++; } if ((val & 0x8000) != 0) { numMisc++; } if ((val & 0x10000) != 0) { numMisc++; } return Integer.toString(numMisc); } @Override public String notFound() { return null; } }); // startage doit2(sheet, "1D01", 38, new CallbackAdapter() { @Override public String found(String value) { int age = Integer.parseInt(value); if (age == -1) { age = 0; } return Integer.toString((int) (age + age * .1)); } @Override public String notFound() { return null; } }); // maxage doit2(sheet, "1C01", 39, new CallbackAdapter() { @Override public String notFound() { return null; } }); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER_MAGIC); // magic c = new byte[4]; while ((stream.read(c, 0, 4)) != -1) { String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); if ((high + low).equals("FFFF")) { break; } int id = Integer.decode("0X" + high + low); Magic monMagic = monsterMagic.get(id); if (monMagic == null) { monMagic = new Magic(); monsterMagic.put(id, monMagic); } //System.out.print("id: " + Integer.decode("0X" + high + low)); stream.read(c, 0, 4); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); int path = Integer.decode("0X" + high + low); //System.out.print(" path: " + Integer.decode("0X" + high + low)); stream.read(c, 0, 4); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); int value = Integer.decode("0X" + high + low); //System.out.println(" value: " + Integer.decode("0X" + high + low)); switch (path) { case 0: monMagic.F = value; break; case 1: monMagic.A = value; break; case 2: monMagic.W = value; break; case 3: monMagic.E = value; break; case 4: monMagic.S = value; break; case 5: monMagic.D = value; break; case 6: monMagic.N = value; break; case 7: monMagic.B = value; break; case 8: monMagic.H = value; break; default: RandomMagic monRandomMagic = null; List<RandomMagic> randomMagicList = monMagic.rand; if (randomMagicList == null) { randomMagicList = new ArrayList<RandomMagic>(); monRandomMagic = new RandomMagic(); if (path == 50) { monRandomMagic.mask = 32640; monRandomMagic.nbr = 1; monRandomMagic.link = value; monRandomMagic.rand = 100; } else if (path == 51) { monRandomMagic.mask = 1920; monRandomMagic.nbr = 1; monRandomMagic.link = value; monRandomMagic.rand = 100; } else { monRandomMagic.mask = path; monRandomMagic.nbr = 1; if (value > 100) { monRandomMagic.link = value / 100; monRandomMagic.rand = 100; } else { monRandomMagic.link = 1; monRandomMagic.rand = value; } } randomMagicList.add(monRandomMagic); monMagic.rand = randomMagicList; } else { boolean found = false; for (RandomMagic ranMagic : randomMagicList) { if (ranMagic.mask == path && ranMagic.rand == value) { ranMagic.nbr++; found = true; } if (ranMagic.mask == 32640 && path == 50 && ranMagic.link == value) { ranMagic.nbr++; found = true; } if (ranMagic.mask == 1920 && path == 51 && ranMagic.link == value) { ranMagic.nbr++; found = true; } } if (!found) { monRandomMagic = new RandomMagic(); if (path == 50) { monRandomMagic.mask = 32640; monRandomMagic.nbr = 1; monRandomMagic.link = value; monRandomMagic.rand = 100; } else if (path == 51) { monRandomMagic.mask = 1920; monRandomMagic.nbr = 1; monRandomMagic.link = value; monRandomMagic.rand = 100; } else { monRandomMagic.mask = path; monRandomMagic.nbr = 1; if (value > 100) { monRandomMagic.link = value / 100; monRandomMagic.rand = 100; } else { monRandomMagic.link = 1; monRandomMagic.rand = value; } } randomMagicList.add(monRandomMagic); } } } } for (int j = 1; j < Starts.MONSTER_COUNT; j++) { Magic monMagic = monsterMagic.get(j); if (monMagic != null) { XSSFRow row = sheet.getRow(j); XSSFCell cell = row.getCell(48, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.F)); cell = row.getCell(49, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.A)); cell = row.getCell(50, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.W)); cell = row.getCell(51, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.E)); cell = row.getCell(52, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.S)); cell = row.getCell(53, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.D)); cell = row.getCell(54, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.N)); cell = row.getCell(55, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.B)); cell = row.getCell(56, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(monMagic.H)); //System.out.print(magout(monMagic.F) + magout(monMagic.A ) + magout(monMagic.W) + magout(monMagic.E) + magout(monMagic.S) + magout(monMagic.D) + magout(monMagic.N) + magout(monMagic.B) + magout(monMagic.H)); if (monMagic.rand != null) { int count = 0; for (RandomMagic ranMag : monMagic.rand) { cell = row.getCell(57 + count * 4, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(ranMag.rand)); cell = row.getCell(58 + count * 4, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(ranMag.nbr)); cell = row.getCell(59 + count * 4, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(ranMag.link)); cell = row.getCell(60 + count * 4, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(magicStrip(ranMag.mask)); count++; //System.out.print(ranMag.rand + "\t" + ranMag.nbr + "\t" + ranMag.link + "\t" + ranMag.mask + "\t"); } } } //System.out.println(""); } stream.close(); wb.write(fos); fos.close(); for (String col : columnsUsed.values()) { System.out.println(col); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:TaskFetcher.java
static HashMap<String, String> fetchActiveTasks(String username, String excel_path) { HashMap<String, String> activetasks = new HashMap<String, String>(); FileInputStream file = null;/*from www.ja v a2 s .co m*/ try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); if (rowIterator.hasNext()) rowIterator.next(); //skipping the first row of heading while (rowIterator.hasNext()) //loop over all entries in the excel sheet { Row row = rowIterator.next(); Cell cell = row.getCell(0); if (username.equalsIgnoreCase(cell.getStringCellValue())) { String task; String status; String totTimeString = null; String latestTimeStamp; double totTime; task = row.getCell(1).getStringCellValue(); status = row.getCell(2).getStringCellValue(); latestTimeStamp = row.getCell(3).getStringCellValue(); if (status.equalsIgnoreCase("Paused") || status.equalsIgnoreCase("Deferred")) { if (row.getCell(4) != null) totTimeString = row.getCell(4).getStringCellValue(); } else if (status.equalsIgnoreCase("In-Progress")) { if (row.getCell(4) != null) totTimeString = row.getCell(4).getStringCellValue(); if (totTimeString != null) { totTime = Double.parseDouble(totTimeString); } else { totTime = 0; } DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date currentTimestamp = new Date(); Date latestTimeStampObj = null; df.format(currentTimestamp); try { latestTimeStampObj = df.parse(latestTimeStamp); } catch (ParseException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } long timeDifference = currentTimestamp.getTime() - latestTimeStampObj.getTime(); long divisor = 60 * 60 * 1000; double diffHours = ((double) timeDifference / (double) divisor); totTime += diffHours; totTimeString = String.valueOf(totTime); } if (status != null && !status.equalsIgnoreCase("completed") && task != null && totTimeString != null) { activetasks.put(task, status + ":" + totTimeString); } } } try { workbook.close(); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } return activetasks; }
From source file:TaskFetcher.java
static HashMap<String, String> fetchAllTasks(String username, String excel_path) { HashMap<String, String> alltasks = new HashMap<String, String>(); FileInputStream file = null;//from w ww.j a v a 2 s .co m try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(1); Iterator<Row> rowIterator = sheet.iterator(); if (rowIterator.hasNext()) rowIterator.next(); //skipping the first row of heading while (rowIterator.hasNext()) //loop over all entries in the excel sheet { Row row = rowIterator.next(); Cell cell = row.getCell(0); if (username.equalsIgnoreCase(cell.getStringCellValue())) { String task; String status; String timestamp; String comments; task = row.getCell(1).getStringCellValue(); status = row.getCell(2).getStringCellValue(); timestamp = row.getCell(3).getStringCellValue(); comments = row.getCell(4).getStringCellValue(); alltasks.put(timestamp, task + ":" + status + ":" + comments); } } try { workbook.close(); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } return alltasks; }
From source file:ItemStatIndexer.java
License:Open Source License
public static void run() { FileInputStream stream = null; try {/*from w ww.ja v a 2s . co m*/ long startIndex = Starts.ITEM; int ch; stream = new FileInputStream("Dominions4.exe"); stream.skip(startIndex); XSSFWorkbook wb = ItemStatIndexer.readFile("BaseI.xlsx"); FileOutputStream fos = new FileOutputStream("NewBaseI.xlsx"); XSSFSheet sheet = wb.getSheetAt(0); XSSFRow titleRow = sheet.getRow(0); int cellNum = 0; XSSFCell titleCell = titleRow.getCell(cellNum); Set<String> skip = new HashSet<String>(Arrays.asList(SkipColumns)); while (titleCell != null) { String stringCellValue = titleCell.getStringCellValue(); if (!skip.contains(stringCellValue)) { columnsUsed.put(cellNum, stringCellValue); } cellNum++; titleCell = titleRow.getCell(cellNum); } // Name InputStreamReader isr = new InputStreamReader(stream, "ISO-8859-1"); Reader in = new BufferedReader(isr); int rowNumber = 1; while ((ch = in.read()) > -1) { StringBuffer name = new StringBuffer(); while (ch != 0) { name.append((char) ch); ch = in.read(); } if (name.length() == 0) { continue; } if (name.toString().equals("end")) { break; } in.close(); stream = new FileInputStream("Dominions4.exe"); startIndex = startIndex + 208l; stream.skip(startIndex); isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); //System.out.println(name); XSSFRow row = sheet.getRow(rowNumber); XSSFCell cell1 = row.getCell(0, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(rowNumber); rowNumber++; XSSFCell cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(name.toString()); } in.close(); stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Const level int i = 0; byte[] c = new byte[1]; stream.skip(36); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(3, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(c[0]*2); cell.setCellValue(c[0] * 2); } stream.skip(207l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Mainpath String[] paths = { "F", "A", "W", "E", "S", "D", "N", "B" }; i = 0; c = new byte[1]; stream.skip(37); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(4, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(paths[c[0]]); cell.setCellValue(paths[c[0]]); } stream.skip(207l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // main level i = 0; c = new byte[1]; stream.skip(39); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(5, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(c[0]); cell.setCellValue(c[0]); } stream.skip(207l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Secondary path i = 0; c = new byte[1]; stream.skip(38); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(6, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(paths[c[0]]); cell.setCellValue(paths[c[0]]); } stream.skip(207l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Secondary level i = 0; c = new byte[1]; stream.skip(40); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(7, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1 || c[0] == 0) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(c[0]); cell.setCellValue(c[0]); } stream.skip(207l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Weapon i = 0; c = new byte[2]; stream.skip(44); while ((stream.read(c, 0, 2)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(8, Row.CREATE_NULL_AS_BLANK); String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); int weapon = Integer.decode("0X" + high + low); if (weapon == 0) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(Integer.decode("0X" + high + low)); cell.setCellValue(Integer.decode("0X" + high + low)); } stream.skip(206l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; // Armor i = 0; c = new byte[2]; stream.skip(46); while ((stream.read(c, 0, 2)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(9, Row.CREATE_NULL_AS_BLANK); String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); int weapon = Integer.decode("0X" + high + low); if (weapon == 0) { //System.out.println(""); cell.setCellValue(""); } else { //System.out.println(Integer.decode("0X" + high + low)); cell.setCellValue(Integer.decode("0X" + high + low)); } stream.skip(206l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; startIndex = Starts.ITEM; // Itemspell stream.skip(48); startIndex = startIndex + 48l; i = 0; isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); while ((ch = in.read()) > -1) { StringBuffer name = new StringBuffer(); while (ch != 0) { name.append((char) ch); ch = in.read(); } in.close(); stream = new FileInputStream("Dominions4.exe"); startIndex = startIndex + 208l; stream.skip(startIndex); isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); //System.out.println(name); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(130, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(name.toString()); i++; if (i >= Starts.ITEM_COUNT) { break; } } in.close(); stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); rowNumber = 1; startIndex = Starts.ITEM; // Startbattlespell and Autocombatspell stream.skip(84); startIndex = startIndex + 84l; i = 0; isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); while ((ch = in.read()) > -1) { StringBuffer name = new StringBuffer(); while (ch != 0) { name.append((char) ch); ch = in.read(); } in.close(); int blankCol = 129; int column = 128; if (hasAttr("8500", startIndex + 36l)) { column = 129; blankCol = 128; } stream = new FileInputStream("Dominions4.exe"); startIndex = startIndex + 208l; stream.skip(startIndex); isr = new InputStreamReader(stream, "ISO-8859-1"); in = new BufferedReader(isr); //System.out.println(name); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(name.toString()); XSSFCell blankcell = row.getCell(blankCol, Row.CREATE_NULL_AS_BLANK); blankcell.setCellValue(""); i++; if (i >= Starts.ITEM_COUNT) { break; } } in.close(); stream.close(); // Fireres doit(sheet, "C600", 11); // Coldres doit(sheet, "C900", 12); // Poisonres doit(sheet, "C800", 13); // Shockres doit(sheet, "C700", 10); // Leadership doit(sheet, "9D00", 61); // str doit(sheet, "9700", 28); // fixforge doit(sheet, "C501", 18); // magic leadership doit(sheet, "9E00", 63); // undead leadership doit(sheet, "9F00", 62); // inspirational leadership doit(sheet, "7001", 64); // morale doit(sheet, "3401", 27); // penetration doit(sheet, "A100", 36); // pillage doit(sheet, "8300", 113); // fear doit(sheet, "B700", 66); // mr doit(sheet, "A000", 26); // taint doit(sheet, "0601", 60); // reinvigoration doit(sheet, "7500", 35); // awe doit(sheet, "6900", 67); // F doit(sheet, "0A00", 73); // A doit(sheet, "0B00", 74); // W doit(sheet, "0C00", 75); // E doit(sheet, "0D00", 76); // S doit(sheet, "0E00", 77); // D doit(sheet, "0F00", 78); // N doit(sheet, "1000", 79); // B doit(sheet, "1100", 80); // H doit(sheet, "1200", 81); // elemental doit(sheet, "1400", 73, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1400", 74, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1400", 75, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1400", 76, new CallbackAdapter() { @Override public String notFound() { return null; } }); // sorcery doit(sheet, "1500", 77, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1500", 78, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1500", 79, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1500", 80, new CallbackAdapter() { @Override public String notFound() { return null; } }); // all paths doit(sheet, "1600", 73, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 74, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 75, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 76, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 77, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 78, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 79, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1600", 80, new CallbackAdapter() { @Override public String notFound() { return null; } }); // fire ritual range doit(sheet, "2800", 82); // air ritual range doit(sheet, "2900", 83); // water ritual range doit(sheet, "2A00", 84); // earth ritual range doit(sheet, "2B00", 85); // astral ritual range doit(sheet, "2C00", 86); // death ritual range doit(sheet, "2D00", 87); // nature ritual range doit(sheet, "2E00", 88); // blood ritual range doit(sheet, "2F00", 89); // elemental range doit(sheet, "1700", 82, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1700", 83, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1700", 84, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1700", 85, new CallbackAdapter() { @Override public String notFound() { return null; } }); // sorcery range doit(sheet, "1800", 86, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1800", 87, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1800", 88, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1800", 89, new CallbackAdapter() { @Override public String notFound() { return null; } }); // all range doit(sheet, "1900", 82, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 83, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 84, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 85, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 86, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 87, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 88, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "1900", 89, new CallbackAdapter() { @Override public String notFound() { return null; } }); // darkvision doit(sheet, "1901", 14); // limited regeneration doit(sheet, "CE01", 16); // regeneration doit(sheet, "BD00", 141); // waterbreathing doit(sheet, "6E00", 47); // airbreathing doit(sheet, "8100", 49); // stealthb doit(sheet, "8601", 38); // stealth doit(sheet, "6C00", 37); // att doit(sheet, "9600", 29); // def doit(sheet, "7901", 30); // woundfend doit(sheet, "9601", 17); // berserk doit(sheet, "BE00", 106); // aging doit(sheet, "2F01", 145); // ivylord doit(sheet, "6500", 126); // forest doit(sheet, "A601", 39); // waste doit(sheet, "A701", 41); // mount doit(sheet, "A501", 40); // swamp doit(sheet, "A801", 42); // researchbonus doit(sheet, "7900", 118); // gitfofwater doit(sheet, "6F00", 48); // corpselord doit(sheet, "9A00", 146); // lictorlord doit(sheet, "6600", 147); // sumauto doit(sheet, "8B00", 134); // bloodsac doit(sheet, "D800", 148); // mastersmith doit(sheet, "6B01", 149); // alch doit(sheet, "8400", 21); // eyeloss doit(sheet, "7E00", 150); // armysize doit(sheet, "A301", 151); // defender doit(sheet, "8900", 152); // Hack for Forbidden Light doit(sheet, "7700", 73, new CallbackAdapter() { @Override public String notFound() { return null; } @Override public String found(String value) { return "2"; } }); doit(sheet, "7700", 77, new CallbackAdapter() { @Override public String notFound() { return null; } @Override public String found(String value) { return "2"; } }); // cannotwear doit(sheet, "C701", 153, new CallbackAdapter() { @Override public String notFound() { return null; } }); doit(sheet, "C801", 153, new CallbackAdapter() { @Override public String notFound() { return null; } }); // sailsz doit(sheet, "7000", 45); // maxsail doit(sheet, "9A01", 46); // flytr doit(sheet, "7100", 50); // protf doit(sheet, "7F01", 24); // heretic doit(sheet, "B800", 119); // autodishealer doit(sheet, "6301", 19); // patrolbonus doit(sheet, "AA00", 114); // prec doit(sheet, "B500", 31); // tmpfiregems doit(sheet, "5801", 90); // tmpairgems doit(sheet, "5901", 91); // tmpwatergems doit(sheet, "5A01", 92); // tmpearthgems doit(sheet, "5B01", 93); // tmpastralgems doit(sheet, "5C01", 94); // tmpdeathgems doit(sheet, "5D01", 95); // tmpnaturegems doit(sheet, "5E01", 96); // tmpbloodgems doit(sheet, "5F01", 97); // healer doit(sheet, "6201", 20); // supplybonus doit(sheet, "7A00", 117); // mapspeed doit(sheet, "A901", 33); // restricted stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); i = 0; int k = 0; Set<Integer> posSet = new HashSet<Integer>(); long numFound = 0; c = new byte[2]; stream.skip(120); while ((stream.read(c, 0, 2)) != -1) { String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); int weapon = Integer.decode("0X" + high + low); if (weapon == 0) { stream.skip(18l - numFound * 2l); int numRealms = 0; // Values for (int x = 0; x < numFound; x++) { byte[] d = new byte[4]; stream.read(d, 0, 4); String high1 = String.format("%02X", d[3]); String low1 = String.format("%02X", d[2]); high = String.format("%02X", d[1]); low = String.format("%02X", d[0]); //System.out.print(low + high + " "); if (posSet.contains(x)) { int fire = new BigInteger(high1 + low1 + high + low, 16).intValue();//Integer.decode("0X" + high + low); //System.out.print(i+1 + "\t" + fire); //System.out.println(""); XSSFRow row = sheet.getRow(i + 1); XSSFCell cell = row.getCell(142 + numRealms, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(fire - 100); numRealms++; } //stream.skip(2); } // System.out.println(""); stream.skip(206l - 18l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("1601")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); // Large bitmap for (String[] pair : DOTHESE) { columnsUsed.remove(Integer.parseInt(pair[1])); rowNumber = 1; boolean[] boolArray = largeBitmap(pair[0]); for (boolean found : boolArray) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(Integer.parseInt(pair[1]), Row.CREATE_NULL_AS_BLANK); if (found) { if (pair[0].equals("airshield")) { cell.setCellValue(80); } else { cell.setCellValue(1); } } else { cell.setCellValue(""); } } } stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.ITEM); i = 0; c = new byte[24]; stream.skip(184); while ((stream.read(c, 0, 24)) != -1) { boolean found = false; System.out.print("(" + (i + 1) + ") "); String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); //System.out.print(high + low + " "); int val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print("1:{"); for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value1[j].equals("") ? ("*****" + (j + 1) + "*****") : value1[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[3]); low = String.format("%02X", c[2]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 2:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value2[j].equals("") ? ("*****" + (j + 1) + "*****") : value2[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[5]); low = String.format("%02X", c[4]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 3:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value3[j].equals("") ? ("*****" + (j + 1) + "*****") : value3[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[7]); low = String.format("%02X", c[6]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 4:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value4[j].equals("") ? ("*****" + (j + 1) + "*****") : value4[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[9]); low = String.format("%02X", c[8]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 5:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value5[j].equals("") ? ("*****" + (j + 1) + "*****") : value5[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[11]); low = String.format("%02X", c[10]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 6:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value6[j].equals("") ? ("*****" + (j + 1) + "*****") : value6[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[13]); low = String.format("%02X", c[12]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 7:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value7[j].equals("") ? ("*****" + (j + 1) + "*****") : value7[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[15]); low = String.format("%02X", c[14]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 8:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value8[j].equals("") ? ("*****" + (j + 1) + "*****") : value8[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[17]); low = String.format("%02X", c[16]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 9:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value9[j].equals("") ? ("*****" + (j + 1) + "*****") : value9[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[19]); low = String.format("%02X", c[18]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 10:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value10[j].equals("") ? ("*****" + (j + 1) + "*****") : value10[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[21]); low = String.format("%02X", c[20]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 11:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value11[j].equals("") ? ("*****" + (j + 1) + "*****") : value11[j])); found = true; } } System.out.print("}"); } high = String.format("%02X", c[23]); low = String.format("%02X", c[22]); //System.out.print(high + low + " "); val = Integer.decode("0X" + high + low); if (val > 0) { System.out.print(" 12:{"); found = false; for (int j = 0; j < 16; j++) { if ((val & MASK[j]) != 0) { System.out.print((found ? "," : "") + (value12[j].equals("") ? ("*****" + (j + 1) + "*****") : value12[j])); found = true; } } System.out.print("}"); } if (!found) { //System.out.println(""); } System.out.println(" "); stream.skip(184l); i++; if (i >= Starts.ITEM_COUNT) { break; } } stream.close(); wb.write(fos); fos.close(); for (String col : columnsUsed.values()) { System.out.println(col); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:accounts.ExcelUtils.java
License:Apache License
public Map<String, Map<TRId, TR>> processAllSheets(String filename, Map<String, BankAccount> baMap, String accountName) throws IOException, DBException { Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>(); FileInputStream file = new FileInputStream(new File(filename)); // Get the workbook instance for XLS file XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); String sheetName = workbook.getSheetName(i); if ("RentalSummary".equalsIgnoreCase(sheetName) || "CompanySummary".equalsIgnoreCase(sheetName) || "PersonalSummary".equalsIgnoreCase(sheetName)) { continue; }/*from w w w .j a va2 s. com*/ if (accountName != null && !accountName.equalsIgnoreCase(sheetName)) { continue; } Map<TRId, TR> mapTr = new HashMap<>(); excelTrMap.put(sheetName, mapTr); System.out.println("Processing sheet: " + sheetName); BankAccount ba = baMap.get(sheetName); if (ba == null) { throw new IOException("Unknown bank account name in excel=" + sheetName); } for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) { Row row = sheet.getRow(rownum); // Get iterator to all cells of current row TR tr = DBFactory.inst().createCorrespondingTRObj(ba); tr.setDate(row.getCell(0).getDateCellValue()); tr.setDescription(row.getCell(1).getStringCellValue()); tr.setDebit((float) row.getCell(2).getNumericCellValue()); tr.setComment(row.getCell(3).getStringCellValue()); tr.setTrType(row.getCell(4).getStringCellValue()); tr.setTaxCategory(row.getCell(5).getStringCellValue()); tr.setProperty(row.getCell(6).getStringCellValue()); tr.setOtherEntity(row.getCell(7).getStringCellValue()); String locked = row.getCell(8).getStringCellValue(); tr.setLocked("YES".equalsIgnoreCase(locked)); tr.setTrId(); mapTr.put(tr.getTrId(), tr); } } return excelTrMap; }
From source file:accounts.ExcelUtils.java
License:Apache License
public Map<String, Map<TRId, TR>> processAllSheets(String filename) throws IOException { Map<String, Map<TRId, TR>> excelTrMap = new TreeMap<>(); FileInputStream file = new FileInputStream(new File(filename)); // Get the workbook instance for XLS file XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i = 0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); String sheetName = workbook.getSheetName(i); Map<TRId, TR> mapTr = new HashMap<>(); excelTrMap.put(sheetName, mapTr); System.out.println("Processing sheet: " + sheetName); // Get iterator to all the rows in current sheet Iterator<Row> rowIterator = sheet.iterator(); for (int rownum = 1; rownum <= sheet.getLastRowNum(); rownum++) { Row row = sheet.getRow(rownum); // Get iterator to all cells of current row TR tr = new TRNonDB(); tr.setDate(row.getCell(0).getDateCellValue()); tr.setDescription(row.getCell(1).getStringCellValue()); tr.setDebit((float) row.getCell(2).getNumericCellValue()); tr.setComment(row.getCell(3).getStringCellValue()); tr.setTrType(row.getCell(4).getStringCellValue()); tr.setTaxCategory(row.getCell(5).getStringCellValue()); tr.setProperty(row.getCell(6).getStringCellValue()); tr.setOtherEntity(row.getCell(7).getStringCellValue()); String lockedStr = row.getCell(7).getStringCellValue(); if ("YES".equalsIgnoreCase(lockedStr) || "TRUE".equalsIgnoreCase(lockedStr)) { tr.setLocked(true);/*from ww w . j a va 2 s. c om*/ } tr.setTrId(); mapTr.put(tr.getTrId(), tr); } } return excelTrMap; }
From source file:aco.Utilities.java
License:Open Source License
static void writeInputDataPoints() { //the file already exists if (new File(filePath3).canRead()) { //System.out.println("File already exists.."); try {// w w w . j a v a2 s . co m FileInputStream file = new FileInputStream(new File(filePath3)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(11); //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); Row r1 = sheet1.getRow(0); if (r1 == null) { // First cell in the row, create r1 = sheet1.createRow(0); } Cell c = r1.getCell(0); if (c == null) { c = r1.createCell(0); } c.setCellValue("VRPTW instance - " + VRPTW.instance.name + "; data point coordinates corresponding to customers' requests"); c.setCellStyle(style); Row r = sheet1.getRow(2); if (r == null) { // First cell in the row, create r = sheet1.createRow(2); } Cell c1 = r.getCell(0); if (c1 == null) { c1 = r.createCell(0); } c1.setCellValue("Point #"); c1.setCellStyle(style); c1 = r.getCell(1); if (c1 == null) { c1 = r.createCell(1); } c1.setCellValue("X Coord"); c1.setCellStyle(style); c1 = r.getCell(2); if (c1 == null) { c1 = r.createCell(2); } c1.setCellValue("Y Coord"); c1.setCellStyle(style); int size = VRPTW.instance.nodes.length; int rowIndex = 3; double x, y; for (int i = 0; i < size; i++) { x = VRPTW.instance.nodes[i].x; y = VRPTW.instance.nodes[i].y; r = sheet1.getRow(rowIndex + i); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(rowIndex + i); } c1 = r.getCell(0); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(0); } c1.setCellValue(i); c1 = r.getCell(1); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(1); } c1.setCellValue(x); c1 = r.getCell(2); if (c1 == null) { // New cell //System.out.println("Empty cell, create new one"); c1 = r.createCell(2); } c1.setCellValue(y); } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath3)); workbook1.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println("File not exists.."); } }
From source file:aco.Utilities.java
License:Open Source License
static void writeExcel(int n, int m, int result) { //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath).canRead()) { //System.out.println("File already exists.."); try {/*from www. j ava 2s. c om*/ FileInputStream file = new FileInputStream(new File(filePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(2); int countRows = sheet1.getLastRowNum() + 1; Row newRow = sheet1.createRow(countRows++); int cellnum = 0; Cell cell = newRow.createCell(cellnum++); cell.setCellValue(n); cell = newRow.createCell(cellnum++); cell.setCellValue(m); cell = newRow.createCell(cellnum++); cell.setCellValue(result); //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook1.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook XSSFWorkbook workbook2 = new XSSFWorkbook(); //Create a blank sheet XSSFSheet sheet2 = workbook2.createSheet("Results - 51 cities"); //Iterate over data and write to sheet int rownum = 0, cellnum = 0; Row row = sheet2.createRow(rownum++); Cell cell = row.createCell(cellnum++); cell.setCellValue(n); cell = row.createCell(cellnum++); cell.setCellValue(m); cell = row.createCell(cellnum++); cell.setCellValue(result); try { //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook2.write(out); out.close(); //System.out.println("Written successfully on disk."); } catch (Exception e) { e.printStackTrace(); } } }
From source file:aco.Utilities.java
License:Open Source License
static void writeResultsExcel(int trialNumber, boolean saveIterCosts) { Row r, r1;/*from ww w.ja v a2s . c o m*/ Cell c; int index1 = 0, index2 = 0, index3 = 0, index4 = 0, index5 = 0; //int index6 = 0; //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath).canRead()) { //System.out.println("File already exists.."); try { FileInputStream file = new FileInputStream(new File(filePath)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); int startIndex = 0, rowIndex = 0; /*switch (VRPTW.m) { case 2: startIndex = 0; rowIndex = 4; break; case 3: startIndex = 2; rowIndex = 5; break; case 5: startIndex = 4; rowIndex = 7; break; case 7: startIndex = 6; rowIndex = 9; break; default: System.out.println("Unknown value for m"); break; }*/ //Get desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(startIndex); //for tours /*XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for number of assigned cities XSSFSheet sheet3 = workbook1.getSheetAt(startIndex + 2); //for cost of individual subtours XSSFSheet sheet4 = workbook1.getSheetAt(startIndex + 3); //for total cost of subtours XSSFSheet sheet5 = workbook1.getSheetAt(startIndex + 4); //for verbose output of total cost at each 5 iteration */ XSSFSheet sheet2 = workbook1.getSheetAt(startIndex + 1); //for verbose output of longest cost at each 5 iteration //define a cell style for bold font CellStyle style = workbook1.createCellStyle(); Font font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); style.setFont(font); //define style with bold font and blue color for font CellStyle styleBoldBlue = workbook1.createCellStyle(); font = workbook1.createFont(); font.setBoldweight(Font.BOLDWEIGHT_BOLD); font.setColor(IndexedColors.BLUE.index); styleBoldBlue.setFont(font); index1 = 133; if (!saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Obtained solutions (values) after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); } //write only once the table header index1 = index1 + 3; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Run #"); c.setCellStyle(style); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue("MinMax (cost of longest subtour)"); c.setCellStyle(style); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue("Total Cost"); c.setCellStyle(style); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue("Amplitude"); c.setCellStyle(style); //write number of run index1 = 137 + trialNumber; r = sheet1.getRow(index1); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet1.createRow(index1); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue(trialNumber + 1); //write MinMax (cost of longest subtour) double longestSubtour = getLongestSubtour(); c = r.getCell(1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(1); } c.setCellValue(longestSubtour); //write total cost double totalCost = getTotalCost(); c = r.getCell(2); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(2); } c.setCellValue(totalCost); //write amplitude double amplitude = getAmplitude(); c = r.getCell(3); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(3); } c.setCellValue(amplitude); } index5 = 859; if (saveIterCosts) { //write only once the name of the algorithm that was run if (trialNumber == 0) { r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue( "Longest cost of subtour at each 5 iteration after running new version (ACS MinMax global, voiajor si oras alesi simultan) with local search"); c.setCellStyle(styleBoldBlue); int tempIndex = index5 + 3; r = sheet2.getRow(tempIndex); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(tempIndex); } ArrayList<Integer> iterNumber = getIterNumber(); c = r.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(0); } c.setCellValue("Nr Iter"); c.setCellStyle(style); int indexTemp = 0; for (int j = 0; j < iterNumber.size(); j++) { indexTemp = tempIndex + 1 + j; r1 = sheet2.getRow(indexTemp); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(indexTemp); } c = r1.getCell(0); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(0); } c.setCellValue(iterNumber.get(j)); } } index5 = index5 + 3; r = sheet2.getRow(index5); if (r == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r = sheet2.createRow(index5); } //for each trial run save at each 5 iteration the best longest cost of a subtour so far ArrayList<Double> iterLongestCost = getIterLongestCost(); int index; //for each run write the table header cell c = r.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r.createCell(trialNumber + 1); } c.setCellValue("Run " + (trialNumber + 1)); c.setCellStyle(style); for (int j = 0; j < iterLongestCost.size(); j++) { index = index5 + 1 + j; r1 = sheet2.getRow(index); if (r1 == null) { // First cell in the row, create //System.out.println("Empty row, create new one"); r1 = sheet2.createRow(index); } c = r1.getCell(trialNumber + 1); if (c == null) { // New cell //System.out.println("Empty cell, create new one"); c = r1.createCell(trialNumber + 1); } c.setCellValue(iterLongestCost.get(j)); } } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath)); workbook1.write(out); out.close(); int nrOfRun = trialNumber + 1; System.out.println("\nRun #" + nrOfRun + " written successfully on disk.\n"); } catch (Exception e) { e.printStackTrace(); } } else { //Blank workbook System.out.println("File " + filePath + " doesn't exists.."); } }
From source file:aco.Utilities.java
License:Open Source License
static void writeParetoSet(ArrayList<Ant> bestSoFarPareto, int trial) { Row r;/*from ww w.j a v a 2s .com*/ Cell c; int lineNumber = 0; //filePath1 += InOut.max_iterations + " iter (ACO MinMax_vers noua).xlsx"; //System.out.println("file path=" + filePath1); //the file already exists; we should add a new row as the last one in the Excel file if (new File(filePath1).canRead()) { //System.out.println("File already exists.."); try { FileInputStream file = new FileInputStream(new File(filePath1)); //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook1 = new XSSFWorkbook(file); //Get first/desired sheet from the workbook XSSFSheet sheet1 = workbook1.getSheetAt(trial); //write table header cells r = sheet1.getRow(lineNumber); if (r == null) { // First cell in the row, create r = sheet1.createRow(lineNumber); } c = r.getCell(0); if (c == null) { // New cell c = r.createCell(0); } c.setCellValue("Point #"); c = r.getCell(1); if (c == null) { // New cell c = r.createCell(1); } c.setCellValue("Total tours length"); c = r.getCell(2); if (c == null) { // New cell c = r.createCell(2); } c.setCellValue("Amplitude of tours"); c = r.getCell(3); if (c == null) { // New cell c = r.createCell(3); } c.setCellValue("List with cost of subtours"); lineNumber++; for (int i = 0; i < bestSoFarPareto.size(); i++) { r = sheet1.getRow(i + lineNumber); if (r == null) { // First cell in the row, create r = sheet1.createRow(i + lineNumber); } //write point id c = r.getCell(0); if (c == null) { // New cell c = r.createCell(0, Cell.CELL_TYPE_NUMERIC); } c.setCellValue(i + 1); //write total cost and amplitude for (int indexObj = 0; indexObj < 2; indexObj++) { c = r.getCell(indexObj + 1); if (c == null) { // New cell c = r.createCell(indexObj + 1, Cell.CELL_TYPE_NUMERIC); } c.setCellValue(bestSoFarPareto.get(i).costObjectives[indexObj]); } //write cost of each individual subtour for (int j = 0; j < bestSoFarPareto.get(i).tour_lengths.size(); j++) { c = r.getCell(j + 3); if (c == null) { // New cell c = r.createCell(j + 3); } c.setCellValue(bestSoFarPareto.get(i).tour_lengths.get(j)); } } //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File(filePath1)); workbook1.write(out); out.close(); //System.out.println("\nWritten Pareto front points successfully on disk.\n"); int nrOfRun = trial + 1; System.out.println("\nRun #" + nrOfRun + " written Pareto front points successfully on disk.\n"); } catch (Exception e) { e.printStackTrace(); } } else { System.out.println(" File " + filePath1 + " doesn't exists"); } }