JasperReports: How to define a header in Excel - excel

I'm cleaning up a legacy application which uses Jasper Reports 3.1.2, and am trying to figure out how to define a header that shows up as the header in the generated Excel spreadsheet (under Page Setup, Header/Footer). The existing code already does this for the footer using:
exportParameters.put(JRXlsAbstractExporterParameter.LEFT_FOOTER, "My footer text");
I can't find an equivalent parameter for the header in the JRXlsAbstractExporterParameter class.
Is there a way to do this in the JRXML template, or via the API ?
Adding a screenshot from the generated Excel report which shows that Excel detects the footer that was defined in the JRXlsAbstractExporterParameter class (code above). I am trying to do the same with the header.

Looking at JasperForge Config Reference, the JRXML header and footer properties are not supported until 3.7.5. In my opinion, it would be easier upgrading to at least version 3.7.5 to accomplish what you're attempting, update your jrxml files, and do regression testing with your existing reports. If upgrading is not possible and you're familiar with POI or JExcelAPI, I would suggest extending the JRXlsExporter or JRExcelApiExporter (limited to two links...sorry) and use custom exporter parameters in your API.
The version of Jasper Reports you're using really limits what you can do in excel. If you do upgrade, you may want to research the XLS properties available in versions above 4.0. If you're going to be doing more excel specific formatting with your existing reports, it would be more beneficial to uprade to a version higher than 4.0.

Related

XSSFWorkbook.setActiveSheet() equivalent in JasperReports?

We're using JasperReports 6.13.0 to generate XLSX format reports. We have a requirement where we need to show a particular sheet as default visible(instead of the first sheet) whenever the user opens the generated XLSX report.
My question is, do we have this feature in JasperReports? I couldn't find anything related to it in the documentation.
Note: In Apache POI, we can achieve this functionality using: XSSFWorkbook.setActiveSheet(int index)
JasperReports doesn't currently include this feature.
You can consider patching the JasperReports code to add it. What you would need to do is to add something like the following line in XlsxWorkbookHelper.exportHeader after the line with workbookPr.
write("<bookViews><workbookView activeTab=\"" + activeSheet + "\"/></bookViews>\\n");
You'd also need to pass the active sheet index somehow from the exporter.
Alternatively, you can export to XLSX using JasperReports and then open the file with POI and set the active sheet.

How to get OleDb for reading excel in asp.net core project

Is there any way of reading excel data in ASP.NET Core (built over .Net Core)? I am not able to refer OleDB in project.json of my .net core project. Is there any other way of doing this?
Do you really need OleDB to read Excel today? To my opinion, OleDB is a bit outdated. There are opensource libraries to work with Excel files which are much easier to use and provide a lot of flexibility.
ClosedXML (https://closedxml.codeplex.com/) is one such library. It's well documented and allows to both read and write Excel files with custom cell style formatting.
I have used OleDB for reading very large Excel files too, it works but there are certain issues with it, here are a few of them off the top of my head:
You will need to install MS ACE OLEDB provider which sometimes is hard to configure.
You will have to read Excel files in passes while with ClosedXML you can access rows/cells randomly by id/address.
OleDB uses a Windows registry configurable setting to check the number of rows (default is 8) to determine the data type for the whole column and sometimes there are issues with it because the data type is determined incorrectly. ClosedXML allows you to set a specific data type for any cell.
I'm not a ClosedXML developer, so this is not an ad. As I mentioned, I have used (and continue to use) both OleDB and ClosedXML in my projects. With OleDB I was able to read very large Excel files (400-800K+ of rows for example) either row by row or using SQL Server "SELECT * FROM OPENROWSET(...)". Also SQL Server can directly write to Excel files using same ACE provider and it worked for very large files too.
However, ClosedXML I have used for reading/writing relatively small files but they used a lot of custom formatting. So if you start a new project I would recommend going away from OleDB.
The only limitation of ClosedXML is that it support only zipped XML Excel files, i.e. Excel version 2007+. You can find many examples on the ClosedXML site mentioned above which would help you to get started.
Let me know if this was helpful. Thanks.
As indicated by andrews, it is recommended to use a third-party library, especially when working with formatting. An alternative to ClosedXML is EPPlus. For most of my project I have used ClosedXML, but I had to switch to EPPlus because it has support for charts.
For ASP.NET Core, you can use EPPlus.Core. I have performed a quick test within an ASP.NET Core 2.0 console app and it seems to work fine:
var newFile = new FileInfo("some file.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(newFile))
{
var ws = xlPackage.Workbook.Worksheets.Add("etc");
ws.Cells[1, 1].Value = "test";
// do work here
xlPackage.Save();
}

Exporting data to existing Excel file

I have a system with an Excel spreadsheet template file which is used for invoicing. I would like the user to be able to click a button on an Xpage, which will then open the spreadsheet and enter the latest invoicing data in Excel. I don't mind if Excel is either the application on their machine or on the server, but my preference would be the application locally on their machine.
I've looked into Xagents, as I feel this is probably the answer. I know they can be used to create Excel but I have not been able to locate any mention of opening an Excel file, and entering data into specific cells.
Is this possible?
EDIT: you can use Apache POI for editing and creating Microsoft Office documents. This is a java project which gives you a handle to office documents and this can be used using java.
A good starting point can be the blog of Christian Guedemann from webgate:
http://guedebyte.wordpress.com/2012/09/17/documents-and-spreadsheets-with-xpages-building-the-kernel-part-ii/
(end of edit)
The only way I KNOW and tried to write data from Notes to Excel is exporting the data to an HTML page and setting the Content Type accordingly (e. g. as described here (there are a lot more resources available for taht):
http://www.dominoguru.com/pages/developer2010_xpagexlsexport.html
I am not sure if this is of help but it seems that this project can help you:
http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=ZK%20Spreadsheet%20for%20XPages
As far as I can see this project can load Excel files from XPages - and then it should also be possible to edit the files.
Besides that the only solution I can think of is a Notes Agent that is called from the XPage. This agent can then run in background and do all the excel stuff. After running, the XPage can show a link to the Excel file. Actually this is the solution I would consider to implement - but maybe others step in with better answers here.
You don't want to introduce a dependency on Excel in your application -- wouldn't work with an iPad front-end. Rather have a look at the ZK Spreadsheet, it will fulfill your needs.
However if you have to have Excel, then you need a roundtrip solution: load the Excel from an URL (probably generated by an XAgent (?) and save it back. The saving back part is the tricky one. Normal HTTP doesn't allow that. What you need there is a webDAV capable server. Watch out for a project on OpenNTF soon (just clearing IBM legal) that provides webDAV.
However the ZK Spreadsheet looks much better for your needs.
I have a sample database at the following URL --> http://www.nnsu.com/nnsusite.nsf/%24%24OpenDominoDocument.xsp?documentId=B65507CB2DE15B3286257986005F061D&action=openDocument
Download the APCC.nsf. This will allow you to create/read a new EXCEL spreadsheet and then stream the resulting file to the requesting browser. There is not need to have EXCEL or office installed on the Server.
THe examples create a new workbook, but you can also store a "template" on the server or in a notes document and use it as a starting point and then save it to a document or stream it to the requesting browser.
With Apache POI you can read/write to a spreadsheet using data from the notes document the process is initiated from.

Dynamically create a MS Word report using a JIRA charts?

Each month I have to manually create a report for my team. For this I use a combination of numbers generated from a groovy script I've written, screenshot, cut & paste from a series of charts in our JIRA instance and cut and pasted excel charts.
I'm finding it more and more boring to do this by hand and I suspect that there is an easier way to automatically generate this report. I can generate the word document with data from the groovy script using this application (http://www.docmosis.com/) but I have not yet found a way of auto including JIRA charts in the generation or excel so my question is:
Is it possible to generate a word document that contains generated data from various sources including (in order of importance):
JIRA charts
Programmatically generate data and
Excel charts?
As you already coded your logic in Groovy, best would be skipping the Excel step and generate your report directly from JIRA using the JIRA PDF View Plugin. This plugin will reduce your work to a single click and download you a nice PDF document (PDF is more portable than Word docs).
These short tutorials help you:
Reuse your Groovy scripts for reporting logic (also see the "Charts" tutorial there)
Bring the data, charts and the template together
Update 2 years after my original answer:
JIRA PDF View Plugin 3.5.0+ can also export JIRA charts (gadgets in JIRA dashboards, to be precise). So, now you can execute your Groovy scripts, include JIRA charts and bring all the result together in a professional PDF document.
Even better, now there exists a free plugin that will make the monthly process 100% automatic for you! It will generate your PDF document and send that to your team members' mailboxes, according to the preferred schedule (CRON trigger).
Related tutorials:
Exporting JIRA dashboards to PDF
Automating JIRA PDF exports
Discl: I'm a developer working on these products, yet this is the best solution to your problem. :-)
Most of the charts generated in Jira are created from data returned from search results. So you can get data from Jira using REST or SOAP api and generate your own charts by other means.
I am not sure if there is a no-coding method of doing it. But I would write a C# program that adds data to the Word template from your sources (Jira, other programs, Excel). And would create a template that generated charts from inserted data.
For Word document generation I would have a look here -http://www.codeproject.com/Articles/20287/Generating-Word-Reports-Documents
For chart creation in the document I would have a look here - http://office.microsoft.com/en-us/word-help/create-a-chart-in-a-document-HP005190046.aspx
Easiest if you convert your JIRA chart to an image first. When you say JIRA chart, do you mean something from this plugin?
Once you have an image, your document generation tool ought to be able to include that.
There are many document generation tools which can include programmatically generated data, and some of those can include Excel charts.
There is now a JIRA plugin to generate charts in Word documents which may help you.
https://marketplace.atlassian.com/plugins/com.clariostechnology.officecharts.officecharts
There is now also Intelligent Reporter for JIRA which is a no-code method for creating word documents from your JIRA data, including native Word charts with full formatting from JIRA data.
https://marketplace.atlassian.com/plugins/com.clariostechnology.intelligentreports
Disclaimer: I work for the company that created this plugin. If there is anything you need that it cannot do, please let me know.

How best to export native data to Excel without introducing dependency on Office?

Our product has the requirement of exporting its native format (essentially an XML file) to Excel for viewing/editing. However, what this entails is having a dependency on Excel (or Office) itself for our product build - something that we do not want.
What we have done is export the data from our native format to a csv file which can be opened in Excel. If user selects an option to open the generated report as well, we (try to) launch Excel application to open it (ofcourse it requires Excel to be already present on the client system).
The data for most part is flat list of records.
Is there a better format (or even a better way) to handle this requirement? This is a common requirement for many products - how do you handle this?
Excel versions, both 2007 and several previous, have native XML formats. 2007, obviously, is XML by default, and earlier versions have the ability to save as XML. This SO question deals with the issue. I'd guess a little inspection would give an idea of what's required. I don't know if a XSD/DTD exists for older versions, but a little creative Googling might yield something.
As other people pointed out, it is reasonably easy to generate Excel XML files. You can do this in multiple ways. For example:
By creating a template Excel XML document, and then using XML DOM to stuff your data into the template, or
Converting the template Excel XML into an XSLT, and then simply passing your proprietary XML as input to XSLT.
I'm using ExcelPackage to create spreadsheets in one of my side projects. Works pretty good, but (at least the version I'm using) its a bit limited when it comes to styling and calculations.
ExcelPackage lets you create OOXML docs (.xslx files) that are natively compat with 2k7, but you can download a plugin for previous versions of Office from MS.
We export our data either using Excel objects (COM based code) on client side or CSV file (usually on server side, but can be used on client side too). And we allow copy data from grids in simple html format, what can be pasted into Excel without problems.
For one customer we even had to export data [from sql stored procedure] into csv-like tab-separated format, but named file like xxxxx.xls - this way excel opened that file in more correct way than csv file. Ugly hack, but worked well.
CSV is most compatible format (no dependencies on external applications or libraries), but customers don't like it. Maybe we need to incorporate some XLS export code, this way all users will be happy :)
If .csv isn't formatted enough, you could create a template in Excel, and use a little bit of VBA code to import the CSV and format it appropriately. This way your app is only concerned with generating the .CSV, and will use the same .XLS for each export.
If you're careful, you should be able to get this to work with most versions of Excel seamlessly.
With Perl there are several modules that can be used to produce .xlsx files without requiring an Office installation. Among those :
https://metacpan.org/pod/Excel::Writer::XLSX is the most well-known, with support for many Excel features like colors, formatting, etc.
https://metacpan.org/pod/Excel::ValueWriter::XLSX (I'm actually the author) has less features but is optimized for fast writing of large amounts of data
If you are working in Java, Checkout the POI project from APACHE.
http://poi.apache.org/
Simple, nice, complete, powerful.
We started with Office on the server, but that's not very nice. We had to kill processes that hung, and had quite a bit of a performance dip. We thought about putting it on a different machine, but didn't bother after trying and using Aspose (commercial). We don't have a very large number of simultaneous users, but complex documents. Simple ones can be handled easier with csv.
I've used FlexCel Studio for a couple of projects now. It's very functional and fast. 100% managed code, no dependencies. Sounds like you'd use the "Reports" feature which allows you to define an empty report template in Excel, then pass datatable and volia, it's populated with your data.
TMS Software
We use a combination of OleDB and Interop. We found that Interop was much faster and used less memory, but it's a pain for compatibility issues, especially when using different language installs of Office.
OleDb has the advantage that you don't require Excel to be installed on the client machine. Both Interop and OleDb support multiple sheets (tables) per workbook which you cannot do with csv.
If you're using C# or VB.Net, and your data is in a a DataSet, DataTable or List<>, then you can use my free "Export to Excel" class.
It uses the free Microsoft OpenXML libraries (so you don't need to have Excel on your server), and lets you export your data into a "real" .xlsx file with just one line of code, eg:
DataSet ds = CreateSampleData();
CreateExcelFile.CreateExcelDocument(ds, "C:\\Sample.xlsx");
All source code is provided on the following page along with a demo project, completely free of charge (and popups !)
http://mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
Hope this helps !

Resources