JSON object flattening to CSV one row - java

Has anyone ever been involved with exporting JSON like this one in my sample made only for the purposes of this conversation:
https://gist.github.com/slavisah/97b57a5826dc0b49ee22895035eb244a
It represents a list of material objects (wood, metal etc.) Requirement is that every material has to be written in one line of CSV file with all of it's behaviors and properties, and their sub-lists in relation to them in the same row. Every list is N sized.
My question is how to structure that CSV file for easiest export/import in my application? Maybe someone is familiar with Java library which is capable of doing things like this?
Thanks.

Some good libraries for working with csv files using java...
http://www.beanio.org/
http://super-csv.github.io/super-csv/index.html

i suggest you to use Apache poi the Java API for Microsoft Documents : https://poi.apache.org/

Related

Java creating PDF file

I am currently working at a project which generates contracts. The idea is that I put the data in a form and save it in a simple database.
So long, this was my favorite place to search for good ideas and simple solutions.
Now I am facing another problem and I don't know how I can solve that. I want to create a PDF and replace some placeholders with some data from my form.
One idea was, that I use an existing Word template with some bookmarks and replace them with the data from my form. Maybe there is a way to do that, and I am just too stupid to find it.
Another idea was, that I am using XML. Therefore, I thought I was clever and just converted the Word template to an PDF, so I am able to convert that PDF to an XML. Attached, you find the XML file. But now I need the XSL file - is there an easy way to create the XSL file?
Or maybe there is another simple solution to solve my problem.
In these attachments you find the PDF file, the Word template and the XML:
Thank you a lot :)
Using a template is a good idea - it makes some changes much quicker to make and then deploy. The comments above are focused on conversion, but don't forget you need to merge your data in (population) first.
If you can use Adobe tools, you can have a PDF template and use the Adobe tools to populate. This saves a "conversion" stage.
You mentioned using Word for templates. This means you to run through two stages of processing:
population - docx is a zipped set of XML files - so you can process them with your own code or using a library.
conversion - you need pdf, so you have to convert the docx to pdf. You also have to watch out for fonts at this stage (ie make sure they are available on your host).
The population stage you could do yourself since you are familiar with XML. But it is definitely complicated. The conversion needs to use a tool that is ideal for it. There are a few mentioned in the comments already.
There are some free/os and commercial tools that can do both parts:
docx4j
JOD Reports
Libre Office (using the Java Uno API) (I blogged this once - Java Convert Word to PDF with UNO)
Docmosis (please note I work for Docmosis)
I suggest starting with the simple example you have attached and prove you can both populate and convert that. Then switch to a more complicated example to see if you can do the other things that might be required (eg repeating or conditions or other logic) during the population stage.

How to fill tables of a word document programatically

I have been given a Microsoft Word Document, with some tables and spots to fill in automatically. I am not sure if this can be done with JAVA, which is my most preferable language.
I am looking for a way to implement a function which I can give the word file to it, and it fills the required spots for me. Is it possible to do it? A hint or a link to a tutorial would definitely suffice. Thanks.
Newer versions Word store documents as zipped XML. Have you filled out the form manually in Word and done a before/after comparison on the XML? Depending on the extent of the changes you could use the standard Java XML APIs to do the same thing programmatically.
A bit of googling and I found docx4j and Apache POI. I haven't used either personally, but it appears that what you're asking for is certainly possible. See this example from the POI SVN repo on how to manipulate tables.

How can i make a java program that dynamicaly picks up data from an excel file?

I am working on an algorithmic trading strategy and have an excel sheet that dynamically picks up the stock values from the internet. I require my JAVA program to pick up these changing values,store them and perform some operations on them dynamically to generate result. Kindly suggest a method to pick those values or in case anybody has that piece of code, please share.
I am sure you heard of Apache POI API to process excel sheets. May be we could suggest something if you could elaborate the problem a bit.
You need to create your own dsn (Data Source Name).
Go through this link -
http://www.javaprogrammingforums.com/jdbc-database-tutorials/356-how-connect-excel-spreadsheet-using-jdbc-java.html

create excel using Java

I am very new to java. I am trying to fetch some data from a database and the result set is displayed in excel. I am able to inetract with database. But how should I go ahead for inserting data into excel sheet.Its simple Java program and in future I would like to generate files in other format say PDF, doc etc.
I am looking for an approach with lesser load on CPU, faster.
thanks in advance for help.
Just spit out a CSV file. It's lightweight and portable. You can grab a csv writer from Apache commons I think but spending the 10 min it would take to write one might be a good learning exercise as well.
If you want a real solution where you want different outputs (eg excel, pdf, rich text etc) then use a reporting tool. There are plenty of opensource tools like ireport which will let you create a template then write a simple java app that renders that to pdf, excel etc. Otherwise you will end up doing it by hand. It's a bit heavyweight but anything more than trival tabular output will be easier.
Apache POI is for you in this case, but you will find it a little bit overwhelmed if you just need to write/read data from an excel file.
Try jExcel instead, the API is simple and straightforward, you can also manipulate sheets within an excel workbook.
The easiest and standard way of doing this is to use POI library:
http://poi.apache.org/spreadsheet/quick-guide.html
The new xlsx format is based on Open-XML and would provide a method of generating these files without any dependency on Microsoft-office COM libraries -- the same could done for docx and pptx formats later, as well as other open-Xml formats like EPUB.
The Apache POI project looks like it might provide one possible solution. There's also an article on the MSDN interop blog that discusses this in some detail.
The key words you should google for are OLE and DDE.
Though, Java is not the best language for interface Microsoft's software.
for generating excel i think you should try simreport in jsimreport.com. in my opinion, it's quite simple to make an excel report, it uses the excel sheet to generate report so easy to config and visually

How to load my data into a GraphML file for easy use in Prefuse?

I'm trying to generate some graphs with prefuse, and it seems like the easiest way to load the data into prefuse is to use a GraphML file.
Is there an easy way to write these files from my data?
Or is there an easier way to load my data into prefuse?
Thanks
yEd can export graphs in GraphML format and JGraphT has a GraphMLExporter. Leaves the problem on how to get your data into those products or libraries. But at least both can create the desired format.
on the other hand - GraphML is in XML format so you can easily use jdom or dom4j to create a DOM, add the nodes based on your data an serialize it to an XML file. This shouldn't be to complicated.
You could use the Network Workbench, which allows you to load data in a lot of different forms including edge lists. Edge lists are usually the easiest format to generate.
I'm not completely sure if you can export from NWB to say GraphML, but NWB includes a number of visualizations, some of which are based on Prefuse.
If you want to do more with your data than just visualize it then NWB might help you.
Check PyGraphML, a basic Python library designed to parse and generate GraphML files. http://hadim.github.io/pygraphml/index.html

Categories

Resources