Procházet zdrojové kódy

Merge pull request #19 from chrischip/chrischip-patch-1

fix custom property name contains space problem
master
PrzemyslawKlys před 10 roky
rodič
revize
3250337aa9
1 změnil soubory, kde provedl 6 přidání a 3 odebrání
  1. 6
    3
      DocX/DocX.cs

+ 6
- 3
DocX/DocX.cs Zobrazit soubor

documents.Add(footers.even.Xml); documents.Add(footers.even.Xml);
#endregion #endregion
var matchCustomPropertyName = customPropertyName;
if (customPropertyName.Contains(" ")) matchCustomPropertyName = "\"" + customPropertyName + "\"";
string match_value = string.Format(@"DOCPROPERTY {0} \* MERGEFORMAT", matchCustomPropertyName).Replace(" ", string.Empty);
// Process each document in the list. // Process each document in the list.
foreach (XElement doc in documents) foreach (XElement doc in documents)
{ {
#region Word 2010+ #region Word 2010+
foreach (XElement e in doc.Descendants(XName.Get("instrText", w.NamespaceName))) foreach (XElement e in doc.Descendants(XName.Get("instrText", w.NamespaceName)))
{ {
string attr_value = e.Value.Replace(" ", string.Empty).Trim(); string attr_value = e.Value.Replace(" ", string.Empty).Trim();
string match_value = string.Format(@"DOCPROPERTY {0} \* MERGEFORMAT", customPropertyName).Replace(" ", string.Empty);
if (attr_value.Equals(match_value, StringComparison.CurrentCultureIgnoreCase)) if (attr_value.Equals(match_value, StringComparison.CurrentCultureIgnoreCase))
{ {
foreach (XElement e in doc.Descendants(XName.Get("fldSimple", w.NamespaceName))) foreach (XElement e in doc.Descendants(XName.Get("fldSimple", w.NamespaceName)))
{ {
string attr_value = e.Attribute(XName.Get("instr", w.NamespaceName)).Value.Replace(" ", string.Empty).Trim(); string attr_value = e.Attribute(XName.Get("instr", w.NamespaceName)).Value.Replace(" ", string.Empty).Trim();
string match_value = string.Format(@"DOCPROPERTY {0} \* MERGEFORMAT", customPropertyName).Replace(" ", string.Empty);
if (attr_value.Equals(match_value, StringComparison.CurrentCultureIgnoreCase)) if (attr_value.Equals(match_value, StringComparison.CurrentCultureIgnoreCase))
{ {
XElement firstRun = e.Element(w + "r"); XElement firstRun = e.Element(w + "r");

Načítá se…
Zrušit
Uložit