Hi, Folks,
I use IDataExtractionTask to extract
result set, and want output CSV file.
My result set only shows EmployeeNumber
and LastName, please see attached pdf file. The generated pdf file is perfect.
I got this result when I use iExtractResults.nextResultIterator(
) to print result set.
row["EMPLOYEENUMBER"] ,
row["LASTNAME"] ,
1002 , Patterson , null , null ,
null , null , null , null , null , null , null , null , null
null , null ,
I am not sure what is wrong? Please help.
I expected result that should be like this:
----------------------------------------------------------------------------
EMPLOYEENUMBER,
LASTNAME
1002,
Murphy
1056,
Patterson
1076,
Firrelli
1088,
Patterson
1102,
Bondur
1143,Bow
1165, Jennings
1166,
Thompson
1188,
Firrelli
I use resultItem.getResultMetaData().getColumnName(i)
to print column’s name. But how do take row[ ] out without my coding.
The following is my code
public void runDataExtraction()
{
try
{
//Open previously created report document
IReportDocument iReportDocument = reportEngine.openReportDocument( docFile );
//Create Data Extraction Task
IDataExtractionTask iDataExtract =
reportEngine.createDataExtractionTask(iReportDocument);
//Get list of result sets
ArrayList resultSetList = (ArrayList)iDataExtract.getResultSetList( );
System.out.println("resultSetList " + resultSetList.size() );
//Choose first result set
IResultSetItem resultItem = (IResultSetItem)resultSetList.get( 0 );
String dispName = resultItem.getResultSetName( );
iDataExtract.selectResultSet( dispName );
for (int i=0; i< resultItem.getResultMetaData().getColumnCount( ); i++)
{
System.out.print( resultItem.getResultMetaData().getColumnName(i) + " ,
" );
}
System.out.println("");
IExtractionResults iExtractResults = iDataExtract.extract();
IDataIterator iData = null;
if ( iExtractResults != null )
{
iData = iExtractResults.nextResultIterator( );
//iterate through the results
if ( iData != null )
{
int n = 0;
StringBuffer sb = new StringBuffer();
String new_pair = "";
while ( iData.next( ) )
{
sb.append( new_pair );
Object
objColumn;
try{
objColumn = iData.getValue(n++);
sb.append(objColumn);
sb.append(" , ");
}catch(Exception e){
objColumn = new String("");
}
}
System.out.println( sb.toString() );
iData.close();
}
}
iDataExtract.close();
}catch( Exception e)
{
e.printStackTrace();
}
}