Modules@robinpath/excel
excel

@robinpath/excel

0.1.4Node.jsPublic

Read, write, and manipulate Excel spreadsheets (.xlsx)

Excel

Read, write, and manipulate Excel spreadsheets (.xlsx) with sheets, cells, JSON/CSV conversion

Package: @robinpath/excel | Category: Documents | Type: Integration

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the excel module when you need to:

  • Read an Excel file into an array of row objects -- Use excel.read to perform this operation
  • Write an array of objects to an Excel file -- Use excel.write to perform this operation
  • List all sheet names in an Excel file -- Use excel.readSheetNames to perform this operation
  • Add a new sheet with data to an existing Excel file -- Use excel.addSheet to perform this operation
  • Convert an Excel file to JSON (shortcut for read().rows) -- Use excel.toJson to perform this operation

Quick Reference

FunctionDescriptionReturns
readRead an Excel file into an array of row objects{rows, headers, sheetName, rowCount}
writeWrite an array of objects to an Excel file{path, rows, columns}
readSheetNamesList all sheet names in an Excel fileArray of sheet name strings
addSheetAdd a new sheet with data to an existing Excel file{path, sheet, rows}
toJsonConvert an Excel file to JSON (shortcut for read().rows)Array of row objects
fromJsonCreate an Excel file from JSON data{path, rows, columns}
toCsvConvert an Excel file to CSV stringCSV string
getCellGet a specific cell value{value, formula, type}
setCellSet a specific cell valueTrue

Functions

read

Read an Excel file into an array of row objects

Module: excel | Returns: object -- {rows, headers, sheetName, rowCount}

excel.read "./data.xlsx"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file
optionsobjectNo{sheet, headers}

write

Write an array of objects to an Excel file

Module: excel | Returns: object -- {path, rows, columns}

excel.write "./output.xlsx" $data {"sheetName": "Users"}
ParameterTypeRequiredDescription
filePathstringYesOutput path
dataarrayYesArray of row objects
optionsobjectNo{sheetName, colWidth, headerColor, autoFilter}

readSheetNames

List all sheet names in an Excel file

Module: excel | Returns: array -- Array of sheet name strings

excel.readSheetNames "./data.xlsx"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file

addSheet

Add a new sheet with data to an existing Excel file

Module: excel | Returns: object -- {path, sheet, rows}

excel.addSheet "./data.xlsx" "Summary" $summaryData
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file
sheetNamestringYesNew sheet name
dataarrayNoRow data

toJson

Convert an Excel file to JSON (shortcut for read().rows)

Module: excel | Returns: array -- Array of row objects

excel.toJson "./data.xlsx"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file

fromJson

Create an Excel file from JSON data

Module: excel | Returns: object -- {path, rows, columns}

excel.fromJson "./output.xlsx" $jsonData
ParameterTypeRequiredDescription
filePathstringYesOutput path
dataanyYesJSON array or string

toCsv

Convert an Excel file to CSV string

Module: excel | Returns: string -- CSV string

excel.toCsv "./data.xlsx"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file

getCell

Get a specific cell value

Module: excel | Returns: object -- {value, formula, type}

excel.getCell "./data.xlsx" "B2"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file
cellstringYesCell reference (e.g. 'A1')
sheetstringNoSheet name (optional)

setCell

Set a specific cell value

Module: excel | Returns: boolean -- True

excel.setCell "./data.xlsx" "A1" "Hello"
ParameterTypeRequiredDescription
filePathstringYesPath to .xlsx file
cellstringYesCell reference
valueanyYesCell value
sheetstringNoSheet name (optional)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Sheet "..." not foundCheck the error message for details
@desc "Read and validate result"
do
  set $result as excel.read "./data.xlsx"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Cell

Retrieve all items and loop through them.

@desc "Get cell and iterate results"
do
  set $result as excel.getCell "./data.xlsx" "B2"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with addSheet

Create a new resource and capture the result.

set $result as excel.addSheet "./data.xlsx" "Summary" $summaryData
print "Created: " + $result

3. Check before creating

List existing items and only create if needed.

@desc "Get cell and add sheet"
do
  set $existing as excel.getCell "./data.xlsx" "B2"
  if $existing == null
    excel.addSheet "./data.xlsx" "Summary" $summaryData
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Excel workflow

Chain multiple excel operations together.

@desc "Read, write, and more"
do
  set $r_read as excel.read "./data.xlsx"
  set $r_write as excel.write "./output.xlsx" $data {"sheetName": "Users"}
  set $r_readSheetNames as excel.readSheetNames "./data.xlsx"
  print "All operations complete"
enddo

5. Safe read with validation

Check results before proceeding.

@desc "Read and validate result"
do
  set $result as excel.read "./data.xlsx"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • pdf -- PDF module for complementary functionality
  • office -- Office module for complementary functionality
  • docusign -- DocuSign module for complementary functionality
  • pandadoc -- PandaDoc module for complementary functionality
  • hellosign -- HelloSign module for complementary functionality

Versions (1)

VersionTagPublished
0.1.4latest1 months ago
Install
$ robinpath add @robinpath/excel

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.4
LicenseMIT
Unpacked Size11.8 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

productivity