How to handle file auto download in internet explorer/chrome using robot framework? - download

I am trying to download few files with file type as tsv, csv, txt, xls and xlsx using Robot framework through IE/chrome but each time ,it is asking either to open, save or cancel file after clicking on download button. I want it to get auto-downloaded to specific location without asking user to perform open/save or cancel.Is there any way around this?

Related

Proper SpreadsheetML file extension

I want to create a a SpreadsheetML file on local drive which can be opened in MS Excel or Open Office by clicking on file in Windows Explorer.
I tried all filename extensions registered to Microsoft Excel i could find so far.
Some of them (.xls for example) allows file to be opened, but after "File is in different format than specified by the file extension" warning dialog. Some extensions (like .xlsx) causes Excel to show format error dialog without opening file.
Wikipedia tells that extension should be .xml, but it is registered to be opened by web browser by default.
This, this and this similar questions are about downloading a file from web and setting proper content-type. But i can not change content-type for local file.
This article explains how this annoying Extension Hardening mechanism works and how to disable it, but i think it is wrong to force user to disable security features just to allow spreadsheet file to be opened.
So there is no solution or am i missing something?
Now Open Office can open .xlsx (and read) files and Excel can open (and read) .ods files. My suggestion is to pick one of them that best suits your audience and your understanding of the specific file format.
Both of the applications have advantages and disadvanges and non-supported features between the two of them.
I suggest reviewing the document Differences between the OpenDocument Spreadsheet (.ods) format and the Excel (.xlsx) format.
When you work with two file formats, like .xlsx and .ods, there might
be formatting differences, and not all features will be available.
You’ll be able to convert data and content, but the way you work with
the content might be different depending on which formats you use.
One gotcha is with Open Office when you save a .xlsx file it will change the format to a .ods file. Both the applications will re-arrange the folder structure after saving anyway.
The biggest change is how you go about creating the SpreadsheetML files, both Open Office and Excel have a different folder structure depending on the file extension you will use.
Here is a short example of an Excel folder format.
-/
- _rels/
- .rels
- xl/
- _rels/
- workbook.xml.rels
- sheet1.xml
- workbook.xml
- [Content_Types].xml
I have created a sample GitHub repository for this with a sample that will open in both Excel and Open Office.
https://github.com/Nico-StackOverflow/proper-spreadsheetml-file-extension

Open a paperclip attached word doc in Ruby/rails

I have a rails app with file attachments using paperclip. Images and pdfs work fine in that if I click on the linked attachment, the image or pdf opens. If I right click, I can do a save-as.
However, with Office files such as word.docx, I can only download the file. If I go do Dos and type the filename, it will open in MS word. Therefore, I think that I should be able to use the system or system call and just pass the attachment name from paperclip (ie attachment.image.url) to dos and the file should open. I think the command I want would be something like
system(attachment.image.url)
I can't figure out how to write the statement to do that.
Your browser will not (and should not) allow you to execute anything outside of the browser itself, this means that without some external app making the call to your Rails app from the clients machine, you will not be able to open the Word doc without downloading it.
You are able to open the images and PDFs in the browser because the browser supports them, but most browsers won't open Word docs.
You can either have the user download the file, or maybe use a third party viewer that you can open the word doc with inside the browser.

Open Excel files on a remote computer

I want to programmatically open Excel files on a user's computer, read what is in the first cell, then save this to a mysql db on my webapp with the following info:
cell content (text)
file_updated_date (date)
Is this possible?
Will the user have to install a desktop application for me to open files on their computer, or can I get permission to run a script and return information from a website?
What language or technologies are available to open Excel files, read content, and send to an http endpoint? Is this a Ruby program?
RailsCast is going to be your friend. Learn it, like it, love it. That link should take your straight to his CSV/Excel importing video that can walk you through basically exactly what you're trying to do. As far as reading from the file goes anyways. As for writing back to the webserver, if the webserver doesn't move you can embed the address into your code and work from that. HTTPClient should be able to help you with that part.

import multiple files in the same type in sketchup ruby api

I am a beginer with ruby and sketchup.I need to select and import multiple files at the same time when open a dialog for importing. I used a class, which is inherited from Importer interface of SketchUp . But if i want to import multiple file, it means that i have to open importer dialog many time for doing that. It is inconvenience.
After importing, it is return all the paths of all file i have imported .Do you have any idea for implementing that?
Thanks you so much !
Unfortunately the Ruby API doesn't implement any API to select multiple files in a file dialog.
Further more, if you use the Importer class you are stuck with the file dialog it displays. It's single select only.
If you know all files in the folder should be read you should let the user pick a single file, then extract the path from that and read all the files from that directory.
If you drop the Importer class you can craft your own alternative. The best would then to create a Ruby C Extension that calls the OS API to display a multi-select dialog.
Alternatively, you can create a WebDialog that display the files and let the user pick multiple files. But that means you'll have to create all the UI from scratch and it'll not lok like the native OS file dialogs.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/webdialog.php
https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki
If you are making a Windows only plugin you can make use of the drag and drop feature of HTML5. Though this also has drawbacks of requiring the user to have a recent IE version. (OSX hides the WebDialogs when SU isn't active - so you cannot use it as a drop target when you drag files from Finder.)
I made a proof of concept a while back: https://github.com/thomthom/DropZone

Excel .xlsx download - sharing violation error message on Open and Save combination

I've found this question posed a few times, but no definitive answers as yet. Looks like a decent solution would help quite a few people.
So we create an excel file (.xlsx) on the server and download it to the client using content-disposition 'attachment'. The Open Save dialog appears and all works fine if you choose Save, or Open and then Save As... However if you choose Open and then hit the Save... button then Excel hangs for a moment and then presents the message:
Your changes could not be saved to 'Export[5].xlsx' because of a sharing violation. Try saving to a different file.
then:
The file you are trying to open 'F8CAC020.IE5\HM2NBE5C\F8CAC020', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
then:
you finally get the Save As: dialog (assuming you pressed 'Yes').
Code for creating the file is:
Response.Clear()
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("content-disposition", "attachment;filename=Export.xlsx")
Response.AddHeader("Content-Length", New System.IO.FileInfo(NewFile).Length)
Response.TransmitFile(NewFile)
Response.Flush()
If you remove the content-disposition header you get the right sort of behaviour in Excel, but with the wrong name and no guarantee that the Excel document will not instead be shown in the browser (depending on client settings). If you press Open and then Save then you
get a message:
'default.aspx' is read-only. To save a copy, click OK, then give the workbook a new name in the Save As dialog box.
So the question is how to combine the 2 behaviours into a reasonable one:
Get the nice error message directly above, when you try to Open and then Save a downloaded file, but also specify that the document should be downloaded and given a default filename.
Cheers,
James
I believe there is a bug in the IE file download code that does not acknowledge the completed file transfer (download) from the web server, thus leaving a connection to the downloaded (temporary) file open when the save is attempted. That generates the "sharing violation" message. I tried the same code with FireFox and I don't get the same result, which surely leads me to believe this is an IE-specific problem.
Unfortunately, given that I believe this to be a bug in IE, I don't think there is presently a clean resolution to this issue.

Resources