Wednesday, May 15, 2019

Create Excel Report of Selected Single Schedule Task in Schedule Manager

import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;

public class SingleReport {

int count=1;
FileOutputStream fileOut ;
TCSession session;

public SingleReport() throws InvalidFormatException, IOException, TCException
{
TCComponent tcc=(TCComponent)                                                                                                                                          AIFUtility.getCurrentApplication().getTargetComponent();
session=tcc.getSession();
session.getUser();

String filename="C:\\Temp\\SingleScheduleExcelReport.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook();
                XSSFSheet sheet = workbook.createSheet("FirstSheet");
     
                sheet.setColumnWidth(0, 6000);
                sheet.setColumnWidth(1, 6000);
                sheet.setColumnWidth(2, 6000);
                sheet.setColumnWidth(3, 6000);
               sheet.setColumnWidth(4, 6000);
               sheet.setColumnWidth(5, 6000);
     
              XSSFCellStyle mystyle=workbook.createCellStyle();
              XSSFFont myfont=workbook.createFont();
              myfont.setBold(true);
              mystyle.setFont(myfont);
              mystyle.setFillForegroundColor(HSSFColor.GOLD.index);
              mystyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
              mystyle.setBorderBottom(BorderStyle.MEDIUM);
     
              XSSFRow rowhead = sheet.createRow((short)0);
              rowhead.createCell(0).setCellValue("TASK NAME");
              rowhead.getCell(0).setCellStyle(mystyle);
     
        rowhead.createCell(1).setCellValue("START DATE");
        rowhead.getCell(1).setCellStyle(mystyle);
        rowhead.createCell(2).setCellValue("FINISHED DATE");
        rowhead.getCell(2).setCellStyle(mystyle);
        rowhead.createCell(3).setCellValue("ACTUAL START DATE");
        rowhead.getCell(3).setCellStyle(mystyle);
        rowhead.createCell(4).setCellValue("ACTUAL FINISH DATE");
        rowhead.getCell(4).setCellStyle(mystyle);
        rowhead.createCell(5).setCellValue("RESOURCE ASSIGNMENT");
        rowhead.getCell(5).setCellStyle(mystyle);
     
        fileOut = new FileOutputStream(filename);

AIFComponentContext[] children=tcc.getChildren();

TCProperty Object_Name;
        TCProperty Start_Date;
TCProperty Finish_Date;
        TCProperty Actual_Start_Date;
        TCProperty Actual_finish_Date;
 TCProperty Resource_Assignment;
 
        XSSFRow row1 = sheet.createRow((short)count);
row1.createCell(0).setCellValue("               ");
count++;
XSSFRow row2 = sheet.createRow((short)count);
        row2.createCell(1).setCellValue(children[0].toString());
        row2.getCell(1).setCellStyle(mystyle);
        count++;
        XSSFRow row3 = sheet.createRow((short)count);
        row3.createCell(0).setCellValue("               ");
        count++;
     
            for(int j=0;j<children.length;j++)
{
TCComponent taskcomp=(TCComponent) children[j].getComponent();
Object_Name=taskcomp.getTCProperty("object_name");
Start_Date=taskcomp.getTCProperty("start_date");
Finish_Date=taskcomp.getTCProperty("finish_date");
Actual_Start_Date=taskcomp.getTCProperty("actual_start_date");
Actual_finish_Date=taskcomp.getTCProperty("actual_finish_date");
Resource_Assignment=taskcomp.getTCProperty("ResourceAssignment");


    XSSFRow row = sheet.createRow((short)count);
            row.createCell(0).setCellValue(Object_Name.toString());
            row.createCell(1).setCellValue(Start_Date.toString());
            row.createCell(2).setCellValue(Finish_Date.toString());
            row.createCell(3).setCellValue(Actual_Start_Date.toString());
            row.createCell(4).setCellValue(Actual_finish_Date.toString());
            row.createCell(5).setCellValue(Resource_Assignment.toString());
            count++;
}
            workbook.write(fileOut);
fileOut.flush();
fileOut.close();
}
}

No comments:

Post a Comment