//This will create excel report of mutliple schedule task stored in folder.
import java.io.FileOutputStream;
import org.apache.poi.hssf.util.HSSFColor;
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.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
public class CreateReport {
int count=1;
FileOutputStream fileOut ;
public CreateReport() throws Exception
{
AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
session.getUser();
String filename="C:\\Temp\\ScheduleExcelReport.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);
TCComponentQueryType querytype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query=(TCComponentQuery) querytype.find("General...");
String[] EntryName={"Name","Type"};
String[] EntryValue={"ScheduleFolder","Folder"};
TCComponent[] comp=query.execute(EntryName, EntryValue);
if(comp[0] instanceof TCComponentFolder)
{
AIFComponentContext[] context=comp[0].getChildren();
TCProperty Object_Name;
TCProperty Start_Date;
TCProperty Finish_Date;
TCProperty Actual_Start_Date;
TCProperty Actual_finish_Date;
TCProperty Resource_Assignment;
for (int i = 0; i < context.length; i++)
{
TCComponent tcc=(TCComponent) context[i].getComponent();
if (tcc instanceof TCComponentSchedule)
{
AIFComponentContext[] children=tcc.getChildren();
AIFComponentContext[] SecChi=children[0].getComponent().getChildren();
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<SecChi.length;j++)
{
TCComponent taskcomp=(TCComponent)
SecChi[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();
}
}
import java.io.FileOutputStream;
import org.apache.poi.hssf.util.HSSFColor;
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.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentQuery;
import com.teamcenter.rac.kernel.TCComponentQueryType;
import com.teamcenter.rac.kernel.TCComponentSchedule;
import com.teamcenter.rac.kernel.TCProperty;
import com.teamcenter.rac.kernel.TCSession;
public class CreateReport {
int count=1;
FileOutputStream fileOut ;
public CreateReport() throws Exception
{
AbstractAIFApplication app=AIFUtility.getCurrentApplication();
TCSession session=(TCSession) app.getSession();
session.getUser();
String filename="C:\\Temp\\ScheduleExcelReport.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);
TCComponentQueryType querytype=(TCComponentQueryType) session.getTypeComponent("ImanQuery");
TCComponentQuery query=(TCComponentQuery) querytype.find("General...");
String[] EntryName={"Name","Type"};
String[] EntryValue={"ScheduleFolder","Folder"};
TCComponent[] comp=query.execute(EntryName, EntryValue);
if(comp[0] instanceof TCComponentFolder)
{
AIFComponentContext[] context=comp[0].getChildren();
TCProperty Object_Name;
TCProperty Start_Date;
TCProperty Finish_Date;
TCProperty Actual_Start_Date;
TCProperty Actual_finish_Date;
TCProperty Resource_Assignment;
for (int i = 0; i < context.length; i++)
{
TCComponent tcc=(TCComponent) context[i].getComponent();
if (tcc instanceof TCComponentSchedule)
{
AIFComponentContext[] children=tcc.getChildren();
AIFComponentContext[] SecChi=children[0].getComponent().getChildren();
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<SecChi.length;j++)
{
TCComponent taskcomp=(TCComponent)
SecChi[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