How to set Jasper to use XSSF? - jasper-reports

In a existing system already use jasper 5.0 and as I know it use poi HSSF to generate xls data, but now as the application grow up, the report have a problem with a big count transaction to generate.
I have search for the solution and found POI with XSSF. Because jasper use POI HSSF too, I thinking about to use XSSF inside of JASPER.
Is that possible? and how I could do that? I need to use jasper because it's not possible for now to change the existing app.

To export jrxml generating ooxml XSSF, excel file xlxs
Use the net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter
Example:
JasperPrint jasperPrint = JasperFillManager.fillReport(report, paramMap, connection); //Example of how to get the jasper print
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
File outputFile = new File("excelTest.xlsx");
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setOnePagePerSheet(false); //Set configuration as you like it!!
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
Naturally you need related libraries (poi-ooxml.jar, poi-ooxml-schemas.jar, xmlbeans.jar) in your classpath, they are present in the distribution of jasper report.
The JRXlsxExporter is available since version 4.5 this is the jasper report 5.5.0 API. In version 4 parameters where set instead of properties please see jasperreports-export-to-xlsx-not-xls

Related

How to load an embedded rpt file in crystal report

We have a requirement to load crystal report from embedded resource. In our application each module is a portable area and rpt files are embedded in the assembly. In the crystal report viewer we need to read the embedded rpt file and load the report document using the embedded rpt file.
Thanks in advance,
Anoop X.
Something like this?
private void SetReportSource(String reportPath)
{
object reportPathAsObject = (object)reportPath;
ReportClientDocument reportClientDocument = new ReportClientDocumentClass();
reportClientDocument.Open(ref reportPathAsObject, 0);
crystalReportViewer.ReportSource = reportClientDocument;
}

Cannot find Subreport from jar file

I have completed my java project through Netbeans with Jasper Report. I copied the files to another laptop and run the jar file, but I get an error when i run the report from the jar file pertaining to the subreport:
net.sf.jasperreports.engine.jrexception resource not found at ...path
It tried to look on the original path of the subreport where I have developed my program and reports. Now, since I want to run the program to another laptop, I dont have that path anymore. What to do? How to set the subreports to a relative path? I have this subreport expression:
$P{SUBREPORT_DIR} + "SubReport_Items.jasper"
Please help...
You can not use relative path in jasper report, that's why you normally use $P{SUBREPORT_DIR}, since the $P{SUBREPORT_DIR} is parameter, your application can use relative path and then pass the absolute path to jasper report es.
java code example
File reportDir = new File("myReportDirRealtiveToApplication"); //relative path
String absolutePath = reportDir.getAbsolutePath() + File.separator; //Convert to absolute
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("SUBREPORT_DIR", absolutePath); //Pass as parameter
pass the parameter map to your export/fill method, below is an example, naturally you will use what ever you are using currently....
JasperFillManager.fillReportToFile(jasperFileName, paramMap, myConnection); //Fill the report

Replacing aspose JRPptExporterParameter.PPT_TEMPLATE_PRESENTATION in jasperreports 5.0

I am generating a ppt report using jasperreports and aspose library (ppt exporter from aspose). I'm trying to eliminate aspose from the project and use the ppt exporter from jasperreports 5.0. The problem is that at the moment the generated report needs an external .pot file which is added using aspose:
com.aspose.slides.jasperreports.JRPptExporter exporter = new com.aspose.slides.jasperreports.JRPptExporter();
......
exporter.setParameter(com.aspose.slides.jasperreports.JRPptExporterParameter.PPT_TEMPLATE_PRESENTATION, pptTemplate);
exporter.exportReport();
I didn't find any similar parameter in JRExporterParameter from jasperreports and I couldn't find any efficient solution yet. Is there any method of using an external .pot file? I was thinking about creating a second JasperPrint object from the .pot file and then exporting both JasperPrint objects setting JRExporterParameter.JASPER_PRINT_LIST
Not sure if that fits for you, but I've written a custom PPTX Exporter (only pptx, not binary ppt), which is based on Apache POI. The POI element can be initalized by your own template pptx (not yet implemented in my version).
https://code.google.com/p/pptx-shape-exporter/
Drop me a line, if this sounds interesting to you.

API to get Crystal RPT version

In the Crystal Studio, I can get to the version of an rpt file by going to Report|Performance Information|Report Definition|File Format Schema.
Is there a way of getting to this same information via the Crystal .NET API?
I can't find it for the life of me.
OLIVER
Check out ReportDocument.ReportClientDocument.MajorVersion and MinorVersion. You'll need to add a reference to CrystalDecisions.ReportAppServer.ClientDoc to access it.
using(var rptDoc = new ReportDocument())
{
rptDoc.Load(path);
Console.WriteLine(rptDoc.ReportClientDocument.MajorVersion);
}

Crystal Report .NET font changing

I've designed a crystal report that will be sent to a specific (barcode) printer through a web interface. Allowing the report to be generated in the standard crystal report viewer was causing issues, so I am now using the code-behind to send the report directly to the printer.
ReportDocument Report = new ReportDocument();
ParameterDiscreteValue Order = new ParameterDiscreteValue();
Order.Value = Convert.ToInt32(txtOrder);
Report.Load(reportPath);
Report.SetParameterValue("OrderNo", Order);
PageMargins margins;
margins = Report.PrintOptions.PageMargins;
margins.bottomMargin = 0;
margins.leftMargin = 0;
margins.rightMargin = 0;
margins.topMargin = 0;
Report.PrintOptions.ApplyPageMargins(margins);
Report.PrintOptions.PrinterName = "\\\\printserver\\Zebra Z6M Plus (300dpi)";
Report.PrintToPrinter(1, false, PageNum, PageNum);
Report.Close();
When printed from the designer (CRXI) everything works fine but when the web interface sends the job to a printer (any printer) it changes the font to Times New Roman which messes up all of the field sizes. If I use the standard .NET report viewer it uses the correct font, so I'm pretty sure the change is being caused by creating/using the ReportDocument.
How can I send the report directly to a print without it defaulting the fonts back to Times New Roman?
This idea occured to me:
Instead of sending the report straight from Crystal to the printer, what if you use some kind of middleman, i.e. export the .rpt to .pdf first, then print the PDF?
(Yes, it would be a very "wooden tables" tables approach, but if it works, it works.)
While it seemed like the special font I was using had been included on every server imaginable, I was never able to get it to work through the web interface.
I ended up finding a standard windows font that mostly suited the needs of this project and have given up on trying to beat this problem.
You need use RAS SDK API. Crystal Reports for Visual Studio 2010 (v13) include this api. (This code don't work in Crystal Reports for Visual Studio 2005... I don't have info about other versions)
Add this references to your existing code:
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.ReportAppServer.ReportDefModel
And use this code (VB... sorry)
Using rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load(file, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)
rpt.SetDataSource(_ReportSource)
Dim options As New CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions
options.Collated = _Collate
options.NumberOfCopies = _Copies
' TODO: Implement_startPageN and _endPageN
Dim optPrint As CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions
optPrint = rpt.ReportClientDocument.PrintOutputController.GetPrintOptions
optPrint.PrinterName = _PrinterName rpt.ReportClientDocument.PrintOutputController.ModifyPrintOptions(optPrint)
rpt.ReportClientDocument.PrintOutputController.PrintReport(options)
rpt.Close()
End Using
I was trying to change Crystal Report Font according to data that will be shown on the report.
I use Formate Formula to change the font using flags Condition.
if({?vIsRightToLeft}=true)then
"Attari Font"
Else
"Arial"