Beispiel #1
0
 public static void ReplaceData(Newtonsoft.Json.Linq.JObject dtInfo, DocX doc)
 {
     if (dtInfo != null)
     {
         foreach (var member in dtInfo.Properties().ToList())
         {
             string value = "";
             var    lines = member.Value.ToString().Split(new[] { Environment.NewLine },
                                                          StringSplitOptions.RemoveEmptyEntries);
             for (int i = 0; i < lines.Length; i++)
             {
                 if (i == 0)
                 {
                     value = lines[i];
                 }
                 else
                 {
                     value = value + "\r" + lines[i];
                 }
             }
             if (member.Name == "age")
             {
                 value = LabelHelper.GetAgeFromText(value);
             }
             doc.ReplaceText("{" + member.Name + "}", ReplaceHexadecimalSymbols(value));
         }
     }
 }
Beispiel #2
0
 public static void ReplaceData(Dictionary <string, string> dictionaryData, DataTable dtInfo, DocX doc, bool hidden = false)
 {
     if (dictionaryData != null && dictionaryData.Count > 0)
     {
         foreach (var item in dictionaryData)
         {
             string value = "";
             var    lines = (item.Value + "").Split(new[] { Environment.NewLine },
                                                    StringSplitOptions.RemoveEmptyEntries);
             for (int i = 0; i < lines.Length; i++)
             {
                 if (i == 0)
                 {
                     value = lines[i];
                 }
                 else
                 {
                     value = value + "\r" + lines[i];
                 }
             }
             if (item.Key.StartsWith("wd_char"))
             {
                 var format = new Formatting();
                 format.Size       = item.Key.Split('|').Length > 1 ? int.Parse(item.Key.Split('|')[1]) : 15;
                 format.FontFamily = new Novacode.Font("Wingdings 2");
                 format.Hidden     = false;
                 var  tmp  = int.Parse(value);
                 char tick = (char)tmp;
                 doc.ReplaceText("{" + item.Key.Split('|')[0].Replace("wd_char_", "") + "}", tick.ToString(), newFormatting: format);
             }
             else if (item.Key.StartsWith("wd1_char"))
             {
                 var format = new Formatting();
                 format.Size       = 9;
                 format.FontFamily = new Novacode.Font("Wingdings");
                 format.Hidden     = false;
                 var  tmp  = int.Parse(value);
                 char tick = (char)tmp;
                 doc.ReplaceText("{" + item.Key.Replace("wd1_char_", "") + "}", tick.ToString(), newFormatting: format);
             }
             else
             {
                 var format = new Formatting();
                 format.Hidden = false;
                 doc.ReplaceText("{" + item.Key + "}", ReplaceHexadecimalSymbols(value), newFormatting: hidden || value == "(" || value == ")" ? format : null);
             }
         }
     }
     else if (dtInfo != null && dtInfo.Rows.Count > 0)
     {
         foreach (DataRow r in dtInfo.Rows)
         {
             foreach (DataColumn c in dtInfo.Columns)
             {
                 string value = "";
                 var    lines = Convert.ToString(r[c.ColumnName]).Split(new[] { Environment.NewLine },
                                                                        StringSplitOptions.RemoveEmptyEntries);
                 for (int i = 0; i < lines.Length; i++)
                 {
                     if (i == 0)
                     {
                         value = lines[i];
                     }
                     else
                     {
                         value = value + "\r" + lines[i];
                     }
                 }
                 if (c.ColumnName == "age")
                 {
                     value = LabelHelper.GetAgeFromText(value);
                 }
                 doc.ReplaceText("{" + c.ColumnName + "}", ReplaceHexadecimalSymbols(value));
             }
         }
     }
 }