Saturday, June 9, 2012

How to Edit Microsoft Word Documents Programmatically

In many cases, we need to edit existing word documents that follow a pattern. Doing it manually is not a good idea if the word document has be edited often. An example is that a release notes word document which needs to be updated for every release but not all the contents require change. The change may be required to update certain information such as release deliverable version numbers, date, numbers of bugs fixed etc. If number of deliverables is more, its time consuming to update the word document manually.

There are ways to create a new word document altogether in Java programming language (POI), however editing existing document is not a straight forward task. So use of Microsoft technologies will ease the process since when word document is edited, the existing formatting needs to be retained.

We can use VBScript to edit word document and this makes it much easier. Lets look at an example of editing Microsoft word document using VBScript and the VBScript can be invoked through a Java Program or any scripting language.

Simple example: VBScript (EditTable.vbs)  
---------------------------------------------------------
| Set wd = CreateObject("Word.Application")
| Set doc = wd.Documents.Open ("d:\work\ReleaseNotes.doc")
| x = 2  'Second row of the table
| Set objTable = doc.Tables(4)    'I want to edit 4th table in the release notes document
| objTable.Cell(x, 2).Range.Text = "DATA1"  'DATA1...n is a place holder & will be replaced by external |program like java program
| objTable.Cell(x, 3).Range.Text = "DATA2" 
| objTable.Cell(x, 4).Range.text = "DATA3"
| objTable.Cell(x, 5).Range.text = "DATA4"
| doc.save()
-------------------------------------------------------

In above VBScript snippet, the DATA1, DATA2...etc are the new values to the respective table cells. The script can be enhanced to read these data from a database or any other source.
The above script can be called through following Java Code.
----------------------------------------------------------------------------
| public class WriteFile {
|    public static void main(String[] args){
|        try{
|            Process p = Runtime.getRuntime().exec("cmd /c d:/work/EditTable.vbs");
|            p.waitFor();
|            int i = p.exitValue();
|            System.out.println("Exit value="+i);
|        }catch(Exception e){
|            e.printStackTrace();
|        }
|   }
|}
--------------------------------------------------------------------------

If you want to learn in depth on how to create new word documents, Microsoft Excel Sheet files, etc, have a look at  Apache POI - the Java API for Microsoft Documents.

Wednesday, June 6, 2012

Next Version of Internet (IPv6) Rolls Out

The next version of the Internet begins rolling out today(6th June 2012). The Internet is running out of the limit of IP addresses that IPv4(Internet Protocol version4) supports. The only immediate solution to make room for fast adding internet devices is to enable IPv6 and the transition has started already. The World IPv6 Launch  indicates the same. Major websites, internet service providers(ISP), content owners are already rolling out IPv6 for their products or services.

IPv6 supports virtually infinite number of IP address and will be sufficient in the future that can be seen. If you ask exactly how many IP addresses? the answer is 340 trillion, trillion, trillion whereas IPv4 supports 4300,000,000 IP addresses. IPv4 is 32 bit whereas the next version is 128 bit wider. For example IPv6 IP address looks 2001:0db8:85a3:0000:0000:8a2e:0370:7334 whereas IPv4 looks as 127.0.0.1

Well, having said that several questions come to our minds such as how long does it take to completely transit to IPv6?, what are the consequences of not migrating to IPv6? Will my products/services work when switched to IPv6?, Should I be prepared for the switch?, what are the risks involved during transition? Does IPv4 talk to IPv6 or other way around? And the list continues. Lets find out the answers to some of the questions.

The truth is that there is cost involved and also the risk. People need to migrate the complete infrastructure starting from home routers, hosts, DNS infrastructures, their applications and products and also they have to be backward compatible. A part of Internet will still be a IPv4 (Since the transition may not happen all of a sudden and takes time) and the systems migrated to IPv6 may need to talk to older versions. The IPv4 can not talk to IPv6 since they are completely new different network stacks, however certain translators such as NAT64 are needed to be installed which convert IPv6 to IPv4. Yes, new transition technologies are needed!

The IPv6 transition has to be planned carefully since there could be potential network security vulnerabilities in IPv6. This is due to lack of security testing tools for IPv6. Upgrading the security tools, intrusion detection systems, anti-virus software to support IPv6 may mitigate the network security risk.

Internet end users need not worry about the transition, it happens for its shake and they use the internet the way its being used in the past. If you are curious and want to know if the website you surf is supporting IPv6 or not, visit ipv6test.google.com .
  
Related Posts Plugin for WordPress, Blogger...