Connecting Tech Pros Worldwide Help | Site Map

Word, Access and Java - suggestions

  #1  
Old June 21st, 2009, 03:09 PM
Familiar Sight
 
Join Date: Nov 2007
Posts: 153
Hi all,

I would lke some advice/suggestions on the following:

I have my data inputted into jtextbox's which is then assigned to String variables which is then inputted into a access database. (A weeks work!)
now, I need to use that data somehow to fill in fields for a invoice template in word.

any suggestions on where to start would great - I haven't a clue yet!

Regards

Brendan
  #2  
Old June 21st, 2009, 04:49 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Word, Access and Java - suggestions


For starters, read this. It's Apache's POI project that allows Java to access a lot of MicroSoft's file formats (including MicroSoft Word).

kind regards,

Jos
  #3  
Old June 21st, 2009, 05:16 PM
Familiar Sight
 
Join Date: Nov 2007
Posts: 153

re: Word, Access and Java - suggestions


Thanks for that Jos,

I decided to go with the wordApi. Although I can't get that working. ever used it? If so do you know where the wordapi.exe file goes as my program can't find it to execute the following..

Expand|Select|Wrap|Line Numbers
  1. WordProcessing.createNewDocumentFromTemplate("SampleTemplate.doc" );
  2. WordProcessing.typeTextAtBookmark("AddressLine1", "O'Reilly & Associated, Inc.");
  3. WordProcessing.typeTextAtBookmark("AddressLine2", "Mr Miller");
  4. WordProcessing.typeTextAtBookmark("AddressLine3", "101 Moris Street");
  5. WordProcessing.typeTextAtBookmark("AddressLine4", "Sebastopol, CA 95472-9902");
  6. WordProcessing.typeTextAtBookmark("Salutation", "Dear Mr Miller,");
  7. WordProcessing.exec();
going off the stack trace the exception being thrown happens when the following code is executed...

Expand|Select|Wrap|Line Numbers
  1. public static boolean exec() {
  2.     closeWordInput();
  3.     String cmd;
  4.     cmd = "wordAPI.exe";
  5.     try {
  6.       Runtime.getRuntime().exec(cmd).waitFor();
  7.     }
  8.     catch (Exception e) {
  9.       e.printStackTrace();
  10.       System.out.println(cmd + " could not be executed.");
  11.       System.out.println("Please ensure that WordAPI.exe may be found by java.exe by putting it in an appropriate directory.");
  12.       return false;
  13.     }
See anything anybody??
  #4  
Old June 21st, 2009, 05:27 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Word, Access and Java - suggestions


A few questions for you: where does that executable file come from and what is it supposed to do? I posted my reply just 30 minutes ago; I don't believe that you've read the documentation that comes with POI-HWPF stuff after downloading and installing it. Please first read and then code; doing it the other way around (or just doing the second) doesn't make sense because it's silly.

kind regards,

Jos

edit: now I see what you have done: you've copied and pasted an example mentioned in Val's blog without any further Java knowledge; read up on the Runtime class and understand how the example works; you only did the second without doing the first and that is just silly.
  #5  
Old June 21st, 2009, 05:37 PM
Familiar Sight
 
Join Date: Nov 2007
Posts: 153

re: Word, Access and Java - suggestions


Hi Jos,

I haven't read the poi documentation because I'm not using it as I said in my last post??

There isn't any installation documentation with what i am using but it seems so straight forward. The method documentation for what i am using can be read when my problem is solved, as it's useless to me until then.

Please believe me when i say the following - I have searched for the solution to my problem for about an hour without success. I wouldn't just ask before I've looked as - as you say it's silly.

should the following code execute if the file is there or is there an error in it?

Expand|Select|Wrap|Line Numbers
  1. cmd = "C:/Documents and Settings/Admin/My Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/wordAPI.exe";
  2.  
my program is saying it can't find the file but it's there??
  #6  
Old June 21st, 2009, 05:44 PM
Familiar Sight
 
Join Date: Nov 2007
Posts: 153

re: Word, Access and Java - suggestions


I've copied it Jos because the word template document included in the download is made for that code - I will write my own as soon as I get it working!!

I'm not silly - honest!
  #7  
Old June 21st, 2009, 05:49 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Word, Access and Java - suggestions


Quote:
Originally Posted by brendanmcdonagh View Post
I've copied it Jos because the word template document included in the download is made for that code - I will write my own as soon as I get it working!!

I'm not silly - honest!
I believe you but you have to ask yourself a question: how is the exec() method supposed to find an arbitrary wordapi.exe file? Doesn't it have to be known somewhere in the PATH of the process (note: not the CLASSPATH). The easiest way is to put the executable file in the current working directory but then you have to find out what that directory is; there is no magic involved so you can't rely on any magic.

kind regards,

Jos
  #8  
Old June 21st, 2009, 06:05 PM
Familiar Sight
 
Join Date: Nov 2007
Posts: 153

re: Word, Access and Java - suggestions


when you say path do you mean...

Expand|Select|Wrap|Line Numbers
  1.   String cmd;
  2.     cmd = "C:/Documents and Settings/Admin/My Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/wordAPI.exe";
  3.     try {
  4.       Runtime.getRuntime().exec(cmd).waitFor();
same error - can't find file but it's there
  #9  
Old June 21st, 2009, 07:11 PM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

re: Word, Access and Java - suggestions


Quote:
Originally Posted by brendanmcdonagh View Post
when you say path do you mean...

Expand|Select|Wrap|Line Numbers
  1.   String cmd;
  2.     cmd = "C:/Documents and Settings/Admin/My Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/wordAPI.exe";
  3.     try {
  4.       Runtime.getRuntime().exec(cmd).waitFor();
same error - can't find file but it's there
There are spaces in that single String cmd and Java chops up that String to get the command itself and its arguments (and of course it does it not the way you intended (no magic, remember?)); there are also overloaded exec( ... ) methods that circumvent that inconvenience.

kind regards,

Jos
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2007 XML document and the w namespace Andy answers 2 December 6th, 2006 09:55 PM
word access right selen answers 1 November 18th, 2005 03:51 AM
Future of MS ACCESS ... Uwe Range answers 33 November 13th, 2005 08:37 AM
Java's performance far better that optimized C++ Gaurav answers 133 July 22nd, 2005 03:06 PM
Object test = new Object() <-- Java, best way in C++ DrUg13 answers 11 July 22nd, 2005 07:06 AM