List of usage examples for org.apache.poi.xssf.usermodel XSSFCell setCellValue
@Override public void setCellValue(boolean value)
From source file:StatusUpdater.java
static boolean updateStatus(String path, String username, String task, int optionChosen) { File myFile = new File(path); FileInputStream fis = null;/*from w ww . j ava2 s . co m*/ try { fis = new FileInputStream(myFile); } catch (FileNotFoundException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(fis); } catch (IOException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } XSSFSheet sheet = workbook.getSheetAt(0); if (sheet == null) { return false; } Iterator ite1 = sheet.rowIterator(); if (ite1 == null) { return false; } XSSFRow myRow = null; DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); df.format(dateobj); if (ite1.hasNext()) { ite1.next(); } while (ite1.hasNext()) { myRow = (XSSFRow) ite1.next(); XSSFCell usernameCell = myRow.getCell(0); String sheet_userid = null; if (usernameCell.getStringCellValue() != null) { sheet_userid = usernameCell.getStringCellValue(); } else { return false; } System.out.println("sheet_userid=" + sheet_userid); XSSFCell taskCell = myRow.getCell(1); if (taskCell == null) { return false; } String sheet_task = taskCell.getStringCellValue(); System.out.println("sheet_task=" + sheet_task); if (sheet_task == null) { return false; } if (sheet_userid.equals(username) && sheet_task.equals(task)) { break; } } if (optionChosen == 1) { //Resume is pressed. XSSFCell statusCell = myRow.getCell(2); String status = null; if (statusCell != null) { status = statusCell.getStringCellValue(); if (status.equalsIgnoreCase("Paused") || status.equalsIgnoreCase("Deferred")) { XSSFCell timestampCell = myRow.getCell(3); timestampCell.setCellValue(df.format(dateobj)); XSSFCell status_cell = myRow.getCell(2); status_cell.setCellValue("In-Progress"); } else if (status.equalsIgnoreCase("In-Progress")) //trying to Resume an in-progress task. { return true; } else { //trying to resume a finished task or invalid status task. return false; } } else { return false; } } else if (optionChosen == 2) { //Pause is pressed XSSFCell statusCell = myRow.getCell(2); if (statusCell != null) { String status = statusCell.getStringCellValue(); if (status != null) { if (status.equalsIgnoreCase("Paused")) return true; else if (status.equalsIgnoreCase("In-Progress")) { XSSFCell timestampCell = myRow.getCell(3); String dateInString = timestampCell.getStringCellValue(); Date date_obj = null; try { date_obj = df.parse(dateInString); } catch (ParseException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("date value of sheet in pause button=" + dateobj.toString()); Date obj = new Date(); df.format(obj); long diff = date_obj.getTime() - obj.getTime(); long divisor = 60 * 60 * 1000; double diffHours = ((double) diff / (double) divisor); //XSSFCell cell2=myRow.getCell(4); XSSFCell totalTimeCell = null; if (myRow.getCell(4) == null) { totalTimeCell = myRow.createCell(4); totalTimeCell.setCellValue(Double.toString(diffHours)); } else { totalTimeCell = myRow.getCell(4); double timeSpent = Double.parseDouble(totalTimeCell.getStringCellValue()); timeSpent += diffHours; totalTimeCell.setCellValue(String.valueOf(timeSpent)); } statusCell.setCellValue("Paused"); } else if (status.equalsIgnoreCase("Deferred")) { statusCell.setCellValue("Paused"); } else return false; } else return false; } else { return false; } } else if (optionChosen == 3) { //Stop is pressed XSSFCell statusCell = myRow.getCell(2); if (statusCell != null) { String status = statusCell.getStringCellValue(); if (status != null) { if (status.equalsIgnoreCase("Paused")) return true; else if (status.equalsIgnoreCase("In-Progress")) { XSSFCell timestampCell = myRow.getCell(3); String dateInString = timestampCell.getStringCellValue(); Date date_obj = null; try { date_obj = df.parse(dateInString); } catch (ParseException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("date value of sheet in pause button=" + dateobj.toString()); Date obj = new Date(); df.format(obj); long diff = date_obj.getTime() - obj.getTime(); long divisor = 60 * 60 * 1000; double diffHours = ((double) diff / (double) divisor); XSSFCell totalTimeCell = null; if (myRow.getCell(4) == null) { totalTimeCell = myRow.createCell(4); totalTimeCell.setCellValue(Double.toString(diffHours)); } else { totalTimeCell = myRow.getCell(4); double timeSpent = Double.parseDouble(totalTimeCell.getStringCellValue()); timeSpent += diffHours; totalTimeCell.setCellValue(String.valueOf(timeSpent)); } statusCell.setCellValue("Deferred"); } else if (status.equalsIgnoreCase("Paused")) { statusCell.setCellValue("Deferred"); } else { return false; } } else { return false; } } else { return false; } } else if (optionChosen == 4) { XSSFCell status_cell = myRow.getCell(2); if (status_cell.getStringCellValue() == "In-Progress") //logic to calculate the time taken if the task was in-process so far { XSSFCell timestampCell = myRow.getCell(3); String dateInString = timestampCell.getStringCellValue(); Date date_obj = null; try { date_obj = df.parse(dateInString); } catch (ParseException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } Date obj = new Date(); df.format(obj); long fv = date_obj.getTime(); long sv = obj.getTime(); long diff = sv - fv; long divisor = 60 * 60 * 1000; double diffHours = ((double) diff / (double) divisor); XSSFCell cell2 = null; if (myRow.getCell(4) == null) { cell2 = myRow.createCell(4); cell2.setCellValue(Double.toString(diffHours)); } else { cell2 = myRow.getCell(4); double timeSpent = Double.parseDouble(cell2.getStringCellValue()); timeSpent += diffHours; cell2.setCellValue(String.valueOf(timeSpent)); } } status_cell.setCellValue("Completed"); } else { System.out.println("Invalid value for optionChosen"); } try { fis.close(); } catch (IOException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Debug one"); FileOutputStream fileOut = null; try { fileOut = new FileOutputStream(myFile); } catch (FileNotFoundException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Debug two"); try { workbook.write(fileOut); } catch (IOException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } try { fileOut.close(); } catch (IOException ex) { Logger.getLogger(StatusUpdater.class.getName()).log(Level.SEVERE, null, ex); } return true; }
From source file:Viewsale.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet();/*w w w . ja v a 2 s.co m*/ TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6), dm.getColumnName(7), dm.getColumnName(8), dm.getColumnName(9), dm.getColumnName(10), dm.getColumnName(11), dm.getColumnName(12), dm.getColumnName(13), dm.getColumnName(14), dm.getColumnName(15) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6), getCellValue(i, 7), getCellValue(i, 8), getCellValue(i, 9), getCellValue(i, 10), getCellValue(i, 11), getCellValue(i, 12), getCellValue(i, 13), getCellValue(i, 14), getCellValue(i, 15) }); } Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/saleview.xlsx")); wb.write(fos); fos.close(); }
From source file:CreateTable.java
License:Apache License
public static void main(String[] args) throws FileNotFoundException, IOException { Workbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) wb.createSheet(); //Create //from w w w . j a v a2s. co m XSSFTable table = sheet.createTable(); table.setDisplayName("Test"); CTTable cttable = table.getCTTable(); //Style configurations CTTableStyleInfo style = cttable.addNewTableStyleInfo(); style.setName("TableStyleMedium2"); style.setShowColumnStripes(false); style.setShowRowStripes(true); //Set which area the table should be placed in AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(3, 3)); cttable.setRef(reference.formatAsString()); cttable.setId(1); cttable.setName("Test"); cttable.setTotalsRowCount(1); CTTableColumns columns = cttable.addNewTableColumns(); columns.setCount(3); CTTableColumn column; XSSFRow row; XSSFCell cell; for (int i = 0; i < 3; i++) { //Create column column = columns.addNewTableColumn(); column.setName("Column"); column.setId(i + 1); //Create row row = sheet.createRow(i); for (int j = 0; j < 3; j++) { //Create cell cell = row.createCell(j); if (i == 0) { cell.setCellValue("Column" + j); } else { cell.setCellValue(i + j + 0.0); } } } FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:spareexcel.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet();/*from www .j a v a2 s .c o m*/ TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6) }); } Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/sparexcel.xlsx")); wb.write(fos); fos.close(); }
From source file:SiteStatIndexer.java
License:Open Source License
public static void doit2(XSSFSheet sheet, String attr, int column, int column2) throws IOException { FileInputStream stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE);/* ww w . j a v a 2 s.c o m*/ int rowNumber = 1; int i = 0; int k = 0; int numFound = 0; Set<Integer> posSet = new HashSet<Integer>(); byte[] c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { if (ind == 0) { XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); } else { XSSFCell cell = row.getCell(column2, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); } ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals(attr)) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); }
From source file:SiteStatIndexer.java
License:Open Source License
public static void doit(XSSFSheet sheet, String attr, int column, Callback callback) throws IOException { FileInputStream stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE);/*from w ww.j a v a 2s .c o m*/ int rowNumber = 1; int i = 0; int k = 0; int pos = -1; long numFound = 0; byte[] c = new byte[2]; stream.skip(42); 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) { boolean found = false; int value = 0; stream.skip(32l - numFound * 2l); // Values for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); //System.out.print(low + high + " "); if (x == pos) { int tmp = new BigInteger(high + low, 16).intValue(); if (tmp < 1000) { value = Integer.decode("0X" + high + low); } else { value = new BigInteger("FFFF" + high + low, 16).intValue(); } //System.out.print(fire); found = true; } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK); if (found) { if (callback == null) { cell.setCellValue(value); } else { cell.setCellValue(callback.found(Integer.toString(value))); } } else { if (callback == null) { cell.setCellValue(""); } else { cell.setCellValue(callback.notFound()); } } stream.skip(142l - 32l - numFound * 4l); numFound = 0; pos = -1; k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals(attr)) { pos = k; } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); }
From source file:SiteStatIndexer.java
License:Open Source License
public static void run() { FileInputStream stream = null; try {// w w w . j av a 2s .c o m long startIndex = Starts.SITE; int ch; stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); XSSFWorkbook wb = SiteStatIndexer.readFile("MagicSites.xlsx"); FileOutputStream fos = new FileOutputStream("NewMagicSites.xlsx"); XSSFSheet sheet = wb.getSheetAt(0); // 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 + 144l; 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.SITE); rowNumber = 1; // rarity int i = 0; byte[] c = new byte[1]; stream.skip(40); while ((stream.read(c, 0, 1)) != -1) { XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(2, Row.CREATE_NULL_AS_BLANK); if (c[0] == -1 || c[0] == 0) { //System.out.println("0"); cell.setCellValue("0"); } else { //System.out.println(c[0]); cell.setCellValue(c[0]); } stream.skip(143l); i++; if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // loc i = 0; c = new byte[2]; stream.skip(140); 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(3, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(Integer.decode("0X" + high + low)); stream.skip(142l); i++; if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // level i = 0; c = new byte[1]; stream.skip(38); while ((stream.read(c, 0, 1)) != -1) { String high = String.format("%02X", c[0]); //System.out.println(Integer.decode("0X" + high)); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(4, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(Integer.decode("0X" + high)); stream.skip(143l); i++; if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // path String[] paths = { "Fire", "Air", "Water", "Earth", "Astral", "Death", "Nature", "Blood", "Holy" }; i = 0; c = new byte[1]; stream.skip(36); 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(paths[c[0]]); cell.setCellValue(paths[c[0]]); } stream.skip(143l); i++; if (i >= Starts.SITE_COUNT) { break; } } stream.close(); // F doit2(sheet, "0100", 6, 92); // A doit2(sheet, "0200", 7, 93); // W doit2(sheet, "0300", 8, 94); // E doit2(sheet, "0400", 9, 95); // S doit2(sheet, "0500", 10, 96); // D doit2(sheet, "0600", 11, 97); // N doit2(sheet, "0700", 12, 98); // B doit2(sheet, "0800", 13, 99); // gold doit(sheet, "0D00", 14); // res doit(sheet, "0E00", 15); // sup doit(sheet, "1400", 16); // unr doit(sheet, "1300", 17, new CallbackAdapter() { @Override public String found(String value) { return Integer.toString(-Integer.parseInt(value)); } }); // exp doit(sheet, "1600", 18); // lab doit(sheet, "0F00", 19, new CallbackAdapter() { @Override public String found(String value) { return "lab"; } }); // fort doit(sheet, "1100", 20); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // scales String[] scales = { "Turmoil", "Sloth", "Cold", "Death", "Misfortune", "Drain" }; String[] opposite = { "Order", "Productivity", "Heat", "Growth", "Luck", "Magic" }; i = 0; int k = 0; Set<Integer> scalesSet = new HashSet<Integer>(); Set<Integer> oppositeSet = new HashSet<Integer>(); long numFound = 0; c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; String value[] = { "", "" }; int index = 0; for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); //System.out.print(low + high + " "); if (oppositeSet.contains(x)) { //int fire = Integer.decode("0X" + high + low); int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(opposite[fire]); value[index++] = opposite[fire]; } if (scalesSet.contains(x)) { //int fire = Integer.decode("0X" + high + low); int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(scales[fire]); value[index++] = scales[fire]; } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; if (value[0].length() > 0) { XSSFCell cell = row.getCell(21, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(value[0]); } if (value[1].length() > 0) { XSSFCell cell = row.getCell(22, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(value[1]); } stream.skip(142l - 32l - numFound * 4l); numFound = 0; scalesSet.clear(); oppositeSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("1F00")) { oppositeSet.add(k); } if ((low + high).equals("2000")) { scalesSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // rit/ritr i = 0; k = 0; String rit = ""; numFound = 0; int pos = -1; c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); boolean found = false; int value = 0; // Values for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); //System.out.print(low + high + " "); if (x == pos) { //int fire = Integer.decode("0X" + high + low); //int fire = new BigInteger(new byte[]{c[1], c[0]}).intValue(); //System.out.print(rit + "\t" + fire); found = true; value = new BigInteger(new byte[] { c[1], c[0] }).intValue(); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell1 = row.getCell(41, Row.CREATE_NULL_AS_BLANK); XSSFCell cell2 = row.getCell(42, Row.CREATE_NULL_AS_BLANK); if (found) { cell1.setCellValue(rit); cell2.setCellValue(value); } else { cell1.setCellValue(""); cell2.setCellValue(""); } stream.skip(142l - 32l - numFound * 4l); numFound = 0; pos = -1; rit = ""; k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("FA00")) { rit += "F"; pos = k; } if ((low + high).equals("FB00")) { rit += "A"; pos = k; } if ((low + high).equals("FC00")) { rit += "W"; pos = k; } if ((low + high).equals("FD00")) { rit += "E"; pos = k; } if ((low + high).equals("FE00")) { rit += "S"; pos = k; } if ((low + high).equals("FF00")) { rit += "D"; pos = k; } if ((low + high).equals("0001")) { rit += "N"; pos = k; } if ((low + high).equals("0101")) { rit += "B"; pos = k; } if ((low + high).equals("0401")) { rit += "*"; pos = k; } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // hmon i = 0; k = 0; numFound = 0; Set<Integer> posSet = new HashSet<Integer>(); c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { XSSFCell cell = row.getCell(43 + ind, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("1D00")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // hcom i = 0; k = 0; numFound = 0; posSet = new HashSet<Integer>(); c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { XSSFCell cell = row.getCell(73 + ind, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("1E00")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // mon i = 0; k = 0; numFound = 0; posSet = new HashSet<Integer>(); c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { XSSFCell cell = row.getCell(78 + ind, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("0B00")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // com i = 0; k = 0; numFound = 0; posSet = new HashSet<Integer>(); c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { XSSFCell cell = row.getCell(83 + ind, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("0C00")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // provdef i = 0; k = 0; numFound = 0; posSet = new HashSet<Integer>(); c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values boolean found = false; List<Integer> values = new ArrayList<Integer>(); for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (!found) { found = true; } else { //System.out.print("\t"); } //System.out.print(fire); values.add(fire); } stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; int ind = 0; for (Integer mon : values) { XSSFCell cell = row.getCell(89 + ind, Row.CREATE_NULL_AS_BLANK); cell.setCellValue(mon); ind++; } stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("E000")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); // conj doit(sheet, "3C00", 55, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // alter doit(sheet, "3D00", 56, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // evo doit(sheet, "3E00", 57, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // const doit(sheet, "3F00", 58, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // ench doit(sheet, "4000", 59, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // thau doit(sheet, "4100", 60, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // blood doit(sheet, "4200", 61, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // heal doit(sheet, "4600", 62, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // disease doit(sheet, "1500", 63, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // curse doit(sheet, "4700", 64, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // horror doit(sheet, "1800", 65, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // holyfire doit(sheet, "4400", 66, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // holypower doit(sheet, "4300", 67, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); // scry doit(sheet, "4800", 68); // adventure doit(sheet, "C000", 69); // voidgate doit(sheet, "3900", 48, new CallbackAdapter() { @Override public String found(String value) { return value + "%"; } }); stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.SITE); rowNumber = 1; // summoning i = 0; k = 0; posSet = new HashSet<Integer>(); int sum1 = 0; int sum1count = 0; int sum2 = 0; int sum2count = 0; int sum3 = 0; int sum3count = 0; int sum4 = 0; int sum4count = 0; numFound = 0; c = new byte[2]; stream.skip(42); 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(32l - numFound * 2l); // Values for (int x = 0; x < numFound; x++) { stream.read(c, 0, 2); high = String.format("%02X", c[1]); low = String.format("%02X", c[0]); if (posSet.contains(x)) { int fire = new BigInteger(new byte[] { c[1], c[0] }).intValue(); if (sum1 == 0 || sum1 == fire) { sum1 = fire; sum1count++; } else if (sum2 == 0 || sum2 == fire) { sum2 = fire; sum2count++; } else if (sum3 == 0 || sum3 == fire) { sum3 = fire; sum3count++; } else if (sum4 == 0 || sum4 == fire) { sum4 = fire; sum4count++; } } stream.skip(2); } XSSFRow row = sheet.getRow(rowNumber); rowNumber++; //String sum = ""; if (sum1 > 0) { //sum += sum1 + "\t" + sum1count; XSSFCell cell1 = row.getCell(49, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(sum1); XSSFCell cell2 = row.getCell(50, Row.CREATE_NULL_AS_BLANK); cell2.setCellValue(sum1count); } if (sum2 > 0) { //sum += "\t" + sum2 + "\t" + sum2count; XSSFCell cell1 = row.getCell(51, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(sum2); XSSFCell cell2 = row.getCell(52, Row.CREATE_NULL_AS_BLANK); cell2.setCellValue(sum2count); } if (sum3 > 0) { //sum += "\t" + sum3 + "\t" + sum3count; XSSFCell cell1 = row.getCell(53, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(sum3); XSSFCell cell2 = row.getCell(54, Row.CREATE_NULL_AS_BLANK); cell2.setCellValue(sum3count); } if (sum4 > 0) { //sum += "\t" + sum3 + "\t" + sum3count; XSSFCell cell1 = row.getCell(71, Row.CREATE_NULL_AS_BLANK); cell1.setCellValue(sum4); XSSFCell cell2 = row.getCell(72, Row.CREATE_NULL_AS_BLANK); cell2.setCellValue(sum4count); } //System.out.println(sum); stream.skip(142l - 32l - numFound * 4l); numFound = 0; posSet.clear(); k = 0; sum1 = 0; sum1count = 0; sum2 = 0; sum2count = 0; sum3 = 0; sum3count = 0; sum4 = 0; sum4count = 0; i++; } else { //System.out.print(low + high + " "); if ((low + high).equals("1200")) { posSet.add(k); } k++; numFound++; } if (i >= Starts.SITE_COUNT) { break; } } stream.close(); // domspread doit(sheet, "1501", 23); // turmoil/order doit(sheet, "1901", 24); // sloth/prod doit(sheet, "1A01", 25); // cold/heat doit(sheet, "1B01", 26); // death/growth doit(sheet, "1C01", 27); // misfortune/luck doit(sheet, "1D01", 28); // drain/magic doit(sheet, "1E01", 29); // fire resistence doit(sheet, "FB01", 30); // cold resistence doit(sheet, "FC01", 31); // str doit(sheet, "FA01", 34); // prec doit(sheet, "0402", 35); // mor doit(sheet, "F401", 36); // shock resistence doit(sheet, "FD01", 32); // undying doit(sheet, "F801", 37); // att doit(sheet, "F501", 38); // poison resistence doit(sheet, "FE01", 33); // darkvision doit(sheet, "0302", 39); // animal awe doit(sheet, "0102", 40); // reveal doit(sheet, "0601", 88); // def doit(sheet, "F601", 91); // awe doit(sheet, "0202", 100); // reinvigoration doit(sheet, "FF01", 101); // airshield doit(sheet, "0002", 102); // provdefcom doit(sheet, "4A00", 103); wb.write(fos); fos.close(); } 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:Viewservice.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet();//from w ww . j ava 2s. co m TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6), dm.getColumnName(7), dm.getColumnName(8), dm.getColumnName(9), dm.getColumnName(10), dm.getColumnName(11), dm.getColumnName(12), dm.getColumnName(13), dm.getColumnName(14), dm.getColumnName(15), dm.getColumnName(16), dm.getColumnName(17), dm.getColumnName(18) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6), getCellValue(i, 7), getCellValue(i, 8), getCellValue(i, 9), getCellValue(i, 10), getCellValue(i, 11), getCellValue(i, 12), getCellValue(i, 13), getCellValue(i, 14), getCellValue(i, 15), getCellValue(i, 16), getCellValue(i, 17), getCellValue(i, 18) }); } Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/serviceview.xlsx")); wb.write(fos); fos.close(); }
From source file:MonsterStatIndexer.java
License:Open Source License
private static void doit1(int skip, int column, XSSFSheet sheet, Callback callback) throws IOException { columnsUsed.remove(column);/*w w w.j a v a 2s. c om*/ FileInputStream stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER); int rowNumber = 1; int i = 0; byte[] c = new byte[2]; stream.skip(skip); while ((stream.read(c, 0, 2)) != -1) { String high = String.format("%02X", c[1]); String low = String.format("%02X", c[0]); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK); int value = Integer.decode("0X" + high + low); if (callback != null) { cell.setCellValue(callback.found(Integer.toString(value))); } else { cell.setCellValue(Integer.decode("0X" + high + low)); } stream.skip(254l); i++; if (i >= Starts.MONSTER_COUNT) { break; } } stream.close(); }
From source file:MonsterStatIndexer.java
License:Open Source License
private static void doit2(XSSFSheet sheet, String attr, int column, Callback callback, boolean append) throws IOException { columnsUsed.remove(column);/* w ww . j ava 2 s . c om*/ FileInputStream stream = new FileInputStream("Dominions4.exe"); stream.skip(Starts.MONSTER); int rowNumber = 1; int i = 0; int k = 0; int pos = -1; long numFound = 0; byte[] 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) { boolean found = false; int value = 0; stream.skip(46l - numFound * 2l); // 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 (x == pos) { value = new BigInteger(high1 + low1 + high + low, 16).intValue(); //System.out.print(fire); found = true; } //stream.skip(2); } //System.out.println(""); XSSFRow row = sheet.getRow(rowNumber); rowNumber++; XSSFCell cell = row.getCell(column, Row.CREATE_NULL_AS_BLANK); if (found) { if (callback == null) { if (append) { String origVal = cell.getStringCellValue(); cell.setCellValue(origVal + value); } else { cell.setCellValue(value); } } else { if (append) { String origVal = cell.getStringCellValue(); if (callback.found(Integer.toString(value)) != null) { cell.setCellValue(origVal + callback.found(Integer.toString(value))); } } else { if (callback.found(Integer.toString(value)) != null) { cell.setCellValue(callback.found(Integer.toString(value))); } } } } else { if (callback == null) { cell.setCellValue(""); } else { if (callback.notFound() != null) { cell.setCellValue(callback.notFound()); } } } stream.skip(254l - 46l - numFound * 4l); numFound = 0; pos = -1; k = 0; i++; } else { //System.out.print(low + high + " "); if (attr.indexOf(low + high) != -1) { if (pos == -1) { pos = k; } } k++; numFound++; } if (i >= Starts.MONSTER_COUNT) { break; } } stream.close(); }