Extract section headers as a separate column

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?


Hi @jchabik and welcome to KNIME Forum

See this workflow extract_section_headers.knwf (21.2 KB) .
Schermafdruk van 2021-03-20 17-03-43 .


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!


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