1

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.

6
  • Have you tried anything so far? Where exactly are you stuck? Commented Feb 21, 2014 at 13:08
  • 1
    Why do you want to use Java for this? Have you thought about using VBA? Commented Feb 21, 2014 at 13:09
  • @Kayz : Thanks for replying. I have no idea where to start from. Actually i didn't encounter this type of situation earlier. Commented Feb 21, 2014 at 13:18
  • @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. :-( Commented Feb 21, 2014 at 13:20
  • @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/1390592 Commented Feb 21, 2014 at 13:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I modified the code and used it for my purpose but it is not opening any file. One more information from my side is that f.canWrite() always returns false whether the file is opened by other person or not.. I am posting my code below.. File f = new File("\\192.XXX.X.XXX:\\Project Status\\Project Status 2014.xls"); while(isActive) { if( f.canWrite() ) { try { Runtime.getRuntime().exec("excel \\192.XXX.X.XXX:\\Project Status\\Project Status 2014") ; } catch (IOException e) { e.printStackTrace(); } isActive = false; } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.