How to read and append a .xlsm file in java - java

I want to read and append a .xlsm file in java. I dont have any idea on how to do it.
Do i need to download any jar file to work with it?
All the search result provides a solution which uses apache poi(I did not get what it is). I dont use any IDE. Using simple FileReader and other logic can't I work with this type of file?
Please give me a clear idea on what is a .xlsm file and how to work with it using java.

"XLSM is a Microsoft Excel macro-enabled spreadsheet that contains worksheets of cells arranged by rows and columns and embedded macros programmed in the Visual Basic for Applications language. XLSM files are like XLSX files, but with macros enabled. They can be opened with Excel 2007 or later, or by previous versions of Excel with Open XML component support."
You can read and write to the file using Apache poi.
Take a look at the following SO Posts
write to xlsm (Excel 2007) using apache poi
Read data from read only xlsm file using Java Apache POI
The Apache POI documentation is located at
https://poi.apache.org/

Related

How to process excel with java excluding apache-poi, jexcel and xlsx4j libraries?

What I already did
I've already checked How to read and write excel file in java and Java Library to read Microsoft Excel files but they are all about the above libraries.
I have e java application for processing excel files. I implemented it with apache-poi but I was not able to sign it because xmlbeans.jar contains duplicated entries.
https://issues.apache.org/jira/browse/XMLBEANS-497
https://issues.apache.org/jira/browse/XMLBEANS-499
I saw the workaround in the second issue with patching the xmlbeans.jar but I don't like the idea of workarounds.
I've already re-implemented the code with xlsx4j which can process .xlsx files and jexcel for .xls files.
Problem
With two libraries the code is hard to maintain so I'm looking for another way to process .xlsx and .xls

Can Apache POI convert an Excel file to CSV without parsing?

Does anyone know if I can use something like Apache POI to convert an Excel file into CSV file in Java without application to parse into it?
Well, there needs to be some application, but you don't have to write it yourself.
I think there is no such ready-made tool included in POI itself, but other people have made such things and you can probably (disclaimer: I have not tried any) use them, for example
https://github.com/anjlab/excel2csv-java
http://code.google.com/p/excel2csv/
Note that this is bound to work only for very simple Excel files, as the Excel workbook format supports a lot of stuff that cannot be expressed in CSV.

Adding cell comments from raw xml for Excel 2007 using java

I need to create cell comments for existing excel file by extracting the xlsx file and using raw XML file.
Is it possible to do it in java without using Apache poi library?
Well I don't know much about excel but I found this website that might help you.

How to load old Microsoft Office XML file (Excel) using Java

I'm not able to load an Excel file in the older Office XML format (think Office 2002 or 2003 version) into Java. I tried JXL and Apache's POI (version 3.7). POI doesn't work since it appears to want the newer Office .xlsx format.
Here's an example of the older Office XML format.
One can generate a similar XML file from MS Excel 2010 by saving the workbook as the format "XML Spreadsheet 2003"?
Are there any open-source Java libraries that will load the XMLSS format? Otherwise I have no choice but to write a custom parser: read the XML file then interpret the cell tags to build out the cell matrix. In this XML format, any rows with empty cell values are skipped, the next cell with data positioned with an index attribute that acts like an offset in the columns, I assume to save space in the XML file.
The format is called SpreadsheetML (do not confuse with .xlsx which is also xml-based), a library called Xelem can handle it:
import nl.fountain.xelem.excel.Workbook;
import nl.fountain.xelem.lex.ExcelReader;
//...
ExcelReader reader = new ExcelReader();
Workbook xlWorkbook = reader.getWorkbook("c:\\my\\spreadsheet.xml");
System.out.println(xlWorkbook.getSheetNames());
Copying Mark Beardsley's answer from POI team http://apache-poi.1045710.n5.nabble.com/How-to-convert-xml-to-xls-td2306602.html :
You have got an Office 2003 xml file there, not an OpenXML file; it is an early attempt by Microsoft to create an xml based file format for Excel and it is in that sense a 'valid' Office file format.
Sadly, POI cannot interpret this file at all and that is why you saw the exception when you tried to wrap it up in the InputStream and pass it to WorkbookFactory(s) constructor. You do however have a number of options;
You could use Excel itself and manually open and save each file you wish to convert, as you already have done.
If you have access to Visual Studio and can write Visual Basic or C# code then you could use a control that will allow you to control Excel programmatically. This way you could automate a file conversion process using Excel itself. Then once the file has been converted wither to the binary or OpenXML formats, POI can be used to process it.
If you are running on a stand alone PC on which a copy of Excel is installed and using the Windows operating system, then you could use OLE to do something very similar from Java code. As above, POI can be used to process the file following the conversion.
If you have access to OpenOffice, it has a rather good API that is accessible from Java code. You could use it to convert between the file types for you - it is simply a matter of discovering the correct filter to use in this case. OpenOffice is good for all except the most complex files and you should be able to use POI to process the file following conversion. However, if you choose this route, it may be best to do all of the work using OpenOffice's UNO api.
Depending upon what you want to do with the file's contents, you could create your own parser using core java code and either the SAX or Xerces parsers (consider using xmlBeans (http://xmlbeans.apache.org/) ). If you simply open the original xml file using a simple text editor, you can see that the structure is not complex and, if all you wish to get at is the raw data it contains, this could be your best option.
After a lot of pain I've found a solution to this. JODConverter uses the OpenOffice.org/LibreOffice API and can convert SpreadsheetML to whatever formats OpenOffice.org suppports.
You might get some result using the OpenOffice API. If not directly you could probably convert to a 'supported' format.
Otherwise the schema for the Office 2003 'SpreadsheetML' isn't very complicated. I have succesfully created an xslt scenario to convert a resultset (database query) to a (simple yet effective) Excel 2003 document (XML format). The other way around should not be very hard to achieve.
Cheers,
Wim
The answer today was to ask the vendor to change their Excel file format to an Excel binary rather than the old Office XML. Doing so allowed me to use Apache POI 3.7 to read the file with no issues. I appreciate the answers, as I had no idea there was no direct support in the Java-based open source libraries for this old Office XML format. Now I know next time to check earlier to see what format the Excel files are in before committing to a timeline.
I had the same problem some time ago, ended up writing a SAX parser to read the XML file. I wrote a blog post about it here.
You can find the sample project to parse the file in Github.

Convert from Excel xlsx to xls in Java

I have an Excel 2007 xlsx file that I would like to programmatically convert to an .xls file. The xlsx file is an export from a reporting tool, and I would like to convert it to xls for better compatibility with the software stack of my application users. The xlsx is as plain as it gets. Just rows with data and basic type information (int/date/string). No formulas.
My platform is Java, and I do not have Microsoft Office installed. I'm looking for a solution that will allow me to convert between the formats with the least amount of effort. I.e. I'd like to avoid having to write a custom "copy application" that would read the xlsx file and copy the rows and formatting to another file. Preferably, the solution is open source and/or free.
I have looked at POI, and as far as I could tell, it can read and write both xls and xlsx files. But I was not able to tell by browsing the documentation and examples if it could read one format and write out in the other. Before I dig in any deeper, I would like to check if any of you out there have done anything like this before in Java, and if you have any tips.
Converting with POI would be a tedious task. I would like to point you to JODConverter. JODConverter is used by OpenOffice to convert its stuff, so it should work fine for that task.
However, that being said, I have not used JODConverter myself.

Categories