Jasper Server - MSWord Exporting Multiple Files - java

Would like to export word file - one file for each record. Something similiar to Excel one sheet per page type option.
Jasper Does a great job with this in regards to generating the DOCX file - but it puts all pages in one file.

Jasper Reports does not have a built in function to do this. It is designed to export one file at a time. What you can do is actually do this in your java code. It would require you getting your data, and looping through each row and exporting it yourself. You would be able to reuse your JasperDesign object though and not have to reinitialize it on every loop.

Related

Possible to automate an excel process using java?

My current program is trying to download files and then combine them into one large excel file. The issue that I'm struggling with is that the website I'm downloading them from is for some reason making them .html files, but appending the .xls extension to them. This allows them to be opened by Excel manually but does not allow me to use Apache POI in order to read them as it sees a file format/extension difference. My process is as follows:
1 - Run part of my program which downloads a file through my web browser using Selenium - This works fine
2 - Manually open each downloaded file and Save-As xlsx files (Note: When I open them in Excel manually is when I'm told there is a file format/extension difference just to be clear)
3 - Run the rest of my program which combs through each new file (the ones created in step 2) and appends all the data to the ultimate output file - This works fine
Is there any way to automate the process or am I going to have to continue to do it manually?
you said in the comment that you opened the file in text editor and saw that it is HTML5.
I would use HTML parser like jsoup to get the data that you need and create a new file using Apache POI.
You can use EasyXLS library. It allows to read HTML files and save as XLSX.
ExcelDocument workbookForXLSX = new ExcelDocument();
for (int i=0; i<fileCount; i++){
ExcelDocument workbookForHTML = new ExcelDocument();
workbookForHTML.easy_LoadHTMLFile(filePath[i]);//or stream to the file
workbookForXLSX.easy_addWorksheet((ExcelWorksheet)workbookForHTML.easy_getSheetAt(0));
workbookForHTML.Dispose();
}
workbookForXLSX.easy_WriteXLSXFile(filePathXLSX);
workbookForXLSX.Dispose();
You can download the Excel library for Java from:
https://www.easyxls.com/java-excel-library
More details about reading HTML files and what HTML tags are supported at:
https://www.easyxls.com/manual/basics/import-from-html-file-format.html

Export from JasperReports to Excel with more than 65532 rows

How to export a JasperReport report to xls with more than 65532 rows? It's possible to split the data in multiple worksheets? The JasperReports version is 4.0.1 and can't be updated (or changed).
Yes. All of these are possible.
What you need, to split the content on multiple sheets is to set a page break in the report, where you know it need's to start at, and set on the properties file, as well.
P.S.
If you want to see some code example, first show me some of your code. Just for a better adjusts and customization.

putting an xls file in a jar

I have an xls spreadsheet that I'm querying using metaModel, and I want to keep the xls file in the jar, because it won't be updated. The method used for creating the data context doesn't allow inputstreams, I tried using this code:
DataContext dataContext = DataContextFactory.createExcelDataContext(getClass().getResourceAsStream("database.xls"));
Unfortunately this doesn't work, as the method createExcelDataContext doesn't take inputstreams as a parameter. Is there any way to keep the file in the jar?
It seems the easiest way to do this is just export to csv, as this is easily done.
Given that other kinds of contexts can be created from an InputStream, I would guess that it's a limitation of Excel, and that you won't be able to open the Excel file if it isn't on the file system.
Consider extracting the file from the jar and copy its content to a temporary file, possibly deleted when the application ends. See File.createTempFile() and File.deleteOnExit().

Automatically update database when new excel sheet is added in a folder

I need to write one java program which monitors a folder containing excel sheets (.xls format) . Once a new excel sheet is added I have to update the database in db2 and move the excel sheet to other place.
Please suggest
It sounds like you need to get notified if files appear in a directory. Java 7 has good support for this, see this article about the Watch Service API. The db2 part, well it isn't clear what you mean by "update", but likely you want to parse the content of the xls file and make some database updates. Apache POI is a good starting place for reading the content of the file into a Java process.

Is it possible using apache poi to load data from an open excel file that is constantly updating?

I have this Java program that uses apache poi to load data from an excel file.
Problem I'm facing is I can't seem to load data from the excel file that is constantly updating. I only get the initial data when I run my java program.
You have to reread the data from the excel file. POI makes a copy into java objects when it reads it, so any further changes won't get reflected in your Java code without rereading the file.
If you mean that you do reread the file but don't see the updates, then it could be that someone is making changes in excel but not saving them, so POI can't see them yet.
This Answer is referred from Fetch Data From Excel have a look at this answer for more details. Maybe this question is a duplicate of the above link or vice versa.
The problem is because the excel data is not saved. I was also dealing with the same problem and got up with a different solution which worked for me. I just created a macro in excel to save the excel workbook whenever it's cell values got changed. Now I got the excel file with up-to-date saved data which can be read through java code and can be used for other purposes.

Categories