private static void ExecuteDataOnCell(ExcelWorksheet sheet, string address, ParameterData data) { string cellValue = DistinctValue(sheet.Cells[address].Value) + ""; Regex regex = new Regex(@"#\{[^\}]*\}"); if (!regex.IsMatch(cellValue)) { return; } try { bool isList = false; if (cellValue.StartsWith("#{")) { var config = ParameterConfig.CreateFromJson(cellValue.TrimStart('#')); if (config.IsSetList()) { isList = true; InsertTableData(sheet, address, config.GetTableValue(data)); } } if (!isList) { sheet.Cells[address].Value = regex.Replace(cellValue, delegate(Match match) { var config = ParameterConfig.CreateFromJson(match.ToString().TrimStart('#')); if (config.IsSetField()) { return(config.GetStringValue(data)); } return(match.ToString()); }); } } catch (Exception ex) { sheet.Cells[address].Value = ex.Message; } }
public static byte[] ExecuteTemplate(string excelFile, ParameterData data) { var stream = new MemoryStream(File.ReadAllBytes(excelFile)); return(ExecuteTemplate(stream, data)); }
public string GetStringValue(ParameterData data) { return(GetFieldValue(data) + ""); }
public byte[] ExecuteTemplate(ParameterData data) { return(ExecuteTemplate(stream, data)); }
public int GetIntValue(ParameterData data) { return(int.Parse(GetFieldValue(data) + "")); }