I'm using mallet to do some topic modeling experiment and now I got the keys.txt and doc.txt which I can open using microsoft excel but when I used POI api to read the content it just didn't work and give me the result as invalid header.
I tried to open the files in excel and save them the second time in xls format and this time it worked. So I guess though I specified in mallet command that it should be saved as xls it didn't work.
Is there any way that I can convert a txt to xls format in java? Or I can use java to open call microsoft excel to open the .txt file and save them again?
Thanks.
Maybe mallet is generated CSV (comma separated value) or TSV (tab separated value) files. You could try a library like opencsv to read the file, create an XLS file from the data using POI. If my assumption is true, you may find more help in this thread.
Related
I need to download some data in webpage in the form of excel file for that webpage contains excel image button. When i click the button an excel file downloads with containing some data which i need. But when i tried to open the downloaded file it showing an error "The file you are trying to open , File is in different format then specified by the file extension or corrupted data. Because of this error i am unable to read the data by using java.
try to save it as xlsx as there are two kind of work book provided by poi that is for xls and another is for xlsx.
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
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.
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.
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/