Facebook
From Edgy Butterfly, 7 Years ago, written in Java.
This paste is a reply to Untitled from Gracious Wigeon - view diff
Embed
Download Paste or View Raw
Hits: 432
  1. package com.mysite.inmarsat;
  2.  
  3. import java.io.*;
  4. import org.apache.poi.hssf.usermodel.HSSFSheet;
  5. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  6. import org.apache.poi.hssf.usermodel.HSSFRow;
  7. import org.apache.poi.hssf.usermodel.HSSFCell;
  8.  
  9. /**
  10.  * Created by gmlynarczy001 on 2016-09-14.
  11.  */
  12. public class Xwriter {
  13.  
  14.     String filename = "INFO.xls";
  15.     HSSFWorkbook workbook = new HSSFWorkbook();
  16.     HSSFSheet uat = workbook.createSheet("UAT");
  17.     HSSFSheet dht = workbook.createSheet("DHT");
  18.     int n = 0;
  19.  
  20.  
  21.     FileOutputStream fileOut;
  22.     private void getFileStream() {
  23.       if (fileOut == null) {
  24.         fileOut = new FileOutputStream(filename);
  25.       }
  26.       return fileOut;
  27.     }
  28.  
  29.        
  30.  
  31.         public void saveExcelMC(String mc){
  32.             try {
  33.  
  34.                 if (EnvAndDP.DP.equals("SHARE")) {
  35.                     n = 1;
  36.                 } else if (EnvAndDP.DP.equals("1090")) {
  37.                     n = 2;
  38.                 } else if (EnvAndDP.DP.equals("1180")) {
  39.                     n = 3;
  40.                 }
  41.  
  42.                 if (EnvAndDP.ENV.equals("UAT")) {
  43.                     HSSFRow head = uat.createRow((short) 0);
  44.                     head.createCell(0).setCellValue("TYPE");
  45.                     head.createCell(1).setCellValue("SHARE");
  46.                     head.createCell(2).setCellValue("1090X");
  47.                     head.createCell(3).setCellValue("1180X");
  48.  
  49.                     HSSFRow rowMC = uat.createRow((short) 1);
  50.                     rowMC.createCell(0).setCellValue("Major Corporate");
  51.                     rowMC.createCell(n).setCellValue(mc);
  52.  
  53.                 } else if (EnvAndDP.ENV.equals("DHT")) {
  54.                     HSSFRow head = dht.createRow((short) 0);
  55.                     head.createCell(0).setCellValue("TYPE");
  56.                     head.createCell(1).setCellValue("SHARE");
  57.                     head.createCell(2).setCellValue("1090X");
  58.                     head.createCell(3).setCellValue("1180X");
  59.  
  60.                     HSSFRow rowMC = dht.createRow((short) 1);
  61.                     rowMC.createCell(0).setCellValue("Major Corporate");
  62.                     rowMC.createCell(n).setCellValue(mc);
  63.                 }
  64.                
  65.                 FileOutputStream fileOut = getFileStream();
  66.                 workbook.write(fileOut);
  67.  
  68.             }catch (IOException e){
  69.                 e.printStackTrace();
  70.             }
  71.         }
  72.         public void saveExcelVess(String vess){
  73.             try {
  74.  
  75.                 if (EnvAndDP.DP.equals("SHARE")) {
  76.                     n = 1;
  77.                 } else if (EnvAndDP.DP.equals("1090")) {
  78.                     n = 2;
  79.                 } else if (EnvAndDP.DP.equals("1180")) {
  80.                     n = 3;
  81.                 }
  82.  
  83.                 if (EnvAndDP.ENV.equals("UAT")) {
  84.                     HSSFRow head = uat.createRow((short) 0);
  85.                     head.createCell(0).setCellValue("TYPE");
  86.                     head.createCell(1).setCellValue("SHARE");
  87.                     head.createCell(2).setCellValue("1090X");
  88.                     head.createCell(3).setCellValue("1180X");
  89.  
  90.                     HSSFRow rowVess = uat.createRow((short) 2);
  91.                     rowVess.createCell(0).setCellValue("Vessel");
  92.                     rowVess.createCell(n).setCellValue(vess);
  93.  
  94.                 } else if (EnvAndDP.ENV.equals("DHT")) {
  95.                     HSSFRow head = dht.createRow((short) 0);
  96.                     head.createCell(0).setCellValue("TYPE");
  97.                     head.createCell(1).setCellValue("SHARE");
  98.                     head.createCell(2).setCellValue("1090X");
  99.                     head.createCell(3).setCellValue("1180X");
  100.  
  101.                     HSSFRow rowVess = dht.createRow((short) 2);
  102.                     rowVess.createCell(0).setCellValue("Vessel");
  103.                     rowVess.createCell(n).setCellValue(vess);
  104.                 }
  105.  
  106.                 FileOutputStream fileOut = getFileStream();
  107.                 workbook.write(fileOut);
  108.  
  109.             }catch (IOException e){
  110.                 e.printStackTrace();
  111.             }
  112.         }
  113. }