Creating multiple sheets in CSV file - java

I am using superCSV to write data in csv format in my code. Its working absolutely fine and very efficiently , but now my requirement changed . I need to write multiple sheets in single xls file which is very time consuming task. So is there is any way in supercsv by which i can write multiple sheet data in single csv file and will send it to client, so that when client open this csv file in MS-Excel, he can see multiple sheets rather than me generating the excel file with with multiple sheets and sending it to client.
Thanks

CSV is a very simple format, and does not have the concept of a "sheet".
So, no, it's not possible directly.
The only thing that I can suggest is to send multiple csv files to the client, perhaps as a .zip file, and have the client unizp it and import one sheet at a time into Excel.
If you need it to open directly in the browser, you'll need to go with an xls file.

Take a look at the api here.
http://supercsv.sourceforge.net/apidocs/index.html
I'm not familiar SuperCsv please don't beat me up too bad if I'm wrong...
Can't you just set CsvPreference to EXCEL

Related

Writing CSV files causing JVM crash

In the existing project user can download report and it has 10 million records, this process gets data from database and writes to csv by using super csv java api then sends an email to user by attaching, it takes huge heap space to hold 10 million java objects and writing these records to csv files, because of this server is crashing and going down as application has many reports like this. is there any better way to handle this.? I red sxssfworkbook documentation and it says specified records count can keep in memory and remaining records will be pushed to hard disk but this is using to create excel files. is there any similar api to create csv files or sxssfworkbook can be used to create csv files.?
There are few Java libraries for reading and writing CSV files. They typically support "streaming", so they do not have the problem of needing to hold the source data or the generated CSV in memory.
The Apache Commons CSV library would be a good place to start. Here is the User Guide. It supports various of flavors of CSV file, including the CSV formats generated by Microsoft Excel.
However, I would suggest that sending a CVS file containing 10 million records (say 1GB uncompressed data) is not going to make you popular with the people who run your users' email servers! Files that size should be made available via an web or file transfer service.

Removing data from multiple excel files

I have two excel files. There is some common data in both the files. I want to get a new excel file which only has non redundant data. I am reading data from excel files using apace POI (Java). Any help on the algorithm that can be used to remove the redundant data (since there are more than 10,000 rows in each excel file). Thanks.
copy all the data in HashSet(). and write it in another file.

How to read excel file with Java without external jars

I'm trying to read excel file and pass all the data to DB. I found a few code examples but all of them required external jars. How can I read excel files using only the standard library?
IF you don't want to use a library then you will have to download the Excel file format specs from MS and write an Excel parser yourself (which is extremely complicated and takes > 10 years for one developer). For the OpenXML format spec see here and here.
Thus I really recommend using a library for that...
Try Apache POI - a free Java library for dealing with MS Office documents..
You can save as the excel file *.cvs and sperated ";". Then, you can read file line by line and get the columns which is getting from each token.
Microsoft excel uses a binary way to save its data, so manually reading excel files might be a hassle. If you could convert the excel (xls) to a comma seperated values (csv) file, then you can just read the file and split your input on the comma's.
This is a difficult problem. First off, it is not as simple as "adding a third party library". There are no existing EXCEL reading libraries that do not cost money and the one that I know that does work is very expensive AND has bugs in it.
One strategy is to create an Excel add in that reads the data and transfers it to your application by OLE or the clipboard or by a TCP/IP port or saves it to a temporary file. If you look in the source code for OPeNDAP.org's ODC project you can find an Excel add in and TCP capability to do this.
You can try referring to the reader in OpenOffice which is open source code, however, in my opinion that code is not easily refactorable into a private project for various reasons.
Microsoft has components and tools to open Excel files and expose them via COM objects.
You can also learn the BIFF format and write your own parser. You probably would want to write a parser for BIFF5, but be forewarned, this is a BIG project, even if you only parse a limited number of data types.

How to get the values from DB and store it in a existing excel file using java?

I want to store the values from the database to an existing excel file. For example if the file is stored in C: data.xls. I want the data from db table to be stored in that.
I will mention the column name in the excel file itself.
Please help me to do this.
Use JDBC API to read/fetch result from the MySql database and jExcelAPI or Apache POI (recommended) to write/update excel document.
Writing to a CSV file is probably the easiest way to do this. CSV files can be opened up in Excel, but cannot have any text formatting. See the CSV Wikipedia article for more details on the format.
If you would rather use an XLS or XLSX format, consider using Apache POI, as the formats of those file types (particularly XLS) is quite complicated to write to manually.
If you are going for a CSV file, you need only open the file, and begin putting rows, one per line, with commas in between values. It's very simple, and works with a variety of software.

Is there any API that takes an Excel file and converts it to a CSV file using Java?

I have 200,000 or more records in an Excel file. If I tried to read records row by row and create a CSV file it's very costly as well as time consuming. Is there any API that can help me with that?
There are several frameworks out there, if you have a look.
For example, you can try:
Apache POI (example)
JExcel (example)
This seems to be the same question as How to import an Excel file into MySQL using ODBC in Java?
What has changed? If you want to write to a CSV file you should use a CSV library such as OpenCSV: http://opencsv.sourceforge.net/

Categories

Resources