I'm automating a scenario in which I need excel file to be updated with current date on daily basis( using java or any macro).For this to update on daily basis,I need to open and close the file so that it can save the current date.I'm using a continuous integration system where in, automation gets triggered at 5am.Before it triggers,I need to open the file and close.
I tried open and close using JXL.But, i'm not sure of reference issues which might get disturbed.
Can this be somehow automated?
Thanks in advance.
You can call a java function that returns the current date and write it to the excel file using jxl.
To make it automated visit this http://www.advancedinstaller.com/java.html. Set this to auto start service. I guess that will solve your problem.
Related
I am using Selenium and I need to upload an image to instagram. But at the time the windows file selector opens I could not get it to search for the image and upload it automatically
Up to this point my application opens well, when it goes to the point of selecting the file it does not do it automatically
I tried using the following codes without success
driver.findElement(By.className(name)).send_keys('C:\\path-to-file\\file.jpg')
But it gives me back the value of the second photo, that is, it generates a file selector from the main folder and not the one that I pass through as a parameter
I am using the following versions:
Java: 8
Selenium: 3.14
ChromeDriver: 76
Normal browsers don't allow JavaScript any access to the local disk. This is basic security. Imagine what would happen if you visit some site and it reads your local password file or any other important data without asking you.
If you want to upload files, take some standalone application or write a small utility that will do that. For instance, try instapy, you can find it pypi.org or on github. It is a matter of taste, the other can prefer other tools. Just try several tools and see which fits your need better.
The window opened for file explorer is not part of the browser and therefore it can not be interacted with via selenium. The solution to this is a software called AutoIt. Use the following link for a guide on how to use AutoIt for file uploads : Link
My application saves excel file data in a database (mongodb) using java.
On user click my application will do
First create an excel file on local filesystem for instance C:\ali.xlsx and place data on excel file .
Open excel file C:\ali.xlsx using java.awt.Desktop class open method for the cross platform perspective.
When user close file C:\ali.xlsx gets its close event so that i will get file updated value and save it to the database.
Delete the file C:\ali.xlsx from the local filesystem.
My Question :
How to implement the third bullet point. In short : how to get close event of any file using java.
If anyone have another approach to implement this functionality please tell me also that's why I write the application flow .
I don't know any straightforward way, the uphill (:-)) way would be:
watch file system with WatchService, (tutorial)
in case of modification of the Excel file check if it's open in processes list and if not - follow with next step.
If I understand correctly you have an Excel sheet and you want to save this data to mongodb every time it gets updated.
There is no trigger available for what you ask. Instead you can keep reading the file at regular intervals and check the "lastModified" attribute. Or as you are deleting the file every time it means if it exists you have an update.
Let me first describe where I am. For readability, that will take three paragraphs.
Original Problem: I am working on a php website, one function of which is to read data from a Word file users upload and then insert the entry into some database. Note: the server is running windows (devil windows!).
My Solution: Write a java program to do the word file reading and database inserting stuff, using java Apache POI library. Then execute the java program in one bat file. Then new problem occurs...
New Problem: How can we make a specific bat file run on a specific file system event? In my case, the event will be file creation in one assigned folder.
Wish I have made myself totally understood. Waiting for your help. Any suggestion is appreciated.
If I were you, I would implement some kind of scheduled task(http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx) on the server that runs the Java app you have for adding the files. Depending on your traffic, you could set it to run every 5 minutes, or every 5 hours, or whatever.
That Java app would then do this:
Look at that directory
If it sees some file(s), loads the file(s) into the database
When it is finished loading the files, it would delete them from the directory (so it doesn't add them the next time the task executes).
At the same time, I'm surprised you're not implementing something with PHP through the web app. If your website is already in php, wouldn't it make sense to keep this application logic as part of the PHP stuff as well? To each their own.
If you went the php route, a super simple approach would be this:
have some page submit_doc.php with a form where users can upload a doc
when they hit the submit button, some other php file would execute, say upload_doc.php
upload_doc.php would handle connecting to the db and adding the file to the db
In my java application I am connecting to Microsoft Excel with Jacob libraries. Everything is fine but I do not know how I can catch com events when any changes in Excel page occurs by using Jacob libraries. For example, In my project I connect database takes table values and copy these values into cells of an excel page. Whenever a cell value is changed, the table value is also changed. That's I want synchronization between java and Microsoft Excel application by Jacob.
Don't use Java to achieve that. See this question: Excel OnChange event, with emphasis on this answer. You should access your database using com directly from Excel. That's easy using ADO. This ADO tutorial from w3schools looks also fine.
If the task is too complex to perform directly from Excel you may think of putting a small marker somewhere (e.g. in the database) that the data changed and process this marker from other app, possibly java app. The difficulty is that the credentials to access the database must be hardcoded in the Excel sheet. But you can create a separate database user with narrow database permissions.
Seeing your comment I also tried using Change event of Excel to detect changes done by other users. My experience on Excel 2003 shows that this works only locally. That is the event is fired only for the user that made the change. If many users have the worksheet open they don't receive Change event caused by changes from other users. So your approach is unfeasible. You may test it with Excel 2010, but my impression is that the events in general work only locally. Couldn't find anything on the net about it. Only this general article: Track changes in a shared workbook.
I am using Java to develop an application, it needs to manage the file on the computer. The application have the ability/function to delete the file on the system. But I want to check whether the selected file is using/reading by another application or not first. Because I don't want to delete the file which is reading/using. How can I do so?
Maybe you could use tryLock()?
On Windows, you can't delete files which are in use ("locked"). Java itself doesn't offer an API to check.
If another application is using the file or actively reading it, then provided that application has done its job correctly (opening the file with a read lock), you won't be able to delete the file -- you'll get an IOException (specifically, a sharing violation). Catch the exception to know whether there was a problem.