Hi, a newcomer here. I have a following Excel file:
I would like to take a section header into a separate column, based on the key word (“powiat”). Like here:
Which Node should I use to tell KNIME "if the row contains the keyword ‘powiat’, fill in the column ‘Powiat’ with the name for all rows until the next ‘powiat’ or the end of the file?
Thanks!
HansS
March 20, 2021, 4:05pm
2
Hi @jchabik and welcome to KNIME Forum
See this workflow extract_section_headers.knwf (21.2 KB) .
.
gr
Hans
3 Likes
Thank you @HansS !
The only solution that I found in the meantime was a simple Java Snippet:
// 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:
// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: "Nazwa" */
public String c_Nazwa;
// Fields for output columns
/** Output column: "powiat" */
public String out_powiat;
// Your custom variables:
String powiat;
// expression start
public void snippet() throws TypeException, ColumnException, Abort {
if (c_Nazwa.contains ("Powiat"))
powiat = c_Nazwa;
// Enter your code here:
out_powiat = powiat;
// expression end
}
}
…but yours seems to be more elegant and scalable!
2 Likes
system
Closed
September 19, 2021, 4:24am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.