ExcelFlow is a domain-specific language designed for filter editing, transforming, and modulating Excel files processed with the xlsx.full.min.js library, ultimately producing CSV exports. This language emphasizes readability, flexibility, and power through a unique syntax.
An ExcelFlow script consists of a series of operations, each on a new line. Operations are grouped into blocks using indentation (2 spaces).
Variables are denoted by $
prefix and can store cell values, ranges, or intermediate results.
$var = A1
$range = A1:C10
- Single cell:
A1
,B2
, etc. - Cell range:
A1:C10
- Entire column:
A:A
,B:B
, etc. - Entire row:
1:1
,2:2
, etc.
- Filter:
filter <condition>
- Transform:
transform <operation>
- Modulate:
modulate <function>
- Export:
export <options>
Conditions use a prefix notation:
== (equal)
!= (not equal)
> (greater than)
< (less than)
>= (greater than or equal)
<= (less than or equal)
&& (and)
|| (or)
! (not)
Built-in functions:
sum()
: Sum of valuesavg()
: Average of valuescount()
: Count of cellsconcat()
: Concatenate stringssplit()
: Split string into arrayjoin()
: Join array into stringmap()
: Apply function to each elementreduce()
: Reduce array to single valuepivot()
: Create pivot table
- Pipe operator
|>
for chaining operations - Spread operator
...
for expanding ranges - Destructuring assignment for working with cell ranges
- Pattern matching for complex conditionals
- Partial application of functions using
_
placeholder
Here's an advanced example demonstrating the power and flexibility of ExcelFlow:
# Load the Excel file
load "sales_data.xlsx"
# Define variables
$sales_range = A2:E1000
$date_col = A:A
$product_col = B:B
$quantity_col = C:C
$price_col = D:D
$total_col = E:E
# Filter out rows with zero quantity
filter $sales_range |> != $quantity_col 0
# Add a new column for categorizing products
transform $sales_range |>
add_column F "Category"
map F:F {
pattern_match $product_col
case /^Electronics/ => "Tech"
case /^Clothing/ => "Apparel"
case /^Books/ => "Literature"
case _ => "Other"
}
# Calculate total revenue and add to a new column
transform $sales_range |>
add_column G "Revenue"
map G:G {
$quantity, $price = destructure $quantity_col, $price_col
* $quantity $price
}
# Modulate the date format
modulate $date_col |>
map { format_date "YYYY-MM-DD" }
# Create a pivot table for sales by category and month
$pivot_table = pivot {
source: $sales_range
rows: [F, month($date_col)]
columns: []
values: [
sum(G) as "Total Revenue"
avg(G) as "Average Revenue"
count(A) as "Number of Sales"
]
}
# Export the results
export {
filename: "sales_analysis.csv"
sheets: [
{
name: "Filtered Sales"
range: $sales_range
},
{
name: "Sales by Category and Month"
range: $pivot_table
}
]
options: {
delimiter: ","
include_headers: true
date_format: "YYYY-MM-DD"
}
}
This example demonstrates the following features:
- Loading an Excel file
- Defining variables for easy reference
- Filtering out rows with zero quantity
- Adding a new column with categorization using pattern matching
- Calculating revenue using destructuring assignment
- Modulating date format
- Creating a pivot table for sales analysis
- Exporting multiple sheets to a CSV file with custom options
The language allows for complex operations to be expressed concisely and readably, making it powerful for Excel file transformation tasks.