Excel writer - output file is read only

Does anyone have any tips on how to handle a loop writing excel files if one or more of the files are open by users they are ‘read only’ and the workflow seems to stop. I either need to just by-pass that file or somehow check before the write the file status and only write if it is OK to do so.

Hi @bradley_peter ,

You can wrap the Excel writer node in a try-catch block

Hopefully the attached workflow will provide the example you need.
In the upper flow, the first Excel writer writes data to a file in the workflow data folder called File3.xlsx. It is set to open the file after writing.

The second table creator contains a list of files to which data must be written. This list includes “File3.xlsx”. It loops through the list and fails when it attempts to write File3.xlsx. This simulates, I believe , the situation you are describing.

So ensure Excel is closed. Run this top workflow and it will fail as show in the above image.

The lower workflow implements a try-catch pattern

In addition, whenever the Excel writer within the loop successfully writes a file, the current file name from the iteration is written out by the CSV Writer to a log file.

If the loop fails, the workflow commences at the Catch-Errors node, using the variable flow taken from the start of the Try-catch block.
Even though Excel fails to write File3.xlsx, the workflow runs to completion.

Again, ensure that Excel is not open prior to starting the lower flow, then execute that flow and you will find that it completes. If you inspect the log file you will see it does not write File3.xlsx within the loop.

I have added a “convenience component” called Open File or Folder to this flow. This is just here to help with the demo. It performs two functions. Standalone, the one at the bottom right of the flow, the node can be reset and then executed in isolation to quickly open the workflow data folder in Explorer. That makes it easy for you to find the log file.

The copy of that component within the loop is used to provide a quick path to the workflow data folder. There are other ways of achieving the same thing, and that component is not a necessary part of the demo, but just there for my convenience! Hope that helps

Catch ReadOnly Excel Writer.knwf (194.2 KB)


Thanks for the response - those nodes sound like what I am after. Should the below work as I thought I’d write all of the files to a temp location and transfer them (if they are not open) to the destination. If they are open - the user can get the file from the temp location when they have closed the original.
The flow seems to stop and not do any of the other rows if the first row/file is opened.

@bradley_peter I think you would have to add an option what to do if the task fails. This example will do nothing if one branch does fail and move to the next step:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.