Selaa lähdekoodia

Fixed the bug: loosing table design on table cloning.

OriginalTab -> CloneOfOriginalTab -> Clone of CloneOfOriginalTab did not work.
master
Viktor Loktev 9 vuotta sitten
vanhempi
commit
ec35b9248a
3 muutettua tiedostoa jossa 49 lisäystä ja 15 poistoa
  1. 26
    15
      DocX/Table.cs
  2. BIN
      DocX/bin/Release/DocX.dll
  3. 23
    0
      UnitTests/DocXUnitTests.cs

+ 26
- 15
DocX/Table.cs Näytä tiedosto

if (design == TableDesign.Custom) 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) switch (design)
{ {
let styleId = e.Attribute(XName.Get("styleId", DocX.w.NamespaceName)) let styleId = e.Attribute(XName.Get("styleId", DocX.w.NamespaceName))
where (styleId != null && styleId.Value == val.Value) where (styleId != null && styleId.Value == val.Value)
select e 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 Näytä tiedosto


+ 23
- 0
UnitTests/DocXUnitTests.cs Näytä tiedosto

} }
} }
[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) public string ReplaceFunc(string findStr)
{ {
var testPatterns = new Dictionary<string, string> var testPatterns = new Dictionary<string, string>

Loading…
Peruuta
Tallenna