/// <summary> /// Auto transform the template with the content from excel data. /// The content provides the template which may contain {{key}}, that will be matched from excel data /// Load the excel using the attribute or excel loader and pass to this transform /// </summary> /// <param name="content">template to transform</param> /// <param name="data">excel data either loaded from the attribute or excel loader</param> /// <returns></returns> protected string Transform(string content, ExcelData data) { if (content.IsEmpty() || data.DataContent.Keys.IsEmpty()) { return(content); } data.DataContent.Iter(k => { content = content.Replace("{{" + k.Key + "}}", k.Value); if (data.ExcelDataRaw.Sheets[data.WorkSheet].ColumnMapping.Any(x => x.Value.EqualsIgnoreCase(k.Key))) { var originalKeyName = data .ExcelDataRaw .Sheets[data.WorkSheet] .ColumnMapping .First(x => x.Value.EqualsIgnoreCase(k.Key)) .Key; content = content.Replace("{{" + originalKeyName + "}}", k.Value); } }); return(content); }
/// <summary> /// Initialize the excel attribute /// </summary> /// <param name="filename">Relative path to the excel with in the project to load</param> /// <param name="worksheet">Worksheet in the excel to load</param> /// <param name="key">The column which contains the key (unique data which can be used as key to each row)</param> /// <param name="column">The column which contains the value</param> public ExcelDataSourceAttribute(string filename, string worksheet, string key, string column) { ExcelData = new ExcelData(filename, worksheet, key, column, ""); }