Im trying to convert a properties file into an excel but i dont know how.
It's look like this in netBeans but i can copy an entire column or all, only let me one for one (And there is a lot of data..)
Anyone knows how to convert this to a excel or at least copy an entire column?
EDIT1: I'm asking this question looking for a non-programming answer because i think netbeans can do anythink like converting this into an excel. (My english is not the best, i hope you can understand what i'm trying to say.)
You should read the file using something like that:
Read the file to a String usign Files.readAllbytes() and then split the content into a list of Strings:
Then you should apply some java project like apache POI here is a example using excel:
http://poi.apache.org/spreadsheet/how-to.html#sxssf
Good luck!!
Use JExcelpApi, http://jexcelapi.sourceforge.net/
Download Link: http://sourceforge.net/projects/jexcelapi/files/jexcelapi/2.6.12/
Tutorial: http://www.andykhan.com/jexcelapi/tutorial.html
You can save the properties file as a csv file.
Just rename it from [filename].properties to [filename].csv
Then you can import the csv file in Excel by using the import function whitch can be found in the menu under Data -> from text.
After clicking on from text there should open a popup in which you can set the import options.
In the first step inside the popupwindow select separated an go to the next step.
Here you can choose what symbol is the separator of the csv file.
Just write = into Separator->other and press on finish.
You can also find a good documentation about how to import csv to excel here: https://superuser.com/questions/407082/easiest-way-to-open-csv-with-commas-in-excel
Related
Is it possible to access a specific row in a CSV file and replace a specific field in it? E.g. like in this pseudo code:
Row row = csvFile.getRow(123);
row.getField(2).set("someString");
Tried Apache Commons CSV and OpenCSV, but can't figure out how to do it with them. Only way I can think of is to iterate through a file, store everything in a new object and create a file, but that doesn't seem like a good way.
Thanks for any suggestion!
Sounds like a duplicate of this one to me.
I am not sure about how to do it with apache but I am sure they have the same mechanisms. In openCSV you would create an CSVReader to your source file and a CSVWriter to your destination file. Then read a record at a time, make any desired changes and write it out.
Or, if the file is small, you can do a readAll and writeAll.
But if you want to do it all in the same file read my comments in the duplicate.
I have a .docx template with fields defined in it. I need to take data inputted by a user in a web-service and insert it into those fields using Java.
My team and I have been researching this for most of the day, and we have been unable to find a straightforward solution to this.
Is there a way to do this relatively easily?
Thanks.
EDIT:
After pressing alt+F9, all of the fields display like this: { FORMTEXT }
POI doesn't seem to have sufficient support to do this.
I was unable to successfully set up the Open Office SDK in Windows XP because I couldn't fulfill all of its dependencies.
docx4j may work, but MailMerger in it is currently not filling the fields in with the given data.
If I extract the docx and open the word/document.xml file, this is what the XML around one field looks like: http://pastebin.com/uXBtz7X5 (search for FieldName and FieldValue to see where these are defined)
Have a look at Docx4j which you can use to update fields in docx documents there is also and example
fieldupdater example
Disclosure: my company sponsors docx4j
Have a look at MailMerger; see the main method at the bottom.
For fields of other types, you can try the more generic field support.
The docx format is a zip file, with XML and other files inside. You may be able to edit the XML files using standard XML tools.
Docmosis and JODReports might help you - they are Java libraries for producing documents / populating templates in several formats. Docmosis can work with DocX and since they are based on the same techologies JODReports probably can too. I don't know if the particular {FORMTEXT} field is going to work, but Docmosis can work with plain-text files or Word's merge fields which look like {MERGEFIELD} when you press ALT-F9.
I have about 100 different text files in the same format. Each file has observations about certain events at certain time periods for a particular person. I am trying to parse out the relevant information for a few individuals for each of the different text files. Ideally, I want to get parse through all this information and create a CSV file (eventually to be imported into Excel) with all the information I need from ALL the text files. Any help/ideas would be greatly appreciated. I would prefer to use java...but any simpler methods are appreciated.
The log files are structured as below: changed data to preserve private information
|||ID||NAME||TIME||FIRSTMEASURE^DATA||SECONDMEASURE^DATA|| etc...
TIME appears like 20110825111501 for 2011, 08/25 11:15:01 AM
Here are the steps in Java:
Open the file using FileReader
You could also wrapped the FileReader with BufferedReader and use readLine() method to read the file line by line
For each line you need to parse it. You know best the data definition of each line, to help you might be able to use various String functions or Java Regex
You could do the same thing for the Date. Check if you could utilize DateFormat
Once you parse the data, you could start building your CSV File using CSVParser mentioned above or write it your own using FileOutputStream
When you are ready to to convert to Excel, you could use Apache POI for Excel
Let me know if you need further clarification
Just to parse through the text file and use CSVParser from apache to write to a csv file. Additionally if you want to write in to excel, you can simply use Apache POI or JXL for that.
You can use SuperCSV to parse the file into a bean and
also to create a csv-file.
i want to know if it's possible to import a text file in excel through java code.
I know that we can use directly Excel and open a text file.
But for me i want to do it with java because i have a java program that create a text file everyday and after i want to open it with excel automatically.
I don't want to loose my time to open Excel, then click import , then choose file, then...
is it possible to do fastly with java?
Thank you
I think the easiest solution here would be to have your Java code create a Comma Seperated Value (CSV) file. They are easy to create and easy for Excel to open (no extra clicks required).
import java.io.IOException;
class ExcelStarter {
public static void main(String args[]) throws IOException
{
Runtime.getRuntime().exec("cmd /c start excel.exe _pathtoexcelfile_");
}
}
Yes, it is possible. You can parse your text file and put the data in a worksheet using the Apache XSSF library for xlsx. And then save it. 10 minutes of research should be sufficient to find what you need.
I have used Apache POI and their HSSF. It has a Java API with which to read Excel files.
If it is a CSV (Comma Separate Value) file, you may also want to see this question Can you recommend a java library for reading and possibly writing csv files
I want to insert the data at some positions in the text file without actually overwriting on the existing data.I tried RandomAccessFile ....but that also overwrites it....
Is there any way to insert the data without overwriting??
-Thanks in advance
You have to read your file and rewrite it. During this operation you have to find the place where you want to put your text and write it.
It is not possible (not with Java, and not with any other programming language) to "just" insert data in the middle of the file, without having to re-write the rest of the file. The problem is not the programming language, the problem is the way files work.