Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Changing column decimal format with the DE
b2tech
Hello:
Anyone have any luck using the DE to modify a table column to change the format for a given column to a specified number of decimal places?
I am trying to pass from a user report GUI interface the number of decimal places to display for each column. (I have 10 columns of decimal data to display) This number will pass into my java program (that creates the *.rptdesign file) which selects the library table, and then locates the table column in question, and modifies the format.
Anyone have an example of doing this - ie. getting table, getting column, flipping from 2 decimals to 4
Thanks
BillH
Find more posts tagged with
Comments
JasonW
Bill
Try code like this (with attached report):
package DEAPI;
import java.util.HashMap;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.HTMLCompleteImageHandler;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.RenderOption;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.DesignElementHandle;
import org.eclipse.birt.report.model.api.LibraryHandle;
import org.eclipse.birt.report.model.api.DesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.StyleHandle;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.elements.structures.IncludedLibrary;
import org.eclipse.birt.report.model.api.elements.structures.NumberFormatValue;
import org.eclipse.birt.report.model.elements.ReportDesign;
import com.ibm.icu.util.ULocale;
public class ModTable {
public void runReport() throws EngineException
{
IReportEngine engine=null;
IDesignEngine dengine=null;
EngineConfig config = null;
try{
config = new EngineConfig( );
config.setBIRTHome("C:\\birt\\birt-runtime-2_5_1\\birt-runtime-2_5_1\\ReportEngine");
config.setLogConfig(null, Level.FINE);
config.setResourcePath("C:\\work\\workspaces\\BIRT2.2SrcExamples\\APIs\\Reports");
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
DesignConfig dconfig = new DesignConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_5_1/birt-runtime-2_5_1/ReportEngine");
IDesignEngineFactory dfactory = (IDesignEngineFactory) Platform
.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dengine = dfactory.createDesignEngine( dconfig );
IReportRunnable design = null;
//Open the report design
SessionHandle session = dengine.newSessionHandle( ULocale.ENGLISH );
design = engine.openReportDesign("Reports/tabledataformat.rptdesign");
ReportDesignHandle report = (ReportDesignHandle) design.getDesignHandle( );
ElementFactory elementFactory = report.getElementFactory( );
TableHandle th = (TableHandle)report.findElement("mytable");
RowHandle row = (RowHandle) ( th.getDetail( ).get( 0 ) );
CellHandle cell = (CellHandle) ( row.getCells( ).get( 3 ) );
DataItemHandle dih =(DataItemHandle)cell.getContent( ).get(0);
NumberFormatValue formatValueToSet = new NumberFormatValue( );
formatValueToSet.setPattern( "###0.0" );
formatValueToSet.setCategory("Custom");
dih.clearProperty(StyleHandle.NUMBER_FORMAT_PROP);
dih.setProperty( StyleHandle.NUMBER_FORMAT_PROP, formatValueToSet );
report.saveAs("reports/modtabledataitemformat.rptdesign");
//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFileName("output/desample/changedatadecimalformat.html");
options.setOutputFormat("html");
options.setImageDirectory("resample/images");
//options.setBaseImageURL(baseImageURL)
task.setRenderOption(options);
task.run();
task.close();
session.closeAll(false);
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
ModTable ex = new ModTable( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}