Task 834: .XLSB File Format

Task 834: .XLSB File Format

The file format specifications for the .XLSB file format are detailed in the Microsoft [MS-XLSB] specification, which describes it as a ZIP-based binary format for Excel workbooks, using binary records for efficiency over XML.

  1. List of all the properties of this file format intrinsic to its file system:

File extension: .xlsb

MIME type: application/vnd.ms-excel.sheet.binary.macroEnabled.12

Developer: Microsoft

Initial release: 2007 with Office 2007

Category: Spreadsheet file format

Container: ZIP archive based on Open Packaging Conventions (OPC/OOXML)

File signature (magic number): PK\003\004 (hex 50 4B 03 04)

Internal structure: ZIP package containing XML parts for relationships and content types, and binary .bin parts for workbook data

Typical internal files (parts in the ZIP file system):

[Content_Types].xml (defines content types for all parts)

_rels/.rels (package relationships)

docProps/app.xml (application properties like part counts)

docProps/core.xml (core properties like creator, date)

xl/_rels/workbook.bin.rels (workbook relationships)

xl/workbook.bin (binary workbook data with records for sheets, formulas, etc.)

xl/styles.bin (binary styles data)

xl/sharedStrings.bin (binary shared strings table)

xl/theme/theme1.xml (theme XML)

xl/worksheets/sheet1.bin (binary sheet data, can be multiple sheet*.bin)

Binary record format in .bin parts: Each record consists of a 2-byte record type, 4-byte size, and variable-length data

Byte order: Little-endian

Version information: Stored in BrtFileVersion record in workbook.bin

Macro support: Yes, macro-enabled by default

Compression: ZIP compression on parts

Advantages: Smaller file size and faster load/save compared to .xlsx for large datasets

Disadvantages: Binary, not human-readable, harder to recover from corruption

  1. Two direct download links for files of format .XLSB:

http://file.fyicenter.com/b/sample.xlsb

http://file.fyicenter.com/b/sample.xlsb (note: limited public direct links available; this is a duplicate for completeness)

  1. Ghost blog embedded HTML JavaScript for drag and drop .XLSB file to dump properties (internal files) to screen:
XLSB File Properties Dumper
Drag and drop .XLSB file here
  1. Python class to open .XLSB, decode, read, write, and print properties (internal files):
import zipfile
from io import BytesIO

class XLSBHandler:
    def __init__(self, filename):
        self.filename = filename
        self.properties = []
        self.zip_data = None

    def read_and_decode(self):
        with zipfile.ZipFile(self.filename, 'r') as z:
            self.properties = z.namelist()
            self.zip_data = BytesIO()
            with zipfile.ZipFile(self.zip_data, 'w') as new_z:
                for name in self.properties:
                    with z.open(name) as f:
                        new_z.writestr(name, f.read())
        self.print_properties()

    def print_properties(self):
        print("XLSB Properties (internal files):")
        for prop in self.properties:
            print(prop)

    def write(self, new_filename):
        if self.zip_data is None:
            raise ValueError("Read the file first")
        self.zip_data.seek(0)
        with open(new_filename, 'wb') as f:
            f.write(self.zip_data.read())

# Example usage:
# handler = XLSBHandler('sample.xlsb')
# handler.read_and_decode()
# handler.write('copy.xlsb')
  1. Java class to open .XLSB, decode, read, write, and print properties (internal files):
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

public class XLSBHandler {
    private String filename;
    private List<String> properties = new ArrayList<>();
    private byte[] zipData;

    public XLSBHandler(String filename) {
        this.filename = filename;
    }

    public void readAndDecode() throws IOException {
        try (ZipFile z = new ZipFile(filename)) {
            z.stream().forEach(entry -> properties.add(entry.getName()));
        }
        // Read to memory for write
        try (FileInputStream fis = new FileInputStream(filename);
             ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            byte[] buffer = new byte[1024];
            int len;
            while (len = fis.read(buffer) > -1) {
                baos.write(buffer, 0, len);
            }
            zipData = baos.toByteArray();
        }
        printProperties();
    }

    public void printProperties() {
        System.out.println("XLSB Properties (internal files):");
        for (String prop : properties) {
            System.out.println(prop);
        }
    }

    public void write(String newFilename) throws IOException {
        if (zipData == null) {
            throw new IllegalStateException("Read the file first");
        }
        try (FileOutputStream fos = new FileOutputStream(newFilename)) {
            fos.write(zipData);
        }
    }

    // Example usage:
    // public static void main(String[] args) throws IOException {
    //     XLSBHandler handler = new XLSBHandler("sample.xlsb");
    //     handler.readAndDecode();
    //     handler.write("copy.xlsb");
    // }
}
  1. JavaScript class to open .XLSB, decode, read, write, and print properties (internal files) (for Node.js):
const fs = require('fs');
const zipper = require('adm-zip'); // Assume adm-zip library for simplicity, or use built-in zlib for full parse

class XLSBHandler {
  constructor(filename) {
    this.filename = filename;
    this.properties = [];
    this.zipData = null;
  }

  readAndDecode() {
    const zip = new zipper(this.filename);
    this.properties = zip.getEntries().map(entry => entry.entryName);
    this.zipData = zip.toBuffer();
    this.printProperties();
  }

  printProperties() {
    console.log('XLSB Properties (internal files):');
    this.properties.forEach(prop => console.log(prop));
  }

  write(newFilename) {
    if (!this.zipData) {
      throw new Error('Read the file first');
    }
    fs.writeFileSync(newFilename, this.zipData);
  }
}

// Example usage:
// const handler = new XLSBHandler('sample.xlsb');
// handler.readAndDecode();
// handler.write('copy.xlsb');
  1. C class to open .XLSB, decode, read, write, and print properties (internal files) (simple ZIP listing using manual parse; for full, use libzip):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ZIP_LOCAL_HEADER 0x04034b50

typedef struct {
    char* name;
} Property;

typedef struct {
    char* filename;
    Property* properties;
    int prop_count;
    unsigned char* zip_data;
    size_t zip_size;
} XLSBHandler;

XLSBHandler* create_xlsb_handler(const char* filename) {
    XLSBHandler* h = malloc(sizeof(XLSBHandler));
    h->filename = strdup(filename);
    h->properties = NULL;
    h->prop_count = 0;
    h->zip_data = NULL;
    h->zip_size = 0;
    return h;
}

void read_and_decode(XLSBHandler* h) {
    FILE* f = fopen(h->filename, "rb");
    if (!f) return;
    fseek(f, 0, SEEK_END);
    h->zip_size = ftell(f);
    fseek(f, 0, SEEK_SET);
    h->zip_data = malloc(h->zip_size);
    fread(h->zip_data, 1, h->zip_size, f);
    fclose(f);

    // Simple parse for file names
    size_t offset = 0;
    while (offset < h->zip_size) {
        if (*(unsigned int*)(h->zip_data + offset) == ZIP_LOCAL_HEADER) {
            unsigned short name_len = *(unsigned short*)(h->zip_data + offset + 26);
            offset += 30;
            char* name = malloc(name_len + 1);
            strncpy(name, (char*)(h->zip_data + offset), name_len);
            name[name_len] = '\0';
            h->properties = realloc(h->properties, sizeof(Property) * (h->prop_count + 1));
            h->properties[h->prop_count].name = name;
            h->prop_count++;
            offset += name_len;
            unsigned short extra_len = *(unsigned short*)(h->zip_data + offset - 2);
            offset += extra_len;
            unsigned int compressed = *(unsigned int*)(h->zip_data + offset - 12);
            offset += compressed;
        } else {
            break;
        }
    }
    print_properties(h);
}

void print_properties(XLSBHandler* h) {
    printf("XLSB Properties (internal files):\n");
    for (int i = 0; i < h->prop_count; i++) {
        printf("%s\n", h->properties[i].name);
    }
}

void write(XLSBHandler* h, const char* new_filename) {
    if (!h->zip_data) return;
    FILE* f = fopen(new_filename, "wb");
    if (!f) return;
    fwrite(h->zip_data, 1, h->zip_size, f);
    fclose(f);
}

void destroy_xlsb_handler(XLSBHandler* h) {
    for (int i = 0; i < h->prop_count; i++) {
        free(h->properties[i].name);
    }
    free(h->properties);
    free(h->filename);
    free(h->zip_data);
    free(h);
}

// Example usage:
// int main() {
//     XLSBHandler* handler = create_xlsb_handler("sample.xlsb");
//     read_and_decode(handler);
//     write(handler, "copy.xlsb");
//     destroy_xlsb_handler(handler);
//     return 0;
// }