Search in sources :

Example 51 with XSSFRow

use of org.apache.poi.xssf.usermodel.XSSFRow in project financial by greatkendy123.

the class ExcelReaderUtil method readZJRecord_NewVersion.

/**
 * 导入战绩Excel
 *
 * 两个功能:
 * 	A:导入到场次信息
 * 	B:导入到联盟Tab
 *
 * @param file 文件夹
 * @return
 */
public static Wrap readZJRecord_NewVersion(File file, String userClubId, String LMType) {
    // 新增了联盟类型
    List<UserInfos> userInfoList = new LinkedList<>();
    UserInfos info = null;
    FileInputStream is = null;
    // 是否已经判断过为空 波哥要求添加
    boolean isHasJudged = false;
    try {
        // 桌号
        String name = file.getName();
        String tableId = name.substring(name.lastIndexOf("-") + 1, name.lastIndexOf("."));
        tableId = "第" + tableId + "局";
        if (StringUtil.isBlank(userClubId) || DataConstans.Index_Table_Id_Map.containsValue(tableId)) {
            return new Wrap(false, "该战绩表(" + tableId + "场次)已经导过");
        }
        log.info("开始----------导入战绩Excel");
        userInfoList = new LinkedList<>();
        is = new FileInputStream(file);
        // 获取excel sheet
        Workbook workbook = (XSSFWorkbook) getWeebWork(file.getAbsolutePath());
        XSSFSheet sheet = (XSSFSheet) workbook.getSheetAt(0);
        // 若无数据,要提示
        int rowNum = sheet.getLastRowNum();
        if (rowNum == 0 && !isHasJudged) {
            isHasJudged = true;
            ShowUtil.show("提示:总手数为0!");
        }
        // 开始遍历Excel行数据
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            XSSFRow row = (XSSFRow) rowIterator.next();
            // add 总手数为空的提示
            // Cell ZSScell = row.getCell(6);
            XSSFCell ZSScell = row.getCell(7);
            if (ZSScell == null) {
                continue;
            }
            // 总手数
            String totalHandCount = ZSScell.toString();
            Integer _tempCount = 0;
            if (!"总手数".equals(totalHandCount)) {
                try {
                    _tempCount = Integer.valueOf(totalHandCount);
                    if (_tempCount == 0) {
                        if (!isHasJudged) {
                            isHasJudged = true;
                            ShowUtil.show("提示:总手数为0!");
                        }
                    }
                } catch (Exception e) {
                    _tempCount = 1;
                }
            }
            info = new UserInfos();
            // 排除第一行以及俱乐部ID不匹配的情况
            // String clubID = row.getCell(9).toString();
            String clubID = row.getCell(10).toString();
            if (row.getRowNum() != 0 && userClubId.equals(row.getCell(10).toString())) {
                // 对于符合条件的进行存储
                // int[] clumns = new int[]{6,7,8,9, 10,15,17,18,19};
                int[] clumns = new int[] { 7, 8, 9, 10, 11, 16, 18, 19, 20 };
                for (int cn : clumns) {
                    XSSFCell cell = row.getCell(cn);
                    if (cell == null) {
                        log.error("出现空值,导入战绩文件夹失败" + "\t");
                        return new Wrap();
                    }
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    String value = cell.getStringCellValue();
                    value = StringUtil.isBlank(value) ? "" : value.trim();
                    switch(cn) {
                        case // add 总手数(只判断不导入)
                        7:
                            if ((StringUtil.isBlank(value) || "0".equals(value)) && !isHasJudged) {
                                isHasJudged = true;
                                ShowUtil.show("提示:总手数为0!");
                            }
                            break;
                        case 8:
                            info.setPlayerId(value);
                            break;
                        case 9:
                            info.setPlayerName(value);
                            break;
                        case 10:
                            info.setClubId(value);
                            break;
                        case 11:
                            info.setClubName(value);
                            break;
                        case 16:
                            info.setInsurance(value);
                            break;
                        case 19:
                            info.setZj(value);
                            break;
                        case 20:
                            {
                                String dateStr = value.split(" ")[0];
                                info.setDay(value);
                                // add 导入的第一局作为当天的时间
                                if (StringUtil.isBlank(DataConstans.Date_Str)) {
                                    DataConstans.Date_Str = dateStr;
                                } else {
                                    try {
                                        if (sdf.parse(dateStr).before(sdf.parse(DataConstans.Date_Str))) {
                                            DataConstans.Date_Str = dateStr;
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
                info.setTableId(tableId);
                userInfoList.add(info);
            }
        }
        // 遍历excel结束
        // 存储数据  {场次=infoList...}
        DataConstans.zjMap.put(tableId, userInfoList);
        is.close();
        // add 添加所有记录到联盟对帐表
        LMController.currentRecordList = LM_ExcelReaderUtil.readRecord_NewVersion(file);
        // LMController.refreshClubList();//放到锁定时去添加
        // LMController.checkOverEdu();
        log.info("结束----------导入战绩Excel" + " ===size:" + userInfoList.size());
    } catch (Exception e) {
        e.printStackTrace();
        return new Wrap();
    }
    return new Wrap(true, userInfoList);
}
Also used : Wrap(com.kendy.other.Wrap) UserInfos(com.kendy.entity.UserInfos) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row)

Example 52 with XSSFRow

use of org.apache.poi.xssf.usermodel.XSSFRow in project irida by phac-nml.

the class ProjectSamplesMetadataTemplateController method downloadTemplate.

/**
 * Download a {@link MetadataTemplate} as an Excel file.
 *
 * @param templateId
 * 		{@link Long} identifier for a {@link MetadataTemplate}
 * @param response
 * 		{@link HttpServletResponse}
 *
 * @throws IOException
 * 		thrown if output stream cannot be used.
 */
@RequestMapping(value = "/{templateId}/excel")
public void downloadTemplate(@PathVariable Long templateId, HttpServletResponse response) throws IOException {
    MetadataTemplate template = metadataTemplateService.read(templateId);
    List<MetadataTemplateField> fields = template.getFields();
    List<String> headers = fields.stream().map(MetadataTemplateField::getLabel).collect(Collectors.toList());
    String label = template.getLabel().replace(" ", "_");
    // Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();
    // Create a blank sheet
    XSSFSheet worksheet = workbook.createSheet(label);
    // Write the headers
    XSSFRow headerRow = worksheet.createRow(0);
    for (int i = 0; i < headers.size(); i++) {
        XSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(headers.get(i));
    }
    response.setHeader("Content-Disposition", "attachment; filename=\"" + label + ".xlsx\"");
    ServletOutputStream stream = response.getOutputStream();
    workbook.write(stream);
    stream.flush();
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) MetadataTemplate(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplate) UIMetadataTemplate(ca.corefacility.bioinformatics.irida.ria.web.models.UIMetadataTemplate) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) ServletOutputStream(javax.servlet.ServletOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) MetadataTemplateField(ca.corefacility.bioinformatics.irida.model.sample.MetadataTemplateField) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 53 with XSSFRow

use of org.apache.poi.xssf.usermodel.XSSFRow in project xm-ms-entity by xm-online.

the class EntityToExcelConverterUtils method toExcel.

/**
 * Writes entities to excel file.
 * @param entities the entities list
 * @return byte array of excel file
 */
public static byte[] toExcel(List<SimpleExportXmEntityDto> entities, String sheetName) {
    if (CollectionUtils.isEmpty(entities)) {
        log.warn("Passed empty object for serialize, therefore return empty byte array which represents excel file");
        return new byte[0];
    }
    try (XSSFWorkbook workbook = new XSSFWorkbook();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
        XSSFSheet sheet = workbook.createSheet(sheetName);
        XSSFCreationHelper creationHelper = workbook.getCreationHelper();
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(creationHelper.createDataFormat().getFormat(DateFormatConverter.getJavaDateTimePattern(0, Locale.US)));
        int rowCount = 0;
        XSSFRow headerRow = sheet.createRow(rowCount);
        IntStream.range(0, headers.length).forEach(i -> headerRow.createCell(i).setCellValue(headers[i]));
        for (SimpleExportXmEntityDto entity : entities) {
            Row row = sheet.createRow(++rowCount);
            int columnCount = 0;
            Cell cell = row.createCell(columnCount);
            cell.setCellValue(entity.getOrElseId(0L));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseKey(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseTypeKey(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseStateKey(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseName(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(Date.from(entity.getOrElseStartDate(Instant.now())));
            cell.setCellStyle(cellStyle);
            cell = row.createCell(++columnCount);
            cell.setCellValue(Date.from(entity.getOrElseStartDate(Instant.now())));
            cell.setCellStyle(cellStyle);
            cell = row.createCell(++columnCount);
            cell.setCellValue(Date.from(entity.getOrElseEndDate(Instant.now())));
            cell.setCellStyle(cellStyle);
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseAvatarUrl(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseDescription(StringUtils.EMPTY));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.isOrElseRemoved(false));
            cell = row.createCell(++columnCount);
            cell.setCellValue(entity.getOrElseCreatedBy(StringUtils.EMPTY));
        }
        workbook.write(outputStream);
        return outputStream.toByteArray();
    } catch (IOException e) {
        throw new IllegalStateException("Exception while writing data to excel file");
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) SimpleExportXmEntityDto(com.icthh.xm.ms.entity.domain.SimpleExportXmEntityDto) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFCreationHelper(org.apache.poi.xssf.usermodel.XSSFCreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) Cell(org.apache.poi.ss.usermodel.Cell)

Example 54 with XSSFRow

use of org.apache.poi.xssf.usermodel.XSSFRow in project structr by structr.

the class ToExcelFunction method writeExcel.

public Workbook writeExcel(final List list, final String propertyView, final List<String> properties, final boolean includeHeader, final boolean localizeHeader, final String headerLocalizationDomain, final Locale locale) throws IOException {
    final Workbook workbook = new XSSFWorkbook();
    final XSSFSheet sheet = (XSSFSheet) workbook.createSheet();
    int rowCount = 0;
    int cellCount = 0;
    XSSFRow currentRow = null;
    XSSFCell cell = null;
    if (includeHeader) {
        currentRow = (XSSFRow) sheet.createRow(rowCount++);
        cellCount = 0;
        if (propertyView != null) {
            final Object obj = list.get(0);
            if (obj instanceof GraphObject) {
                for (PropertyKey key : ((GraphObject) obj).getPropertyKeys(propertyView)) {
                    cell = (XSSFCell) currentRow.createCell(cellCount++);
                    String value = key.dbName();
                    if (localizeHeader) {
                        try {
                            value = LocalizeFunction.getLocalization(locale, value, headerLocalizationDomain);
                        } catch (FrameworkException fex) {
                            logger.warn("to_excel(): Exception", fex);
                        }
                    }
                    cell.setCellValue(value);
                }
            } else {
                cell = (XSSFCell) currentRow.createCell(cellCount++);
                cell.setCellValue("Error: Object is not of type GraphObject, can not determine properties of view for header row");
            }
        } else if (properties != null) {
            for (final String colName : properties) {
                cell = (XSSFCell) currentRow.createCell(cellCount++);
                String value = colName;
                if (localizeHeader) {
                    try {
                        value = LocalizeFunction.getLocalization(locale, value, headerLocalizationDomain);
                    } catch (FrameworkException fex) {
                        logger.warn("to_excel(): Exception", fex);
                    }
                }
                cell.setCellValue(value);
            }
        }
    }
    for (final Object obj : list) {
        currentRow = (XSSFRow) sheet.createRow(rowCount++);
        cellCount = 0;
        if (propertyView != null) {
            if (obj instanceof GraphObject) {
                for (PropertyKey key : ((GraphObject) obj).getPropertyKeys(propertyView)) {
                    final Object value = ((GraphObject) obj).getProperty(key);
                    cell = (XSSFCell) currentRow.createCell(cellCount++);
                    cell.setCellValue(escapeForExcel(value));
                }
            } else {
                cell = (XSSFCell) currentRow.createCell(cellCount++);
                cell.setCellValue("Error: Object is not of type GraphObject, can not determine properties of object");
            }
        } else if (properties != null) {
            if (obj instanceof GraphObject) {
                final GraphObject castedObj = (GraphObject) obj;
                for (final String colName : properties) {
                    final PropertyKey key = StructrApp.key(obj.getClass(), colName);
                    final Object value = castedObj.getProperty(key);
                    cell = (XSSFCell) currentRow.createCell(cellCount++);
                    cell.setCellValue(escapeForExcel(value));
                }
            } else if (obj instanceof Map) {
                final Map castedObj = (Map) obj;
                for (final String colName : properties) {
                    final Object value = castedObj.get(colName);
                    cell = (XSSFCell) currentRow.createCell(cellCount++);
                    cell.setCellValue(escapeForExcel(value));
                }
            }
        }
    }
    return workbook;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) FrameworkException(org.structr.common.error.FrameworkException) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) Map(java.util.Map) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) PropertyKey(org.structr.core.property.PropertyKey)

Example 55 with XSSFRow

use of org.apache.poi.xssf.usermodel.XSSFRow in project dom5utils by larzm42.

the class MonsterStatIndexer method run.

public static void run() {
    FileInputStream stream = null;
    List<Monster> monsterList = new ArrayList<Monster>();
    try {
        BufferedWriter writer = new BufferedWriter(new FileWriter("monsters.txt"));
        BufferedWriter writerUnknown = new BufferedWriter(new FileWriter("monstersUnknown.txt"));
        long startIndex = Starts.MONSTER;
        int ch;
        stream = new FileInputStream(EXE_NAME);
        stream.skip(Starts.MONSTER_MAGIC);
        Set<String> unknown = new TreeSet<String>();
        // magic
        byte[] 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);
            }
            stream.read(c, 0, 4);
            high = String.format("%02X", c[1]);
            low = String.format("%02X", c[0]);
            int 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);
            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 if (path == 52) {
                            monRandomMagic.mask = 30720;
                            monRandomMagic.nbr = 1;
                            monRandomMagic.link = value;
                            monRandomMagic.rand = 100;
                        } else if (path == 53) {
                            monRandomMagic.mask = 32640;
                            monRandomMagic.nbr = 1;
                            monRandomMagic.link = value;
                            monRandomMagic.rand = 100;
                        } else if (path == 56) {
                        // Don't know what this is
                        } else {
                            monRandomMagic.mask = path;
                            monRandomMagic.nbr = 1;
                            if (value > 100) {
                                monRandomMagic.link = value / 100;
                                monRandomMagic.rand = 100;
                            } else {
                                monRandomMagic.link = 1;
                                monRandomMagic.rand = value;
                            }
                        }
                        if (path != 56) {
                            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 (ranMagic.mask == 30720 && path == 52 && ranMagic.link == value) {
                                ranMagic.nbr++;
                                found = true;
                            }
                            if (ranMagic.mask == 32640 && path == 53 && 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 if (path == 52) {
                                monRandomMagic.mask = 30720;
                                monRandomMagic.nbr = 1;
                                monRandomMagic.link = value;
                                monRandomMagic.rand = 100;
                            } else if (path == 53) {
                                monRandomMagic.mask = 32640;
                                monRandomMagic.nbr = 1;
                                monRandomMagic.link = value;
                                monRandomMagic.rand = 100;
                            } else if (path == 56) {
                            // Don't know what this is
                            } else {
                                monRandomMagic.mask = path;
                                monRandomMagic.nbr = 1;
                                if (value > 100) {
                                    monRandomMagic.link = value / 100;
                                    monRandomMagic.rand = 100;
                                } else {
                                    monRandomMagic.link = 1;
                                    monRandomMagic.rand = value;
                                }
                            }
                            if (path != 56) {
                                randomMagicList.add(monRandomMagic);
                            }
                        }
                    }
            }
        }
        stream.close();
        stream = new FileInputStream(EXE_NAME);
        stream.skip(startIndex);
        // 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();
            Monster monster = new Monster();
            monster.setId(rowNumber);
            monster.setName(name.toString());
            monster.setAp(getBytes2(startIndex + 40));
            monster.setMapmove(getBytes2(startIndex + 42));
            monster.setSize(getBytes2(startIndex + 44));
            monster.setRessize(getBytes2(startIndex + 44));
            monster.setHp(getBytes2(startIndex + 46));
            monster.setProt(getBytes2(startIndex + 48));
            monster.setStr(getBytes2(startIndex + 50));
            monster.setEnc(getBytes2(startIndex + 52));
            monster.setPrec(getBytes2(startIndex + 54));
            monster.setAtt(getBytes2(startIndex + 56));
            monster.setDef(getBytes2(startIndex + 58));
            monster.setMr(getBytes2(startIndex + 60));
            monster.setMor(getBytes2(startIndex + 62));
            monster.setWpn1(getBytes2(startIndex + 208 + 24) == 0 ? null : getBytes2(startIndex + 208 + 24));
            monster.setWpn2(getBytes2(startIndex + 210 + 24) == 0 ? null : getBytes2(startIndex + 210 + 24));
            monster.setWpn3(getBytes2(startIndex + 212 + 24) == 0 ? null : getBytes2(startIndex + 212 + 24));
            monster.setWpn4(getBytes2(startIndex + 214 + 24) == 0 ? null : getBytes2(startIndex + 214 + 24));
            monster.setWpn5(getBytes2(startIndex + 216 + 24) == 0 ? null : getBytes2(startIndex + 216 + 24));
            monster.setWpn6(getBytes2(startIndex + 218 + 24) == 0 ? null : getBytes2(startIndex + 218 + 24));
            monster.setWpn7(getBytes2(startIndex + 220 + 24) == 0 ? null : getBytes2(startIndex + 220 + 24));
            monster.setArmor1(getBytes2(startIndex + 228 + 24) == 0 ? null : getBytes2(startIndex + 228 + 24));
            monster.setArmor2(getBytes2(startIndex + 230 + 24) == 0 ? null : getBytes2(startIndex + 230 + 24));
            monster.setArmor3(getBytes2(startIndex + 232 + 24) == 0 ? null : getBytes2(startIndex + 232 + 24));
            monster.setBasecost(getBytes2(startIndex + 234 + 24));
            monster.setRcost(getBytes2(startIndex + 236 + 24));
            monster.setRpcost(getBytes2(startIndex + 240 + 24));
            List<AttributeValue> attributes = getAttributes(startIndex + Starts.MONSTER_ATTRIBUTE_OFFSET, Starts.MONSTER_ATTRIBUTE_GAP);
            for (AttributeValue attr : attributes) {
                boolean found = false;
                for (int x = 0; x < KNOWN_MONSTER_ATTRS.length; x++) {
                    if (KNOWN_MONSTER_ATTRS[x][0].equals(attr.attribute)) {
                        found = true;
                        if (KNOWN_MONSTER_ATTRS[x][1].endsWith("#")) {
                            int i = 1;
                            for (String value : attr.values) {
                                monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1].replace("#", i + ""), Integer.parseInt(value)));
                                i++;
                            }
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("startage")) {
                            int age = Integer.parseInt(attr.values.get(0));
                            if (age == -1) {
                                age = 0;
                            }
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString((int) (age + age * .1))));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("heatrec")) {
                            int val = Integer.parseInt(attr.values.get(0));
                            if (val == 10) {
                                val = 0;
                            } else {
                                val = 1;
                            }
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val)));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("coldrec")) {
                            int val = Integer.parseInt(attr.values.get(0));
                            if (val == 10) {
                                val = 0;
                            } else {
                                val = 1;
                            }
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val)));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("incunrest")) {
                            double val = Double.parseDouble(attr.values.get(0)) / 10d;
                            if (val < 1 && val > -1) {
                                monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Double.toString(val)));
                            } else {
                                monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString((int) val)));
                            }
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("petrify")) {
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], "1"));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("eyes")) {
                            int age = Integer.parseInt(attr.values.get(0));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(age + 2)));
                        } else if (KNOWN_MONSTER_ATTRS[x][0].equals("A400")) {
                            monster.addAttribute(new Attr("n_summon", "1"));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0)));
                        } else if (KNOWN_MONSTER_ATTRS[x][0].equals("A500")) {
                            monster.addAttribute(new Attr("n_summon", "2"));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0)));
                        } else if (KNOWN_MONSTER_ATTRS[x][0].equals("A600")) {
                            monster.addAttribute(new Attr("n_summon", "3"));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0)));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod fire")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "F";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod air")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "A";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod water")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "W";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod earth")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "E";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod astral")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "S";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod death")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "D";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod nature")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "N";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("gemprod blood")) {
                            String gemprod = "";
                            if (monster.getAttribute("gemprod") != null) {
                                gemprod = monster.getAttribute("gemprod").toString();
                            }
                            gemprod += attr.values.get(0) + "B";
                            monster.addAttribute(new Attr("gemprod", gemprod));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("pathcost")) {
                            if (monster.getAttribute("startdom") == null) {
                                monster.addAttribute(new Attr("startdom", 1));
                            }
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0)));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("spreadchaos/death")) {
                            if (attr.values.get(0).equals("100")) {
                                monster.addAttribute(new Attr("spreadchaos", 1));
                            } else if (attr.values.get(0).equals("103")) {
                                monster.addAttribute(new Attr("spreaddeath", 1));
                            }
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("spreadorder/growth")) {
                            if (attr.values.get(0).equals("100")) {
                                monster.addAttribute(new Attr("spreadorder", 1));
                            } else if (attr.values.get(0).equals("103")) {
                                monster.addAttribute(new Attr("spreadgrowth", 1));
                            }
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("damagerev")) {
                            int val = Integer.parseInt(attr.values.get(0));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val - 1)));
                        } else if (KNOWN_MONSTER_ATTRS[x][1].equals("popkill")) {
                            int val = Integer.parseInt(attr.values.get(0));
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], Integer.toString(val * 10)));
                        } else {
                            monster.addAttribute(new Attr(KNOWN_MONSTER_ATTRS[x][1], attr.values.get(0)));
                        }
                    }
                }
                if (!found) {
                    monster.addAttribute(new Attr("\tUnknown Attribute<" + attr.attribute + ">", attr.values.get(0)));
                    unknown.add(attr.attribute);
                }
            }
            List<String> largeBitmap = largeBitmap(startIndex + 272, values);
            for (String bit : largeBitmap) {
                monster.addAttribute(new Attr(bit, 1));
            }
            if (monster.getAttribute("slow_to_recruit") != null) {
                monster.addAttribute(new Attr("rt", "2"));
            } else {
                monster.addAttribute(new Attr("rt", "1"));
            }
            if (largeBitmap.contains("heat")) {
                monster.addAttribute(new Attr("heat", "3"));
            }
            if (largeBitmap.contains("cold")) {
                monster.addAttribute(new Attr("cold", "3"));
            }
            String additionalLeader = "0";
            if (monster.getAttribute("additional leadership") != null) {
                additionalLeader = monster.getAttribute("additional leadership").toString();
            }
            monster.addAttribute(new Attr("leader", 40 + Integer.parseInt(additionalLeader)));
            if (largeBitmap.contains("noleader")) {
                if (!"".equals(additionalLeader)) {
                    monster.addAttribute(new Attr("leader", additionalLeader));
                } else {
                    monster.addAttribute(new Attr("leader", 0));
                }
            }
            if (largeBitmap.contains("poorleader")) {
                if (!"".equals(additionalLeader)) {
                    monster.addAttribute(new Attr("leader", 10 + Integer.parseInt(additionalLeader)));
                } else {
                    monster.addAttribute(new Attr("leader", 10));
                }
            }
            if (largeBitmap.contains("goodleader")) {
                if (!"".equals(additionalLeader)) {
                    monster.addAttribute(new Attr("leader", 80 + Integer.parseInt(additionalLeader)));
                } else {
                    monster.addAttribute(new Attr("leader", 80));
                }
            }
            if (largeBitmap.contains("expertleader")) {
                if (!"".equals(additionalLeader)) {
                    monster.addAttribute(new Attr("leader", 120 + Integer.parseInt(additionalLeader)));
                } else {
                    monster.addAttribute(new Attr("leader", 120));
                }
            }
            if (largeBitmap.contains("superiorleader")) {
                if (!"".equals(additionalLeader)) {
                    monster.addAttribute(new Attr("leader", 160 + Integer.parseInt(additionalLeader)));
                } else {
                    monster.addAttribute(new Attr("leader", 160));
                }
            }
            if (largeBitmap.contains("poormagicleader")) {
                monster.addAttribute(new Attr("magicleader", 10));
            }
            if (largeBitmap.contains("okmagicleader")) {
                monster.addAttribute(new Attr("magicleader", 40));
            }
            if (largeBitmap.contains("goodmagicleader")) {
                monster.addAttribute(new Attr("magicleader", 80));
            }
            if (largeBitmap.contains("expertmagicleader")) {
                monster.addAttribute(new Attr("magicleader", 120));
            }
            if (largeBitmap.contains("superiormagicleader")) {
                monster.addAttribute(new Attr("magicleader", 160));
            }
            if (largeBitmap.contains("poorundeadleader")) {
                monster.addAttribute(new Attr("undeadleader", 10));
            }
            if (largeBitmap.contains("okundeadleader")) {
                monster.addAttribute(new Attr("undeadleader", 40));
            }
            if (largeBitmap.contains("goodundeadleader")) {
                monster.addAttribute(new Attr("undeadleader", 80));
            }
            if (largeBitmap.contains("expertundeadleader")) {
                monster.addAttribute(new Attr("undeadleader", 120));
            }
            if (largeBitmap.contains("superiorundeadleader")) {
                monster.addAttribute(new Attr("undeadleader", 160));
            }
            if (largeBitmap.contains("coldres15")) {
                String additionalCold = "0";
                if (monster.getAttribute("coldres") != null) {
                    additionalCold = monster.getAttribute("coldres").toString();
                }
                boolean cold = false;
                if (largeBitmap.contains("cold") || monster.getAttribute("cold") != null) {
                    cold = true;
                }
                monster.addAttribute(new Attr("coldres", 15 + Integer.parseInt(additionalCold.equals("") ? "0" : additionalCold) + (cold ? 10 : 0)));
            } else {
                String additionalCold = "0";
                if (monster.getAttribute("coldres") != null) {
                    additionalCold = monster.getAttribute("coldres").toString();
                }
                boolean cold = false;
                if (largeBitmap.contains("cold") || monster.getAttribute("cold") != null) {
                    cold = true;
                }
                int coldres = Integer.parseInt(additionalCold.equals("") ? "0" : additionalCold) + (cold ? 10 : 0);
                monster.addAttribute(new Attr("coldres", coldres == 0 ? "" : Integer.toString(coldres)));
            }
            if (largeBitmap.contains("fireres15")) {
                String additionalFire = "0";
                if (monster.getAttribute("fireres") != null) {
                    additionalFire = monster.getAttribute("fireres").toString();
                }
                boolean heat = false;
                if (largeBitmap.contains("heat") || monster.getAttribute("heat") != null) {
                    heat = true;
                }
                monster.addAttribute(new Attr("fireres", 15 + Integer.parseInt(additionalFire.equals("") ? "0" : additionalFire) + (heat ? 10 : 0)));
            } else {
                String additionalFire = "0";
                if (monster.getAttribute("fireres") != null) {
                    additionalFire = monster.getAttribute("fireres").toString();
                }
                boolean heat = false;
                if (largeBitmap.contains("heat") || monster.getAttribute("heat") != null) {
                    heat = true;
                }
                int fireres = Integer.parseInt(additionalFire.equals("") ? "0" : additionalFire) + (heat ? 10 : 0);
                monster.addAttribute(new Attr("fireres", fireres == 0 ? "" : Integer.toString(fireres)));
            }
            if (largeBitmap.contains("poisonres15")) {
                String additionalPoisin = "0";
                if (monster.getAttribute("poisonres") != null) {
                    additionalPoisin = monster.getAttribute("poisonres").toString();
                }
                boolean poisoncloud = false;
                if (largeBitmap.contains("undead") || largeBitmap.contains("inanimate") || monster.getAttribute("poisoncloud") != null) {
                    poisoncloud = true;
                }
                monster.addAttribute(new Attr("poisonres", 15 + Integer.parseInt(additionalPoisin.equals("") ? "0" : additionalPoisin) + (poisoncloud ? 10 : 0)));
            } else {
                String additionalPoison = "0";
                if (monster.getAttribute("poisonres") != null) {
                    additionalPoison = monster.getAttribute("poisonres").toString();
                }
                boolean poisoncloud = false;
                if (largeBitmap.contains("undead") || largeBitmap.contains("inanimate") || monster.getAttribute("poisoncloud") != null) {
                    poisoncloud = true;
                }
                int poisonres = Integer.parseInt(additionalPoison.equals("") ? "0" : additionalPoison) + (poisoncloud ? 10 : 0);
                monster.addAttribute(new Attr("poisonres", poisonres == 0 ? "" : Integer.toString(poisonres)));
            }
            if (largeBitmap.contains("shockres15")) {
                String additionalShock = "0";
                if (monster.getAttribute("shockres") != null) {
                    additionalShock = monster.getAttribute("shockres").toString();
                }
                monster.addAttribute(new Attr("shockres", 15 + Integer.parseInt(additionalShock.equals("") ? "0" : additionalShock)));
            } else {
                String additionalShock = "0";
                if (monster.getAttribute("shockres") != null) {
                    additionalShock = monster.getAttribute("shockres").toString();
                }
                int shockres = Integer.parseInt(additionalShock.equals("") ? "0" : additionalShock);
                monster.addAttribute(new Attr("shockres", shockres == 0 ? "" : Integer.toString(shockres)));
            }
            if (largeBitmap.contains("stealthy40")) {
                String additionalStealth = "0";
                if (monster.getAttribute("stealthy") != null) {
                    additionalStealth = monster.getAttribute("stealthy").toString();
                }
                boolean glamour = false;
                if (monster.getAttribute("illusion") != null) {
                    glamour = true;
                }
                monster.addAttribute(new Attr("stealthy", 40 + Integer.parseInt(additionalStealth.equals("") ? "0" : additionalStealth) + (glamour ? 25 : 0)));
            } else {
                String additionalStealth = "0";
                if (monster.getAttribute("stealthy") != null) {
                    additionalStealth = monster.getAttribute("stealthy").toString();
                }
                monster.addAttribute(new Attr("stealthy", additionalStealth == null || additionalStealth.equals("0") ? "" : additionalStealth));
            }
            if (largeBitmap.contains("requndeadleadership")) {
                // but only if the unit is neither demon nor undead
                if (monster.getAttribute("undead") == null) {
                    if (monster.getAttribute("demon") == null) {
                        monster.addAttribute(new Attr("almostundead", 1));
                    }
                }
            }
            // magic
            Magic monMagic = monsterMagic.get(rowNumber);
            if (monMagic != null) {
                monster.addAttribute(new Attr("F", magicStrip(monMagic.F)));
                monster.addAttribute(new Attr("A", magicStrip(monMagic.A)));
                monster.addAttribute(new Attr("W", magicStrip(monMagic.W)));
                monster.addAttribute(new Attr("E", magicStrip(monMagic.E)));
                monster.addAttribute(new Attr("S", magicStrip(monMagic.S)));
                monster.addAttribute(new Attr("D", magicStrip(monMagic.D)));
                monster.addAttribute(new Attr("N", magicStrip(monMagic.N)));
                monster.addAttribute(new Attr("B", magicStrip(monMagic.B)));
                monster.addAttribute(new Attr("H", magicStrip(monMagic.H)));
                if (monMagic.rand != null) {
                    int count = 1;
                    for (RandomMagic ranMag : monMagic.rand) {
                        monster.addAttribute(new Attr("rand" + count, magicStrip(ranMag.rand)));
                        monster.addAttribute(new Attr("nbr" + count, magicStrip(ranMag.nbr)));
                        monster.addAttribute(new Attr("link" + count, magicStrip(ranMag.link)));
                        monster.addAttribute(new Attr("mask" + count, magicStrip(ranMag.mask)));
                        count++;
                    }
                }
            }
            if (largeBitmap.contains("misc2")) {
                monster.addAttribute(new Attr("hand", 0));
                monster.addAttribute(new Attr("head", 0));
                monster.addAttribute(new Attr("body", 0));
                monster.addAttribute(new Attr("foot", 0));
                monster.addAttribute(new Attr("misc", 2));
            }
            if (monster.getAttribute("itemslots") != null) {
                String slots = monster.getAttribute("itemslots").toString();
                int numHands = 0;
                int numHeads = 0;
                int numBody = 0;
                int numFoot = 0;
                int numMisc = 0;
                boolean crownOnly = false;
                long val = Long.parseLong(slots);
                if ((val & 0x0002) != 0) {
                    numHands++;
                }
                if ((val & 0x0004) != 0) {
                    numHands++;
                }
                if ((val & 0x0008) != 0) {
                    numHands++;
                }
                if ((val & 0x0010) != 0) {
                    numHands++;
                }
                if ((val & 0x0080) != 0) {
                    numHeads++;
                }
                if ((val & 0x0100) != 0) {
                    numHeads++;
                }
                if ((val & 0x0200) != 0) {
                    numHeads++;
                }
                if ((val & 0x0400) != 0) {
                    numBody++;
                }
                if ((val & 0x0800) != 0) {
                    numFoot++;
                }
                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++;
                }
                if ((val & 0x40000) != 0) {
                    crownOnly = true;
                }
                monster.addAttribute(new Attr("hand", numHands));
                monster.addAttribute(new Attr("head", numHeads));
                monster.addAttribute(new Attr("body", numBody));
                monster.addAttribute(new Attr("foot", numFoot));
                monster.addAttribute(new Attr("misc", numMisc));
                if (crownOnly) {
                    monster.addAttribute(new Attr("crownonly", "1"));
                }
            } else if (!largeBitmap.contains("misc2")) {
                monster.addAttribute(new Attr("hand", 2));
                monster.addAttribute(new Attr("head", 1));
                monster.addAttribute(new Attr("body", 1));
                monster.addAttribute(new Attr("foot", 1));
                monster.addAttribute(new Attr("misc", 2));
            }
            if (largeBitmap.contains("mounted")) {
                monster.addAttribute(new Attr("foot", 0));
            }
            monsterList.add(monster);
            stream = new FileInputStream(EXE_NAME);
            startIndex = startIndex + Starts.MONSTER_SIZE;
            stream.skip(startIndex);
            isr = new InputStreamReader(stream, "ISO-8859-1");
            in = new BufferedReader(isr);
            rowNumber++;
        }
        in.close();
        stream.close();
        // fixedname
        File heroesFile = new File("heroes.txt");
        Set<Integer> heroes = new HashSet<Integer>();
        File namesFile = new File("names.txt");
        List<String> names = new ArrayList<String>();
        FileReader herosFileReader = new FileReader(heroesFile);
        FileReader namesFileReader = new FileReader(namesFile);
        BufferedReader bufferedReader = new BufferedReader(herosFileReader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            heroes.add(Integer.parseInt(line));
        }
        bufferedReader.close();
        bufferedReader = new BufferedReader(namesFileReader);
        while ((line = bufferedReader.readLine()) != null) {
            names.add(line);
        }
        bufferedReader.close();
        int nameIndex = 0;
        for (Monster monster : monsterList) {
            Object unique = monster.getAttribute("unique");
            int id = monster.getId();
            if (id == 621 || id == 980 || id == 981 || id == 994 || id == 995 || id == 996 || id == 997 || id == 1484 || id == 1485 || id == 1486 || id == 1487 || (id >= 2765 && id <= 2781) || id == 3382 || id == 3383 || id == 3244 || id == 3245 || id == 3251 || id == 3252 || id == 3253 || id == 3254 || id == 3255 || id == 3425 || id == 3426 || id == 3427 || id == 3428) {
                unique = "0";
            }
            if (heroes.contains(monster.getId()) || (unique != null && unique.equals("1"))) /*|| (monster.getAttribute("startdom") != null) */
            /* || monster.getAttribute("id").equals("641")*/
            {
                monster.addAttribute(new Attr("fixedname", names.get(nameIndex++)));
            }
        }
        XSSFWorkbook wb = new XSSFWorkbook();
        FileOutputStream fos = new FileOutputStream("BaseU.xlsx");
        XSSFSheet sheet = wb.createSheet();
        int rowNum = 0;
        for (Monster monster : monsterList) {
            if (rowNum == 0) {
                XSSFRow row = sheet.createRow(rowNum);
                for (int i = 0; i < unit_columns.length; i++) {
                    row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(unit_columns[i]);
                }
                rowNum++;
            }
            XSSFRow row = sheet.createRow(rowNum);
            for (int i = 0; i < unit_columns.length; i++) {
                Object object = monster.getAttribute(unit_columns[i]);
                if (object != null) {
                    row.getCell(i, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
                }
            }
            dumpTextFile(monster, writer);
            rowNum++;
        }
        dumpUnknown(unknown, writerUnknown);
        writer.close();
        writerUnknown.close();
        wb.write(fos);
        fos.close();
        wb.close();
        wb = new XSSFWorkbook();
        fos = new FileOutputStream("monster.xlsx");
        sheet = wb.createSheet();
        rowNum = 0;
        int removedColumns = 0;
        for (Monster monster : monsterList) {
            if (rowNum == 0) {
                XSSFRow row = sheet.createRow(rowNum);
                for (int i = 0; i < unit_columns.length; i++) {
                    if (unit_columns[i].startsWith("wpn") || unit_columns[i].startsWith("armor") || unit_columns[i].startsWith("realm")) {
                        removedColumns++;
                        continue;
                    }
                    row.getCell(i - removedColumns, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(unit_columns[i].toLowerCase());
                }
                rowNum++;
            }
            XSSFRow row = sheet.createRow(rowNum);
            removedColumns = 0;
            for (int i = 0; i < unit_columns.length; i++) {
                if (unit_columns[i].startsWith("wpn") || unit_columns[i].startsWith("armor") || unit_columns[i].startsWith("realm")) {
                    removedColumns++;
                    continue;
                }
                Object object = monster.getAttribute(unit_columns[i]);
                if (object != null) {
                    row.getCell(i - removedColumns, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
                }
            }
            rowNum++;
        }
        wb.write(fos);
        fos.close();
        wb.close();
        wb = new XSSFWorkbook();
        fos = new FileOutputStream("monster_weapon.xlsx");
        sheet = wb.createSheet();
        rowNum = 0;
        for (Monster monster : monsterList) {
            if (rowNum == 0) {
                XSSFRow row = sheet.createRow(rowNum);
                for (int i = 0; i < unit_columns.length; i++) {
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("id");
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("monster_id");
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("weapon_id");
                }
                rowNum++;
            }
            for (int i = 0; i < unit_columns.length; i++) {
                if (!unit_columns[i].startsWith("wpn")) {
                    continue;
                }
                Object object = monster.getAttribute(unit_columns[i]);
                if (object != null) {
                    XSSFRow row = sheet.createRow(rowNum);
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(rowNum);
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(monster.getId());
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
                    rowNum++;
                }
            }
        }
        wb.write(fos);
        fos.close();
        wb.close();
        wb = new XSSFWorkbook();
        fos = new FileOutputStream("monster_armor.xlsx");
        sheet = wb.createSheet();
        rowNum = 0;
        for (Monster monster : monsterList) {
            if (rowNum == 0) {
                XSSFRow row = sheet.createRow(rowNum);
                for (int i = 0; i < unit_columns.length; i++) {
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("id");
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("monster_id");
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("armor_id");
                }
                rowNum++;
            }
            for (int i = 0; i < unit_columns.length; i++) {
                if (!unit_columns[i].startsWith("armor")) {
                    continue;
                }
                Object object = monster.getAttribute(unit_columns[i]);
                if (object != null) {
                    XSSFRow row = sheet.createRow(rowNum);
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(rowNum);
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(monster.getId());
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
                    rowNum++;
                }
            }
        }
        wb.write(fos);
        fos.close();
        wb.close();
        wb = new XSSFWorkbook();
        fos = new FileOutputStream("monster_realm.xlsx");
        sheet = wb.createSheet();
        rowNum = 0;
        for (Monster monster : monsterList) {
            if (rowNum == 0) {
                XSSFRow row = sheet.createRow(rowNum);
                for (int i = 0; i < unit_columns.length; i++) {
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("id");
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("monster_id");
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue("realm");
                }
                rowNum++;
            }
            for (int i = 0; i < unit_columns.length; i++) {
                if (!unit_columns[i].startsWith("realm")) {
                    continue;
                }
                Object object = monster.getAttribute(unit_columns[i]);
                if (object != null) {
                    XSSFRow row = sheet.createRow(rowNum);
                    row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(rowNum);
                    row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(monster.getId());
                    row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).setCellValue(object.toString());
                    rowNum++;
                }
            }
        }
        wb.write(fos);
        fos.close();
        wb.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) BufferedWriter(java.io.BufferedWriter) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) TreeSet(java.util.TreeSet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) FileReader(java.io.FileReader) HashSet(java.util.HashSet) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) File(java.io.File)

Aggregations

XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)59 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)39 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)39 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)35 FileOutputStream (java.io.FileOutputStream)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 FileInputStream (java.io.FileInputStream)14 BufferedReader (java.io.BufferedReader)10 FileNotFoundException (java.io.FileNotFoundException)10 Test (org.junit.Test)10 InputStreamReader (java.io.InputStreamReader)9 Reader (java.io.Reader)9 File (java.io.File)8 HashMap (java.util.HashMap)8 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)8 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5