%

% Copyright 2017-2020 The MathWorks, Inc.
function headers = createColumnHeaders(this, parsedVar, dataValues, parsedElem)
    import xls.internal.WriteTable;
    valueDimensions = removeTimeDimension(parsedVar, size(dataValues));
    allDims = WriteTable.getAllDimensions(valueDimensions);

    headers = createDataHeader(this, parsedVar, dataValues, allDims', parsedElem);
end

function valueDimensions = removeTimeDimension(parsedVar, valueDimensions)
    valueDimensions(parsedVar.getTimeDim) = [];
end

function headers = createDataHeader(this, parsedVar, dataValues, allDims, parsedElem)
    wtd = this.getWriteTableDimensions(dataValues, allDims);
    headers = wtd.toString(parsedVar.VariableName);

    if isenum(dataValues) || isstring(dataValues)
        % convert to string so that <missing> values can be used for padding
        data = string([wtd.data]);
    else
        data = [wtd.data];
        if any(isnan(data))
            error(message('sl_xls:WriteTable:CannotWriteNaN', parsedElem.getBlockSource));
        end

        if ~islogical(data)
            % write numeric data to table as double
            data = double(data);
        end
    end
    reader = xls.internal.reader.getReader(data);
    data = this.enforceRectangularData('D', data, reader.getMissing);
    this.D{:, end+1 : end+numel(wtd)} = data;
end
