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.
If you enjoyed this post you might want to subscribe to our RSS Feed!


One Response
I don´t find anywhere how to write the document, I mean, create the .docx and save it in any dir….