Convert excel file from XLSX to XLSB in Java - java

I am using Java + Apache POI to generate an excel file (format xlsx/xls). Due to huge data the generated excel file (format xlsx/xls) takes more size (~50 MB).
So I am trying to convert xlsx/xls to xlsb to reduce the size of the excel file.
Here is the problem: Apache POI does not support writing to xlsb file. So what I am trying is:
Generate a xlsx/xls file using Apache POI.
After that convert generated xlsx/xls to xlsb. For this I am using
SmartXls Java library. But this library is not open source. You need to
buy license for this. Also I checked EasyXls Java library, but it also requires buying a license.
Below code is used to convert xlsx/xls to xlsb using SmartXls Java library:
WorkBook wb = new WorkBook();
wb.readXLSX(.../xlsxPath);
wb.writeXLSB(new java.io.FileOutputStream(.../xlsbPath));
wb.dispose();
Kindly someone help me whether any open source library is available for it or is there any other way to do this conversion in Java.
Thanks in advance.

Related

What is the difference between poi and poi-ooxml

I'm learning about data driven testing using Selenium and Excel. I'm taking an online course that has asked used to add the Apache poi and poi-ooxml dependencies in Maven.
I'm struggling to understand what the differences between the two are. Are both required in order to retrieve data in Excel and pass these to our tests?
Thanks
Excel files has long history
Excel 97-2003 workbook:
This is a legacy Excel file that follows a binary file format. The file extension of the format is .xls.
Excel 97-2003 in terms of apache poi is called - Horrible Spreadsheet Format As the Excel file format is complex and contains a number of tricky characteristics,
apache-poi jar has code to handle these file
Excel 2007+ workbook:
This is the default XML-based file format for Excel 2007 and later versions. It follows the Office Open XML (OOXML) format, which is a zipped, XML-based file format developed by Microsoft for representing office documents. The file extension of the format is .xlsx. ( DOCX,PPTX are other OOXML based examples).
Excel 2007+ workbook in terms of apache poi is called - XML Spreadsheet Format -these file format are advanced version of HSSF and has additional features, code to handle these files are written in apache-poi-ooxml jar
More reading
As .xls is almost dead but still some applications use it, so for backward compatibility both dependencies are required.
here is what Apache have to say -
HSSF Excel XLS poi For HSSF only, if common SS is needed see below
Common SS Excel XLS and XLSX poi-ooxml WorkbookFactory and friends
all require poi-ooxml, not just core poi
you can read more at their official website http://poi.apache.org/components/index.html#components

Is it necessary to add POI for reading and writing Excel Sheets in JAVA?

Is it necessary to add Apache POI and similar libraries to read and write Excel Files in JAVA? Is there any predefined JAVA library for reading and writing Excel Sheets?

How to convert ms-Excel file to Pdf in java?

Because I have used JXL api for excel but now I want to convert it to Pdf file so please tell me how to change my code to convert excel to pdf?
You could use iText to create a pdf file in java and use Apache POI to access the data in the MS-EXCEL file. If you combine both, you could convert your excel file.
A raw example is given here
Also, there is this new API:
You can try Aspose.Cells for Java which allows you to convert Excel file to PDF in Java applications. It doesn't require MS Office/OpenOffice etc to be installed on your development or deployment machine. It also works on both Windows and Linux platforms. The code is very simple as shown below:
//Instantiate a new workbook with excel file path
Workbook workbook = new Workbook("F:\\FileTemp\\Book1.xls");
//Save the document in Pdf format
workbook.save("F:\\FileTemp\\MyPdfFile.pdf", FileFormatType.PDF);

Is there any way to generate Xlsx (2007) using xmlss?

When saving an excel sheet (xls - 2330) in .xml form, the xmlss file will contain the respective xsl code. But in xlsx i can't save the file with .xml format.
Also is there any specific Apache POI API availabe to convert .xls (2003) to .xlsx(2007) format?
Since the POI creates the xmlss file to create the xlsx, is there any simpler option?
related links:
http://msdn.microsoft.com/en-us/library/aa140066%28office.10%29.aspx#odc_xmlss_x:header
Greetings in advance.

Convert Excel sheet to PDF through Java

I need to convert an excel spreadsheet to PDF file. I looked for in the Web and I found that the best way to do this is using OpenOffice API, but it is not free.
Someone know any open source library for doing this?
Any examples code is appreciating
Apache POI can read Excel. iText can write PDF.

Categories

Resources