xsheetjs/docbits/62_columns.md
SheetJS 70c48a74b9 API Improvements
- `aoa_to_sheet` function (fixes #314 h/t @fonzy2013 @rvdwijngaard)
- `writeFileAsync` function (fixes #396 h/t @barbalex)
- `sheet_to_json` tests + docs + blankrows (fixes #602 h/t @EEaglehouse)
- write number format scan now includes every index >= 50
- propagate SSF IE8 fixes (fixes #171 h/t @sheetjsdev)
- update shim for extendscript (see #603 h/t @firas3d)
- more flow type definitions
2017-03-24 21:36:40 -04:00

1.3 KiB

Column Properties

Excel internally stores column widths in a nebulous "Max Digit Width" form. The Max Digit Width is the width of the largest digit when rendered. The internal width must be an integer multiple of the the width divided by 256. ECMA-376 describes a formula for converting between pixels and the internal width.

Given the constraints, it is possible to determine the MDW without actually inspecting the font! The parsers guess the pixel width by converting from width to pixels and back, repeating for all possible MDW and selecting the MDW that minimizes the error. XLML actually stores the pixel width, so the guess works in the opposite direction.

The !cols array in each worksheet, if present, is a collection of ColInfo objects which have the following properties:

type ColInfo = {
	MDW?:number;  // Excel's "Max Digit Width" unit, always integral
	width:number; // width in Excel's "Max Digit Width", width*256 is integral
	wpx?:number;  // width in screen pixels
	wch?:number;  // intermediate character calculation
};

Even though all of the information is made available, writers are expected to follow the priority order:

  1. use width field if available
  2. use wpx pixel width if available
  3. use wch character count if available