Facebook
From Edgy Butterfly, 7 Years ago, written in Java.
This paste is a reply to Untitled from Gracious Wigeon - go back
Embed
Viewing differences between Untitled and Re: Untitled
package com.mysite.inmarsat;

import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

/**
 * Created by gmlynarczy001 on 2016-09-14.
 */
public class Xwriter {

    String filename = "INFO.xls";
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet uat = workbook.createSheet("UAT");
    HSSFSheet dht = workbook.createSheet("DHT");
    int n = 0;

0;
  
  
    FileOutputStream fileOut;
    private void getFileStream() {
      if (fileOut == null) {
        fileOut = new FileOutputStream(filename);
      }
      return fileOut;
    }
  
          

        public void saveExcelMC(String mc){
            try {

                if (EnvAndDP.DP.equals("SHARE")) {
                    n = 1;
                } else if (EnvAndDP.DP.equals("1090")) {
                    n = 2;
                } else if (EnvAndDP.DP.equals("1180")) {
                    n = 3;
                }

                if (EnvAndDP.ENV.equals("UAT")) {
                    HSSFRow head = uat.createRow((short) 0);
                    head.createCell(0).setCellValue("TYPE");
                    head.createCell(1).setCellValue("SHARE");
                    head.createCell(2).setCellValue("1090X");
                    head.createCell(3).setCellValue("1180X");

                    HSSFRow rowMC = uat.createRow((short) 1);
                    rowMC.createCell(0).setCellValue("Major Corporate");
                    rowMC.createCell(n).setCellValue(mc);

                } else if (EnvAndDP.ENV.equals("DHT")) {
                    HSSFRow head = dht.createRow((short) 0);
                    head.createCell(0).setCellValue("TYPE");
                    head.createCell(1).setCellValue("SHARE");
                    head.createCell(2).setCellValue("1090X");
                    head.createCell(3).setCellValue("1180X");

                    HSSFRow rowMC = dht.createRow((short) 1);
                    rowMC.createCell(0).setCellValue("Major Corporate");
                    rowMC.createCell(n).setCellValue(mc);
                }

                
}
                
                
FileOutputStream fileOut = new FileOutputStream(filename);
getFileStream();
                workbook.write(fileOut);
                fileOut.close();

write(fileOut);

            }catch (IOException e){
                e.printStackTrace();
            }
        }
        public void saveExcelVess(String vess){
            try {

                if (EnvAndDP.DP.equals("SHARE")) {
                    n = 1;
                } else if (EnvAndDP.DP.equals("1090")) {
                    n = 2;
                } else if (EnvAndDP.DP.equals("1180")) {
                    n = 3;
                }

                if (EnvAndDP.ENV.equals("UAT")) {
                    HSSFRow head = uat.createRow((short) 0);
                    head.createCell(0).setCellValue("TYPE");
                    head.createCell(1).setCellValue("SHARE");
                    head.createCell(2).setCellValue("1090X");
                    head.createCell(3).setCellValue("1180X");

                    HSSFRow rowVess = uat.createRow((short) 2);
                    rowVess.createCell(0).setCellValue("Vessel");
                    rowVess.createCell(n).setCellValue(vess);

                } else if (EnvAndDP.ENV.equals("DHT")) {
                    HSSFRow head = dht.createRow((short) 0);
                    head.createCell(0).setCellValue("TYPE");
                    head.createCell(1).setCellValue("SHARE");
                    head.createCell(2).setCellValue("1090X");
                    head.createCell(3).setCellValue("1180X");

                    HSSFRow rowVess = dht.createRow((short) 2);
                    rowVess.createCell(0).setCellValue("Vessel");
                    rowVess.createCell(n).setCellValue(vess);
                }

                FileOutputStream fileOut = new FileOutputStream(filename);
getFileStream();
                workbook.write(fileOut);
                fileOut.close();

write(fileOut);

            }catch (IOException e){
                e.printStackTrace();
            }
        }
}