MyNixOS website logo
Description

Fast Utilities for Splitting Excel Sheets.

Provides tools for splitting large Excel worksheets into multiple smaller sheets based on a specified number of rows per chunk. The package reads Excel files, partitions the data efficiently using the 'data.table' package, and writes the resulting subsets into a single workbook with multiple sheets using the 'openxlsx' package. This is useful for handling large datasets, preparing data for reporting, and exporting manageable Excel files for downstream analysis.

A detailed description of the split_excel_to_sheets() function:


split_excel_to_sheets()

Purpose Reads a source Excel file, partitions its data into n equal-sized chunks, and writes each chunk as a separate styled sheet within a single returned workbook object.


Parameters

ParameterTypeDefaultDescription
file_pathcharacterrequiredPath to the source .xlsx file to read
nintegerrequiredNumber of splits — determines how many sheets are created
sheetinteger or character1Source sheet to read from — by index or name
output_pathcharacter or NULLNULLIf provided, saves the workbook to disk at this path; if NULL, returns in-memory only
sheet_prefixcharacter"Part"Prefix for generated sheet names — e.g. "Part"Part_1, Part_2, …
header_stylelogicalTRUEApplies a dark blue styled header row to each sheet when TRUE
col_widthscharacter or numeric"auto""auto" for openxlsx auto-sizing, a numeric vector for fixed widths, or NULL to skip entirely

What it does — step by step

Step 1 — Validate Checks that the file exists, and that n is a positive whole number. If n exceeds the number of rows, it downgrades n with a warning rather than erroring out.

Step 2 — Read Reads the source sheet using openxlsx::read.xlsx() with detectDates = FALSE for speed, then immediately converts the result to a data.table in-place via setDT().

Step 3 — Chunk Uses cut() to assign each row to a chunk group in a single vectorised operation, then data.table::split() to partition the table into a named list — no loops, no repeated subsetting.

Step 4 — Write sheets Iterates over each chunk, creates a named sheet, writes the data with writeData(), applies a pre-built header style and body style, sets column widths, and freezes the top row. The header createStyle() object is built once and reused across all sheets.

Step 5 — Save (optional) If output_path is provided, calls saveWorkbook(). Otherwise, the step is skipped and the workbook lives in memory only.


Return value

Returns the openxlsx workbook object invisibly, meaning it can be captured and further manipulated — additional sheets, summaries, or charts — before a final saveWorkbook() call.


Timing

Each of the 4 phases is timed and printed to the console via message(), giving the caller visibility into where time is being spent across large files.

Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows