Skip to main content

Blazing Fast Data Processing with V8

V8 is an embeddable JavaScript engine written in C++. It powers Chromium and Chrome, NodeJS and Deno, Adobe UXP and other platforms.

SheetJS is a JavaScript library for reading and writing data from spreadsheets.

This demo uses V8 and SheetJS to read and write spreadsheets. We'll explore how to load SheetJS in a V8 context and process spreadsheets and structured data from C++ and Rust programs.

The "Complete Example" creates a C++ command-line tool for reading spreadsheet files and generating new workbooks. "Bindings" covers V8 engine bindings for other programming languages.

Integration Details

The SheetJS Standalone scripts can be parsed and evaluated in a V8 context.

Initialize V8

The official V8 hello-world example covers initialization and cleanup. For the purposes of this demo, the key variables are noted below:

v8::Isolate* isolate = v8::Isolate::New(create_params);
v8::Local<v8::Context> context = v8::Context::New(isolate);

The following helper function evaluates C strings as JS code:

v8::Local<v8::Value> eval_code(v8::Isolate *isolate, v8::Local<v8::Context> context, char* code, size_t sz = -1) {
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, code, v8::NewStringType::kNormal, sz).ToLocalChecked();
v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked();
return script->Run(context).ToLocalChecked();

Load SheetJS Scripts

The main library can be loaded by reading the scripts from the file system and evaluating in the V8 context:

/* simple wrapper to read the entire script file */
static char *read_file(const char *filename, size_t *sz) {
FILE *f = fopen(filename, "rb");
if(!f) return NULL;
long fsize; { fseek(f, 0, SEEK_END); fsize = ftell(f); fseek(f, 0, SEEK_SET); }
char *buf = (char *)malloc(fsize * sizeof(char));
*sz = fread((void *) buf, 1, fsize, f);
return buf;

// ...
size_t sz; char *file = read_file("xlsx.full.min.js", &sz);
v8::Local<v8::Value> result = eval_code(isolate, context, file, sz);

To confirm the library is loaded, XLSX.version can be inspected:

  /* get version string */
v8::Local<v8::Value> result = eval_code(isolate, context, "XLSX.version");
v8::String::Utf8Value vers(isolate, result);
printf("SheetJS library version %s\n", *vers);

Reading Files

V8 supports ArrayBuffer natively. Assuming buf is a C byte array, with length len, this snippet stores the data as an ArrayBuffer in global scope:

/* load C char array and save to an ArrayBuffer */
std::unique_ptr<v8::BackingStore> back = v8::ArrayBuffer::NewBackingStore(isolate, len);
memcpy(back->Data(), buf, len);
v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, std::move(back));
v8::Maybe<bool> res = context->Global()->Set(context, v8::String::NewFromUtf8Literal(isolate, "buf"), ab);

/* parse with SheetJS */
v8::Local<v8::Value> result = eval_code(isolate, context, "globalThis.wb =");

wb will be a variable in the JS environment that can be inspected using the various SheetJS API functions.

Writing Files

The underlying memory from an ArrayBuffer can be recovered:

/* write with SheetJS using type: "array" */
v8::Local<v8::Value> result = eval_code(isolate, context, "XLSX.write(wb, {type:'array', bookType:'xlsb'})");

/* pull result back to C++ */
v8::Local<v8::ArrayBuffer> ab = v8::Local<v8::ArrayBuffer>::Cast(result);
size_t sz = ab->ByteLength();
char *buf = ab->Data();

The resulting buf can be written to file with fwrite.

Complete Example

Tested Deployments

This demo was tested in the following deployments:

V8 VersionPlatformOS VersionCompilerDate
12.1.131darwin-x64macOS 14.1clang 15.0.02023-11-15
12.1.283darwin-armmacOS 14.1.2clang 15.0.02023-12-01
12.0.265win10-x64Windows 10CL 19.37.328222023-10-28
12.3.50linux-x64HoloOS 3.5.7gcc 13.1.12024-01-26
11.8.82linux-armDebian 12gcc 12.2.02023-12-01

This program parses a file and prints CSV data from the first worksheet. It also generates an XLSB file and writes to the filesystem.

When the demo was last tested, there were errors in the official V8 embed guide. The correct instructions are included below.

The build process is long and will test your patience.


0) Prepare /usr/local/lib:

mkdir -p /usr/local/lib
cd /usr/local/lib

If this step throws a permission error, run:

sudo mkdir -p /usr/local/lib
sudo chmod 777 /usr/local/lib

1) Download and install depot_tools:

git clone

If this step throws a permission error, run:

sudo mkdir -p /usr/local/lib
sudo chmod 777 /usr/local/lib

2) Add the path to the PATH environment variable:

export PATH="/usr/local/lib/depot_tools:$PATH"

At this point, it is strongly recommended to add the line to a shell startup script such as .bashrc or .zshrc

3) Run gclient once to update depot_tools:


Clone V8

4) Create a base directory:

mkdir -p ~/dev/v8
cd ~/dev/v8
fetch v8
cd v8

Note that the actual repo will be placed in ~/dev/v8/v8.

5) Checkout the desired version. The following command pulls 12.3.50:

git checkout tags/12.3.50 -b sample

The official documentation recommends:

git checkout refs/tags/12.3.50 -b sample -t

This command failed in local testing:

E:\v8\v8>git checkout refs/tags/12.3.50 -b sample -t
fatal: cannot set up tracking information; starting point 'refs/tags/12.3.50' is not a branch

Build V8

6) Build the static library.

tools/dev/ x64.release.sample
ninja -C v8_monolith

7) Ensure the sample hello-world compiles and runs:

g++ -I. -Iinclude samples/ -o hello_world -fno-rtti -lv8_monolith \
-lv8_libbase -lv8_libplatform -ldl -pthread \

Prepare Project

8) Make a new project folder:

cd ~/dev
mkdir -p sheetjs-v8
cd sheetjs-v8

9) Copy the sample source:

cp ~/dev/v8/v8/samples/ .

10) Create symbolic links to the include headers and obj library folders:

ln -s ~/dev/v8/v8/include
ln -s ~/dev/v8/v8/

11) Build and run the hello-world example from this folder:

g++ -I. -Iinclude -o hello_world -fno-rtti -lv8_monolith \
-lv8_libbase -lv8_libplatform -ldl -Lobj/ -pthread -std=c++17 \

Add SheetJS

12) Download the SheetJS Standalone script and test file. Save both files in the project directory:

curl -LO
curl -LO

13) Download

curl -LO

14) Compile standalone sheetjs.v8 binary

g++ -I. -Iinclude -o sheetjs.v8 -fno-rtti -lv8_monolith \
-lv8_libbase -lv8_libplatform -ldl -Lobj/ -pthread -std=c++17 \

15) Run the demo:

./sheetjs.v8 pres.numbers

If the program succeeded, the CSV contents will be printed to console and the file sheetjsw.xlsb will be created. That file can be opened with Excel.


Bindings exist for many languages. As these bindings require "native" code, they may not work on every platform.


The v8 crate provides binary builds and straightforward bindings. The Rust code is similar to the C++ code.

Pulling data from an ArrayBuffer back into Rust involves an unsafe operation:

/* assuming JS code returns an ArrayBuffer, copy result to a Vec<u8> */
fn eval_code_ab(scope: &mut v8::HandleScope, code: &str) -> Vec<u8> {
let source = v8::String::new(scope, &code).unwrap();
let script = v8::Script::compile(scope, source, None).unwrap();
let result: v8::Local<v8::ArrayBuffer> =;
/* In C++, `Data` returns a pointer. Collecting data into Vec<u8> is unsafe */
unsafe { return std::slice::from_raw_parts_mut(<u8>().as_ptr(),
).to_vec(); }
Tested Deployments

This demo was last tested in the following deployments:

ArchitectureV8 CrateDate

1) Create a new project:

cargo new sheetjs-rustyv8
cd sheetjs-rustyv8
cargo run

2) Add the v8 crate:

cargo add v8
cargo run

3) Download the SheetJS Standalone script and move to the project directory:

curl -LO

4) Download and replace src/

curl -L -o src/

5) Download the test file and run:

curl -LO
cargo run pres.numbers

If the program succeeded, the CSV contents will be printed to console and the file sheetjsw.xlsb will be created. That file can be opened with Excel.