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.

Leo Pflug
  • 544
  • 3
  • 15
Manish
  • 157
  • 1
  • 2
  • 10
  • Have you tried anything so far? Where exactly are you stuck? – Kayz Feb 21 '14 at 13:08
  • 1
    Why do you want to use Java for this? Have you thought about using VBA? – dot_Sp0T Feb 21 '14 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. – Manish Feb 21 '14 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. :-( – Manish Feb 21 '14 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: http://stackoverflow.com/questions/1390592 – dot_Sp0T Feb 21 '14 at 13:28
  • @dot_Sp0T : Can we check whether that excel file is in editable mode? Please go through my requirement once. If it can be done with VBA then i will sure go with that. – Manish Feb 21 '14 at 13:28

1 Answers1

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.

vels4j
  • 11,208
  • 5
  • 38
  • 63
  • 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; } } – Manish Feb 22 '14 at 08:16