Parcourir la source

Fixed the bug: loosing table design on table cloning.

OriginalTab -> CloneOfOriginalTab -> Clone of CloneOfOriginalTab did not work.
master
Viktor Loktev il y a 9 ans
Parent
révision
ec35b9248a
3 fichiers modifiés avec 49 ajouts et 15 suppressions
  1. 26
    15
      DocX/Table.cs
  2. BIN
      DocX/bin/Release/DocX.dll
  3. 23
    0
      UnitTests/DocXUnitTests.cs

+ 26
- 15
DocX/Table.cs Voir le fichier

@@ -785,19 +785,29 @@ namespace Novacode
if (design == TableDesign.Custom)
{
if (string.IsNullOrEmpty(_customTableDesignName))
{
design = TableDesign.None;
if (style != null)
style.Remove();
}
else
{
val.Value = _customTableDesignName;
}
}
else
#region Code is commented out
// The code gives a problem while copiing a table.
// Look at Test_Clone_Table_Twice method in test.
//Example:
//Table tab1 = doc.Tables[ 0 ];
//Table tab2 = doc.InsertTable( tab1 );
//Table tab3 = doc.InsertTable( tab2 ); - here we have exception at "var styleElement =" line below in this method
// The source of the problem is loosing the "<w:tblStyle w:val="a3"/>" by the commented code
//if (string.IsNullOrEmpty(_customTableDesignName))
//{
// design = TableDesign.None;
// if (style != null)
// style.Remove();
//}
//else
//{
// val.Value = _customTableDesignName;
//}
#endregion
}
else
{
switch (design)
{
@@ -1132,9 +1142,10 @@ namespace Novacode
let styleId = e.Attribute(XName.Get("styleId", DocX.w.NamespaceName))
where (styleId != null && styleId.Value == val.Value)
select e
).First();
).FirstOrDefault();
Document.styles.Element(XName.Get("styles", DocX.w.NamespaceName)).Add(styleElement);
if( styleElement != null )
Document.styles.Element(XName.Get("styles", DocX.w.NamespaceName)).Add(styleElement);
}
}
}

BIN
DocX/bin/Release/DocX.dll Voir le fichier


+ 23
- 0
UnitTests/DocXUnitTests.cs Voir le fichier

@@ -296,6 +296,29 @@ namespace UnitTests
}
}
[Test]
public void Test_Clone_Table_Twice()
{
using( var input = File.Open( Path.Combine( _directoryWithFiles, "TableSpecifiedHeights.docx" ), FileMode.Open ) )
{
using( var doc = DocX.Load( input ) )
{
// Make sure content of the file is ok for test
Assert.IsTrue( doc.Tables.Count == 1 );
Table tab1 = doc.Tables[ 0 ];
doc.InsertParagraph( "" );
Table tab2 = doc.InsertTable( tab1 );
Assert.IsTrue( doc.Tables.Count == 2 );
doc.InsertParagraph( "" );
Table tab3 = doc.InsertTable( tab2 );
Assert.IsTrue( doc.Tables.Count == 3 );
doc.SaveAs( Path.Combine( _directoryWithFiles, "TwoClonedTables.docx" ) );
}
}
}
public string ReplaceFunc(string findStr)
{
var testPatterns = new Dictionary<string, string>

Chargement…
Annuler
Enregistrer