Skip to main content

Write a CSV file

A short one: build a table in a Function node and write it out as a .csv file.

  1. Create a new project from the Designer.

  2. Build this flow by dragging nodes from the palette, or by right-clicking the empty canvas and searching by name.

    Flow

    Name on the canvasNode
    StartTrigger → Inject
    Prepare TableProgramming → Function
    Write CSVCSV → Write CSV
    DebugProgramming → Debug
  3. Click Prepare Table, open its editor, and paste:

    Edit Prepare Table

    msg.table = {
    columns: ["model", "year", "price"],
    rows: [
    { "model": "hyundai", "year": 1929, "price": "$4.9" },
    { "model": "bmw", "year": 1980, "price": "$9.9" }
    ]
    }
    return msg;
    note

    This { columns, rows } shape is Robomotion's data table — the same structure the Excel and CSV nodes read and write, and the same thing an Excel Get Range hands back. Nothing here is CSV-specific.

  4. Click Write CSV and set the file path and the table to write.

    Write CSV

    note

    Change the File Path to somewhere that exists on your machine.

  5. Run the flow and open the file. The columns become the header row, and each object in rows becomes a line.

    model,year,price
    hyundai,1929,$4.9
    bmw,1980,$9.9

Try changing it

  • Turn Headers off in the Write CSV options and run again — the header line disappears.
  • Swap Write CSV for Append CSV and run twice; the rows stack instead of overwriting.
  • Replace the Function node with an Excel Get Range and you have an xlsx-to-csv converter, because both nodes speak the same table shape.