How to open result of workflow

Good Morning :slight_smile:
The result of my workflow is the node “Excel Writer”. The file which was created with it - is there a possibility to open it out of KNIME or only about Excel or Windows Explorer?

Thank you.
BR
Daniela

Hi,

you can use some Java code for that. Use a Java Edit Variable node which you connect to your writer:

23

Configure the Java Edit Variable node with the following code and tick “Run only on execution”:

// TODO enter your file path here, or supply it via flow variables
final File file = new File("/path/to/your/file.xls");
if (!file.exists()) {
	throw new Abort(file + " does not exist.");
}
if (!Desktop.isDesktopSupported()) {
	throw new Abort("`java.awt.Desktop` is not supported.");
}
try {
	Desktop.getDesktop().open(file);
} catch (IOException e) {
	throw new Abort("IOException when running `open`.", e);
}

Works fine on macOS. Didn’t have opportunity to test on other platforms yet.

– Philipp

2 Likes

Hi @daniela02,

Couldn’t you just click the Open File after execution box to automatically open upon completion? This is what I do…

2 Likes

Didn’t know about that option, so this is obviously much more convenient for the Excel Writer :+1:

On the other hand, my code solution posted above works for any kind of file and with nodes which do not have such an option.

3 Likes

Hi :slightly_smiling_face:
Thank´s. But I would like to open the file at anytime and not only after execution of the node.

Good Morning :slight_smile:
Thank´s a lot for your reply.

Unfortunately I am completely new at this topics.
It´s clear to me how to add the node. But it is not clear in which section I need to enter which part of your code :frowning:

May I ask you to support me once again?
Daniela

Sure, here’s the configuration in detail …:

Thank youuuu :slight_smile:

Unfortunately it seems that I made a mistake. This is what I´ve entered:

// system imports
import org.knime.base.node.jsnippet.expression.AbstractJSnippet;
import org.knime.base.node.jsnippet.expression.Abort;
import org.knime.base.node.jsnippet.expression.Cell;
import org.knime.base.node.jsnippet.expression.ColumnException;
import org.knime.base.node.jsnippet.expression.TypeException;
import static org.knime.base.node.jsnippet.expression.Type.*;
import java.util.Date;
import java.util.Calendar;
import org.w3c.dom.Document;

// Your custom imports:
import java.io.File;
import java.awt.Desktop;
import java.io.IOException;

// system variables
public class JSnippet extends AbstractJSnippet {

// Your custom variables:

// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
// TODO enter your file path here, or supply it via flow variables
final File file = new File(“H:\KNIME_TEST.xlsx”);
if (!file.exists()) {
throw new Abort(file + " does not exist.");
}
if (!Desktop.isDesktopSupported()) {
throw new Abort("java.awt.Desktop is not supported.");
}
try {
Desktop.getDesktop().open(file);
} catch (IOException e) {
throw new Abort(“IOException when running open.”, e);
}

And this is the error message:


*** Welcome to KNIME Analytics Platform v3.6.0.v201807100937 ***
*** Copyright by KNIME AG, Zurich, Switzerland ***


Log file is located at: H:\KNIME.metadata\knime\knime.log
WARN TipsAndNewsInjector Could not modify intro page: connect timed out
WARN Database Table Connector 0:8 java.lang.NullPointerException
WARN Joiner 0:5 failed to apply settings: Please define at least one joining column pair.
WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Syntax error, insert “)” to complete Expression
Error in line 29: Syntax error, insert “;” to complete BlockStatements

ERROR Java Edit Variable 2:12 Configure failed (RuntimeException): Calculation aborted: \path\to\your\file.xls does not exist.
WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Syntax error on tokens, delete these tokens

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Syntax error on tokens, delete these tokens

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 29: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 28: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 28: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 28: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 28: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

WARN Java Edit Variable 2:12 Compile with errors:
Error in line 28: Invalid escape sequence (valid ones are \b \t \n \f \r " ’ \ )

SORRY for bothering you again!!!

Probably some issue with invalid quote characters? vs. "?

I’ll attach my sample workflow here, which is probably the easiest way. From there you can simply copy + paste the “Java Edit Variable” to your workflow and adapt the path.

KNIME_Open_File.knwf (5.0 KB)

The Problem is that my path Looks like this:

H:\KNIME_TEST.xlsx

/K looks like a command but it is part of the path. I need to separate it someway.

You’ll need to escape this with another \, i.e. it becomes: H:\\KNIME_TEST.xlsx

1 Like

Great!!! It works :slight_smile: Thank´s a lot for your patience and Support!!!