Archive for December, 2009

pie_chart

December 30th, 2009 | No Comments »

It is obvious that a “half decent” application to generate reports has to include a tool for the creation of charts and graphs on the fly, so javaDocx could not do less than that.
In fact javaDocx is a pretty sophisticated tool to that regard and as we show below is very simple to generate a nice chart from some data that could be extracted from a database, a spreadsheet or elsewhere.

In this example we will concentrate in creating a pie chart that plots the following sample data:

Do you like “paella”?
Like paella: 50%
Don´t like paella: 10%
What the f*** is a paella? : 40%
Notice: paella is a typical Spanish rice dish.


import com.javadocx.*;
import java.util.*;

public class graphic {

  public static void main(String[] args) {
    try {
      com.javadocx.cCreateDocx objDocx = new cCreateDocx("docx");
      HashMap<String, Object> array = new HashMap<String, Object>();

      HashMap<String, ArrayList> data = new HashMap<String, ArrayList>();
      ArrayList<Integer> al = new ArrayList<Integer>();
      al.add(50);
      data.put("like paella", al);
      al = new ArrayList<Integer>();
      al.add(10);
      data.put("do not like paella", al);
      al = new ArrayList<Integer>();
      al.add(40);
      data.put("what the f***…?", al);

      array.put("data", data);
      array.put("type", "pieChart");
      array.put("title", "Do you like paella?");
      array.put("showPercent", "1");
      objDocx.fAddGraphic(array);

      objDocx.fCreateDocx("simple_piechart", new HashMap());
    } catch (Exception e) {
      System.out.println("error " + e.toString());
    }
  }
}



That generates this pie chart.

If you prefer a 3D version of this pie chart you need the Pro version but the required code is not much different:


import com.javadocx.*;
import java.util.*;

public class graphic {

  public static void main(String[] args) {
    try {
      com.javadocx.cCreateDocx objDocx = new cCreateDocx("docx");
      HashMap<String, Object> array = new HashMap<String, Object>();

      HashMap<String, ArrayList> data = new HashMap<String, ArrayList>();
      ArrayList<Integer> al = new ArrayList<Integer>();
      al.add(50);
      data.put("like paella", al);
      al = new ArrayList<Integer>();
      al.add(10);
      data.put("do not like paella", al);
      al = new ArrayList<Integer>();
      al.add(40);
      data.put("what the f***…?", al);

      array.put("data", data);
      array.put("type", "pie3DChart");
      array.put("title", "Do you like paella?");
      array.put("showPercent", "1");
      objDocx.fAddGraphic(array);

      objDocx.fCreateDocx("simple_piechart", new HashMap());
    } catch (Exception e) {
      System.out.println("error " + e.toString());
    }
  }
}

A very simple .docx

December 28th, 2009 | 1 Comment »

JavaDocx keeps simple things simple, and there should be nothing simpler than the usual “Hello World Script” that will allow you to generate a Word document with “Hello World” on it.

A few lines of code will do, assuming you have already installed the JAVADOCX library on your web server.

The code reads:

<br />
import com.javadocx.*;<br />
import java.util.*;</p>
<p>public class text {</p>
<p>public static void main(String[] args) {<br />
try {<br />
com.javadocx.cCreateDocx objDocx = new cCreateDocx(".docx");<br />
HashMap<String, String> array = new HashMap<String, String>();<br />
array.put("text", "Hello World.");<br />
objDocx.fAddText(array);<br />
objDocx.fCreateDocx("hello_world", new HashMap());<br />
} catch (Exception e) {<br />
System.out.println("error " + e.toString());<br />
}<br />
}<br />
}<br />

But if you are a wannabe designer : -) you may try the same document with advanced formatting.

You may center the text and write it in bold characters with one line more of code:

<br />
import com.javadocx.*;<br />
import java.util.*;</p>
<p>public class text {</p>
<p>public static void main(String[] args) {<br />
try {<br />
com.javadocx.cCreateDocx objDocx = new cCreateDocx(".docx");<br />
HashMap<String, String> array = new HashMap<String, String>();<br />
array.put("text", "Hello World.");<br />
array.put("b", "single");<br />
array.put("jc", "center");<br />
objDocx.fAddText(array);<br />
objDocx.fCreateDocx("hello_world", new HashMap());<br />
} catch (Exception e) {<br />
System.out.println("error " + e.toString());<br />
}<br />
}<br />
}<br />

You will not get a job as a designer (to be a programmer is not so bad after all) with this Word document but we hope that this example will prompt you to scan the JAVADOCX documentation.

Why JAVADocX ?

December 18th, 2009 | No Comments »

The word processors are some of the most used software programs both at home and at work and Microsoft Office Word™ , whether we like it or not, has become their de facto standard. Since 2003 Microsoft Word™ is also part of an open standard (OOML) based on XML.

It is not among our objectives to endorse or support any specific standard or company but we believe that a tool like JAVADOCX can be of much help to all of those professionals that need to create reports in MS Word (.docx) format within a JAVA platform. Indeed, JAVADOCX was born from our own need to generate data driven editable Word reports for our clients using JAVA.

We offer JAVADOCX in two different ways:

  • Free version: that allows a reasonably skilled programmer to generate a basic MS Word document in the .docx format at no cost.
  • Pro version: that allows for the geneartion of more sophiticated MS Word documents at very low cost.

Although one may use the free (LGPL) version for the majority of applications it cannot be upgraded to include support and lacks some of the advanced features of the Pro version.

We hope that you consider this JAVA library useful and we wait for your feedback to improve it.