1
votes

Requirement : One Excel sheet is present on a network drive say 'P:' drive whose ip address is like 192.XXX.X.XXX . This drive is mapped onto my local system. On this network drive, in a folder (name it 'My Folder') that excel sheet is present which can be accessed from many other computers. but it can be opened in editable mode on only one computer at a time.

I just want to write a desktop java program which runs in background continuously and keeps checking that excel sheet is in editable mode or not. As soon as it finds that sheet is in editable mode,program opens that excel sheet in default program on my local system.

1
Have you tried anything so far? Where exactly are you stuck?Kayz
Why do you want to use Java for this? Have you thought about using VBA?dot_Sp0T
@Kayz : Thanks for replying. I have no idea where to start from. Actually i didn't encounter this type of situation earlier.Manish
@dot_Sp0T : I want to use java for this because i know some java and i can understand the code if somebody provides. I don't know anything about VBA. :-(Manish
@Manish thing is, this is a, more or less, typical situation where you'd use a simple script instead of a fully fledged java program. After quick use of google i found this for java: stackoverflow.com/questions/1390592dot_Sp0T

1 Answers

1
votes

So basically you need whether a File has access to write or not. If writable, open with default program.

You can do this.

  run () {
     while(isActive) {
         File f = new File("book1.xlsx");
         if( f.canWrite() ) {
           Runtime.getRuntime().exec("excel book1") ;
         } else {
            sleep(time);
         }
     }
  }
} 

The above sample may help you to complete your requirement.