%

% Copyright 2017-2018 The MathWorks, Inc.
function addColumnToTable(this, column)
    prevCol = this.TypesCol;
    [stringArray, this.TypesCol] = column.toStringArray(this.TypesCol);
    locAlignBlockPaths(this, prevCol);
    stringArray = this.enforceRectangularData('M', stringArray, "");
    this.M{:, this.CurrentCol} = stringArray;
    this.CurrentCol = this.CurrentCol + 1;
end

function locAlignBlockPaths(this, prevCol)
    % check if any block paths were added, if so add whitespace after
    % previous block paths so that everything aligns horizontally
    import xls.internal.MetadataTypes;
    if isempty(prevCol)
        return;
    end

    bpDif = sum(this.TypesCol==MetadataTypes.BlockPath) - ...
        sum(prevCol==MetadataTypes.BlockPath);
    if bpDif > 0
        idx = find(this.TypesCol == MetadataTypes.BlockPath, 1, 'last');
        this.M = [ ...
            this.M(1:idx, :); ...
            cellstr(strings(bpDif, size(this.M, 2))); ...
            this.M(idx+1:end, :)];
    end
end
