I am trying to write something in Java that basically does the same thing as "Text-to-Columns" in Excel. I have a long string of data (parsed out from some HTML) and I formatted it to divide the data I need by a semicolon.
For example
Str = brand name;1242141;brand name;753216;brand name;2356123;brand name;656258;
So I want each of the brand names and numbers to be in their own cell. Any ideas on how to do this?
http://www.tutorialspoint.com/java/java_string_split.htm
Str.Split(";")
Should give you the information that you would like. Getting the information into Excel is a whole other bag of cats, but
Best way to export data from Java to MS Excel
Is probably a great way to start.
Related
I am making a java program where I input answers for a friendship survey. It spits out the student's top ten friends. However I need to print out the results and give them to the students. The old of doing it was to have the java program write to write html then we would open each file one at a time and print out the page. However, having 400+ students to do it for takes a while.
So since I am re making the program I would like to make it so I can just have it on word files and print them all out at once. However, I don't know how to write to a word file and notepad isn't stylish enough. Anyone know how to make this possible or another way that is easier?
I did a similar thing some years ago, using Rich Text Format. Its advantage is that it's a plain text format that can easily be manipulated.
I created the form document in Word with some unique placeholder strings where I'd later fill in the actual data and saved it as RTF.
With a text editor, I made sure that Word didn't split the placeholders by inserting some junk formatting directives, and corrected that manually where necessary.
Then, filling in the actual data just meant to do some simple text replacement (in my case, there was no risk to interfere with the formatting directives), and saving the resulting RTF file.
As Word typically opens RTF files just as easy as DOC or DOCX ones, this was an easy working solution for me.
Here is the thing; I have to store simple data which I have to define once (manually). I must have a functionality to search in it after using keywords. It's like this:
My first item
title:my_title
description:my_description (long, few hundreds words)
keyword1:my_keyword1
keywordx:my_keywordx
And I want a lot of items like this. For example 100 or 1000.
And after in code I want to make search function to look for specific items (as result may be a few, not only one) based on keywords and show the result as text in TextView field for example.
Do You have any idea how I should storage this data? I would prefer .xml file (person who will create data is not a programmer, it'll be much easier for him).
Put your data in JSON format as a text file, create a "res" folder, and put that text file in there. From the "your activity", read this file from the raw folder and parse the JSON.
I see this to make text file and it also helps me out but in all examples i see that they just making string in notepad or we can say text file...
Can any one say that how to make table formatted text file in android??
i want to make file(invoice)
This is most likely going to involve some some slightly messy string processing. Assuming you have your data in an acceptable format (such as string arrays), you should be able to construct a single java string representing the whole table, and then use the code you found already to print it to a file. Use the escape character \t to separate between columns and \n to separate between rows.
That would be TSV format, and it is very easy to generate. Just add a TAB after every field, and a CR/LF pair after every record.
I've got a HTML website, in which there is some kind of data inside a table(I have no control in which way data is displayed on that website). I need to get/extract this table data.
i.e. nth row in the table has 2 columns, first columns text is "last update time", and the next column has some datestamp value. Using jquery I could say exactly that I want to get this tables nth row second column text which would give me some timestamp string.
Is there something like this in java, I will basically get the whole site and try to extract that information in the same manner as I described above. Does java have something similar?
Since javascript can be executed as a shell script as long as there is interpreter available, can something similar be done so that jquery functions are possible to invoke from java?
I think jsoup will help you.
Java can parse a DOM and you can interpret it that way. For a brief explanation, check out http://tutorials.jenkov.com/java-xml/dom-document-object.html
Its certainly not going to be as simple as writing a jquery function to do the same.
I have a situation where I have been asked to write a program that essentially does an arbitrary SQL select over JDBC, convert the ResultSet to something loadable in Excel and send it as an attachment in an email.
The question goes for what dataformat to use in order to be loadable by as many different versions of Excel as possible.
I have considered:
XLS - native format, the simplest way to generate seems to be with JExcel.
CSV - comma separated format, must use semicolons instead of commas to cope with European decimal commas, and then there is all the quotation stuff.
HTML - it appears that Excel knows how to read an HTML table. It should be sufficient then to set the MIME-type to be application/vnd.ms-excel
but naturally there must be other interesting ways to do it.
My major concern is incorrect interpretion of the data:
Numbers with decimal commas gets misinterpreted on systems with decimal points.
Character encoding issues (We cannot rely on the recipient using ISO-Latin-#).
Date interpretation - we have earlier found that the YYYY-MM-DD format is pretty robust.
My major concern is robustness. I don't mind it being tedious to code, if I can count on the result being good.
Suggestions and experiences to share?
I am aware of JSP generating Excel spreadsheet (XLS) to download - that page does not discuss robustness.
I'd recommend Andy Khan's JExcel. It's the best library for working with Excel in Java.
Apache hssf
This has always been the chosen method where I've worked in Java development.
It's an acronym for Horrible SpreadSheet Format
The quick way to generate Excel files to to write out tab delineated text and name it <name>.xls. Excel will open any text file ending in .xls as a single worksheet.