Example #1
0
  public void run() {
    File dir = new File("../../../../github_data/megafon/cs-core/");

    try {
      Nokia(new File(dir, "nokia/Master project CS SWAP_15.xml"));
      Huawei("УФ", new File(dir, "huawei/ПГ EKA + Ural v0 13 (2000).xml"));
      Huawei("ДвФ", new File(dir, "huawei/ПГ Khab+all cities V 1.6 (2000-2003).xml"));
      Huawei("СбФ", new File(dir, "huawei/ПГ Siberia all cities V 1.1 (2000-2003)_20161209.xml"));

      saveExcelPoject(new File(dir, "projects.xlsx"));
      saveStartProjects(new File(dir, "starts.csv"));
    } catch (IOException | ParserConfigurationException | SAXException e) {
      LOG.log(Level.SEVERE, "Исключение", e);
    }
  }
Example #2
0
/** Перевод всех проектов, сохраненных в XML формат в сводный Excel файл. */
public class Project2Excel {

  private static final Logger LOG = Logger.getLogger(Project2Excel.class.getName());

  private final List<Region> regions = new ArrayList<>(90);

  public void run() {
    File dir = new File("../../../../github_data/megafon/cs-core/");

    try {
      Nokia(new File(dir, "nokia/Master project CS SWAP_15.xml"));
      Huawei("УФ", new File(dir, "huawei/ПГ EKA + Ural v0 13 (2000).xml"));
      Huawei("ДвФ", new File(dir, "huawei/ПГ Khab+all cities V 1.6 (2000-2003).xml"));
      Huawei("СбФ", new File(dir, "huawei/ПГ Siberia all cities V 1.1 (2000-2003)_20161209.xml"));

      saveExcelPoject(new File(dir, "projects.xlsx"));
      saveStartProjects(new File(dir, "starts.csv"));
    } catch (IOException | ParserConfigurationException | SAXException e) {
      LOG.log(Level.SEVERE, "Исключение", e);
    }
  }

  private void Nokia(File file) throws IOException, ParserConfigurationException, SAXException {
    XMLProject project = new XMLProject();

    project.parse(file, new NokiaProjectHandler(this.regions));
  }

  private void Huawei(String filial, File file)
      throws IOException, ParserConfigurationException, SAXException {
    XMLProject project = new XMLProject();

    project.parse(file, new HuaweiProjectHandler(this.regions, filial));
  }

  private void saveExcelPoject(File file) throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("timeplan");
    // Заголовок в 0 строке
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue("Филиал");
    cell = row.createCell(1);
    cell.setCellValue("Город");
    Calendar cal = Calendar.getInstance();
    cal.set(2017, 0, 5); // Начальная дата проекта
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy");
    for (int i = 0; i < 3 * 52; i++) { // Счетчик по неделям
      cell = row.createCell(i + 2);
      cell.setCellValue(sdf.format(cal.getTime()));
      cal.add(Calendar.WEEK_OF_YEAR, 1); // Следующая неделя
    }

    // sheet.setColumnWidth(0, 256);

    // Цвета ячеек
    CellStyle[] styles = new CellStyle[6];
    styles[0] = wb.createCellStyle();
    styles[0].setFillForegroundColor(HSSFColor.RED.index);
    styles[0].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[1] = wb.createCellStyle();
    styles[1].setFillForegroundColor(HSSFColor.GREEN.index);
    styles[1].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[2] = wb.createCellStyle();
    styles[2].setFillForegroundColor(HSSFColor.BLUE.index);
    styles[2].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[3] = wb.createCellStyle();
    styles[3].setFillForegroundColor(HSSFColor.ROSE.index);
    styles[3].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[4] = wb.createCellStyle();
    styles[4].setFillForegroundColor(HSSFColor.LIGHT_BLUE.index);
    styles[4].setFillPattern(FillPatternType.SOLID_FOREGROUND);
    styles[5] = wb.createCellStyle();
    styles[5].setFillForegroundColor(HSSFColor.LIGHT_GREEN.index);
    styles[5].setFillPattern(FillPatternType.SOLID_FOREGROUND);

    short rowIdx = 0;
    for (Region region : this.regions) {
      row = sheet.createRow(++rowIdx);
      cell = row.createCell(0);
      cell.setCellValue(region.filial);
      cell = row.createCell(1);
      cell.setCellValue(region.name);

      cal = Calendar.getInstance();
      cal.set(2017, 0, 5); // Начальная дата проекта
      for (int i = 0; i < 3 * 52; i++) { // Счетчик по неделям
        short color = region.getDateColorIndex(cal.getTime());
        if (color >= 0) {
          cell = row.createCell(i + 2);
          cell.setCellStyle(styles[color]);
        }

        cal.add(Calendar.WEEK_OF_YEAR, 1); // Следующая неделя
      }
    }

    try (FileOutputStream fileOut = new FileOutputStream(file)) {
      wb.write(fileOut);
    }
  }

  private void saveStartProjects(File file) throws IOException {
    Calendar cal = Calendar.getInstance();

    try (PrintWriter out = new PrintWriter(file, "windows-1251")) {
      for (Region region : this.regions) {
        cal.setTime(region.start);

        out.write("\"");
        out.write(region.filial + " " + region.name);
        out.write("\";;;");

        int skeepCells = (cal.get(Calendar.YEAR) - 2017) * 5 + (cal.get(Calendar.MONDAY) % 4);
        for (int i = 0; i < skeepCells; i++) {
          out.write(";");
        }
        out.println("X");
      }
    }
  }
}