jasper reports table creation - jasper-reports

I would like to create a table in my Jasper Report.
This could be done (and it is done :-) ) in iReport, but the content of the table (for example names of the columns) are changing, so I would like to create the report solely from JAVA code (by not using jrxml files).
How is it possible?
So far, this is what I have done (the main parts only):
//table component
final StandardTable table = new StandardTable();
final StandardColumn col1 = new StandardColumn();
final DesignCell col1Header = new DesignCell();
final JRDesignStaticText textElement = new JRDesignStaticText();
col1Header.addElement(textElement);
col1.setDetailCell(col1Header);
table.addColumn(col1);
/datasource
final JRDesignDatasetParameter param = new JRDesignDatasetParameter();
param.setName("REPORT_DATA_SOURCE");
final JRDesignExpression exp = new JRDesignExpression("$P{REPORT_DATA_SOURCE}");
param.setExpression(exp);
//datasetrun
final JRDesignDatasetRun drs = new JRDesignDatasetRun();
table.setDatasetRun(drs);
drs.addParameter( param );
How to continue?
Thank you,
krisy

In case anyone stumbles upon the same problem (and for future myself :-) ) here is how to continue the code above, to add a table element to the summary of the report:
//create reportElement (inside componentelement)
JRDesignComponentElement reportElem = new JRDesignComponentElement();
//reportElem.setKey("table");
reportElem.setComponentKey(new ComponentKey("http://jasperreports.sourceforge.net/jasperreports/components", "jr", "table"));
reportElem.setComponent(table);
reportElem.setHeight(100);
reportElem.setWidth(100);
//add to summary
jRSummary.addElement(reportElem);
(the hard part was to find out how to create the ComponentKey object)
Note: in order to use the table, the subdataset element needs to be created as well.

For htmlComponent the ComponentKey should be:
new ComponentKey("http://jasperreports.sourceforge.net/htmlcomponent", "jr",
"html");

Related

Birt Conditional Page Break

I'm designing a BIRT report that should print on a form. In this report it is printing in both sides so the client is asking to do a Page Break if the details of a WorkOrder ends in a odd number so both WorkOrders wouldnt be in the same sheet.
Is it possible to add a pagecount() and do a page break if it is the end of the work order an its an odd number?
Thanks in advance.
I only have part of the answer. It would be possible on the adding pagination in the beforeFactory on the ReportDesign section. Out of the box Maximo reports have a pagination statement for PDF's. You can extend the if statement - see example of OOTB code below.
You would need to be able to bring back the WO number as a global parameter. That part is what you would need to do some additional research on.
if ( (reportContext.getParameterValue("usepagebreaks") == "false")|| reportContext.getOutputFormat() == "pdf" ) {
// Give each table in the report a name, and add the names to the list below, e.g. ["mainTable", "childTable1"]
var tableListing = ["dataSet_inventory_id13#"];
for each(var tableName in tableListing) {
var table = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement(tableName)
if (table != null) {
table.setProperty("pageBreakInterval", 0);
}
}
}

combine multiple reports in crystal reports in c#

I have designed a crystalReport(myReport.rpt) that is connected to data base without any problem. What I want is to create a report including multiple of this report...!
For example creating a 3-pages report that each page is built by myReport.rpt but with different values...
In fact I want to create some objects from my report class and then combine all of them to be one report and I print that or make pdf from that...
Example:
myReport rpt1= new myReport(); //(some changes in rpt1's fields):
(TextObject)rpt1.ReportDefinition.ReportObjects["time"]).Text=getTime();
((TextObject)rpt1.ReportDefinition.ReportObjects["date"]).Text =getDate();
// or any other changes in fileds
myReport rpt2= new myReport(); //(some changes in rpt2's fields):
(TextObject)rpt2.ReportDefinition.ReportObjects["time"]).Text = getTime();
((TextObject)rpt2.ReportDefinition.ReportObjects["date"]).Text = getDate();
// or any other changes in fileds...
myReport rpt3= new myReport(); //(some changes in rpt3's fields):
(TextObject)rpt3.ReportDefinition.ReportObjects["time"]).Text = getTime();
((TextObject)rpt3.ReportDefinition.ReportObjects["date"]).Text = getDate();
// or any other changes in fileds...
and I want something like this:
CrystalDecisions.CrystalReports.Engine.ReportDocument totalReport=new CrystalDecisions.CrystalReports.Engine.ReportDocument();
totalReport=merge(rpt1,rpt2,rpt3);
totalReport.PrintToPrinter(1, ture, 1, 1);
Thank you for your helping...
I'm using:
VS 2012 & Crystal Reports 13

Controlling table row height for document in poi

I am trying to draw a table in poi using XWPF component using the below code
// InputStream in= Temp.class.getResourceAsStream("Sample.docx");
XWPFDocument doc = new XWPFDocument();
XWPFTable table=doc.createTable(2,2);
// CTDecimalNumber rowSize = table.getCTTbl().getTblPr().getTblStyleRowBandSize();
// rowSize.setVal(new BigInteger("10"));
// table.getRow(1).setHeight(0);
table.getRow(0).getCell(0).setText("Row-0-Cell-0");
table.getRow(0).getCell(1).setText("Row-0-Cell-1");
table.getRow(1).getCell(0).setText("Row-1-Cell-0");
table.getRow(1).getCell(1).setText("Row-1-Cell-1");
FileOutputStream out = new FileOutputStream("simpleTable.docx");
doc.write(out);
out.close();
It draws the table properly but The height of the cells are too big and width also does not falls properly in place. I saw in a note that the table are supposed to auto fit as per the content. Tried couple of things which are as follows:
Tried setting the height as shown in the commented code above but
that did not worked.
Tried reading an existing doc as shown in
inputstream commented code. That gave an exception that could not
read a poi-ooxml file.
Tried using TblStyleRowBandSize but that
always remains null. Not sure how to create a new instance of
CTDecimalNumber or TblStyleRowBandSize
thanks in advance.
Some more insight:
When I create an empty table, and add rows and column by using create, it works fine and does not inserts the formatting character. But making an empty table results in a cell created at the begining and I am still trying to find a way to remove that first column. New code
XWPFTable table=doc.createTable();
XWPFTableRow row1 = table.createRow();
row1.createCell().setText("Row-0-Cell-0");
row1.createCell().setText("Row-0-Cell-1");
XWPFTableRow row2 = table.createRow();
row2.createCell().setText("Row-1-Cell-0");
row2.createCell().setText("Row-1-Cell-1");
I'm not sure on most of your query, but I can help with the last bit, you'll want something like:
if(! table.getTblPr().isSetTblStyleRowBandSize()) {
table.getTblPr().addNewTblStyleRowBandSize();
}
System.out.println("Was " + table.getTblPr().getTblStyleRowBandSize().getVal());
table.getTblPr().getTblStyleRowBandSize().setVal(new BigInteger("12345"));
System.out.println("Now " + table.getTblPr().getTblStyleRowBandSize().getVal());

Crystal Report on C#

Well I have a Cyrstal report which has 4 sub reports on and it is linked through an ItemID column and a Culture, so it has a parameter value "?Pm-ItemID" and "?Pm-Culture" now i'm using DataSet to load the data to the Crystal Report's datasource, when I run the report its giving me an error which was an asking parameter field was not suplied, so i think my question would be what am I going to pass to those ParameterFields?
here's an idea.
ReportDocument myreport = new ReportDocument();
myreport.Load("C:\MyReport.rpt");
DataSet ds = GenerateReportData();
myreport.SetDataSource(ds);
//Loop through each to Load the DataSet
for (int i = 0; i < myreport.Subreports.Count; i++)
{
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
}
//I can see that there's a parameterfields in myreport.ParameterFields
//As I look through inside it there are 8 ParameterFields repeating Pm-ItemID and Pm-Culture
foreach (ParameterField pf in myreport.ParameterFields)
{
myreport.SetParameterValue(pf.Name, Value???);
}
Well, I see what's wrong.
ReportDocument subreport = myreport.SubReports[i];
DataSet subds = GenerateReportData(subreport.name)
subreport.SetDataSource(subds);
should not be done this way, it should be
DataSet subds = GenerateReportData(subreport.name)
myreport.SubReports[i].SetDataSource(subds);
I don't know about Crystal, but in SSRS it works like this:
1) create a subreport and create some parameters
2) create the main report, put there the subreport and in the properties you can specify what to bind to the subreport's parameters
Conclusion: I don't think this is supposed to be set in code, rather report designer.

Sync Services Ado.net SyncSchema

I'm trying to build a custom ServerSyncProvider
right now. I'm trying to understand the GetScema Method.
I'm trying to build a dataSet and associate it to SyncSchema class
one of my table columns is a nvarchar(50).
Here is what I'm doing this:
DataColumn column = new DataColumn();
column.ColumnName = "Name";
column.DataType = typeof(String);
column.MaxLength = 55;
table.Columns.Add(column);
But it turns out that on my client side, this column becomes nvarchar(1)
any idea?
Thanks a lot for helping me.
Use this code:
column.ExtendedProperties.Add("ColumnLength", 50);