Groovy web console

subscribe to the feed Subscribe
to this
site

readfile

Published 6 months ago by test with tags test
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
//content
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.text.SimpleDateFormat;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle; 
import org.apache.poi.xssf.usermodel.XSSFColor; 


def resultLog="";
def errorLog="";
def ValidationLog="";


def filePath = "/var/tmp";
def fileName = "id_rsa.pub";
//Abschaltung_50224539.xlsx

def filePathName = filePath+'/'+fileName;

FileInputStream fis;    
        try
        {
            File file = new File(filePathName);    
            
            
            if (file.exists())    
            {
                resultLog += "\nFile exists";    
                    
                    XSSFWorkbook workbook;
                    XSSFSheet worksheet;
                    XSSFRow headerRow;
                    XSSFCell headerCell;
                    XSSFRow dataRow; 
                    XSSFCell dataCell;
                    
                    
                    fis = new FileInputStream(file);        
                        resultLog += "\nfis object created..";
                        workbook = new XSSFWorkbook (fis);
                        resultLog += "\nworkbook object created..";
                        worksheet = workbook.getSheetAt(0);
                        resultLog += "\nworksheet object created..";
                                                
                        
                        //check for header row exists
                        def isHeaderRow = worksheet.getPhysicalNumberOfRows() > 0;
                        
                        resultLog += "\nisHeaderRow is: $isHeaderRow";    
                        if (isHeaderRow)
                        {
                            headerRow = worksheet.getRow(11);
                            resultLog += "\nheaderRow: $headerRow";    
                        }            
                        
                        fis.close()
            }
            else
            {        
                resultLog += "\nFile not exists";            
            } 
        }/*
        catch (FileNotFoundException e) {
            resultLog += "\nFAIL - "+e;        
        }
        catch (IOException e) {
            resultLog += "\nFAIL - "+e;        
        }*/
        catch (Exception e) {
            resultLog += "\nFAIL - "+e;        
        }


//Inputs to assess layer of this Action task

INPUTS.RESULTSLOGS = resultLog;

//assess
def condition = "good"
def severity = "good"
def detail = "";
def summary = "";
def detailDebug="";

def resultLog = INPUTS.RESULTSLOGS;


    detail += resultLog;
    
// Worksheet
RESULT.condition = condition
RESULT.severity = severity
RESULT.summary = summary
RESULT.detail = detail