Hi,
I’ve noticed that conditional table padding styles (checked for FirstRow in particular) have a somewhat unexpected interaction with inline (as in - defined for specific instance of a table) styles in imported tables.
I’m adding a table style (named Circle Table in my specific case) to a document created in aspose. This style defines padding for entire table, and padding specifically for first row. I then import into this document two tables from another (created with word) document. Both of the imported tables use a style under the same name (Circle Table), but one of the tables had its paddings changed directly (for both first row and whole table). I perform the import with the option “UseDestinationStyles”. In the resulting document, the table that had no direct formatting fully takes on the properties of the Circle Table style from the created document, while in the one that had spacings applied directly table body keeps the direct styles and in heading they are overriden by the Circle Table styles from the target document. While I do expect the attributes from Circle Table from source doc to be overriden with the ones in target doc, I would expect the direct formatting to be kept.
When I used a document prepared with Word Interop that contained Circle Style as the target document instead, direct formatting was kept, so I think this is the expected behavior.
I’m using code as follows to replicate this behavior:
internal class Program
{
static void Main(string[] args)
{
ApplyLicense();
//load reference and source, create Aspose document
var docFromOldEngine = new Document(@"OldEmpty.docx");
var sourceDocument = new Document(@"src.docx");
var madeWithAspose = new Document();
//Add Circle Table style to the empty Aspose document
var style = (TableStyle)madeWithAspose.Styles.Add(StyleType.Table, "Circle Table");
style.TopPadding = 50;
style.Shading.BackgroundPatternColor = Color.Aqua;
style.ConditionalStyles.FirstRow.BottomPadding = 50;
style.ConditionalStyles.FirstRow.Shading.BackgroundPatternColor = Color.Blue;
//Save Empty Aspose document
madeWithAspose.Save(@"AsposeEmpty.docx");
//import tables to both documents
MergeTablesIntoDocument(sourceDocument, docFromOldEngine);
MergeTablesIntoDocument(sourceDocument, madeWithAspose);
//save both
madeWithAspose.Save(@"AsposeWithTables.docx");
docFromOldEngine.Save(@"OldWithTables.docx");
}
private static void MergeTablesIntoDocument(Document sourceDocument, Document targetDocument)
{
var importer = new NodeImporter(sourceDocument,
targetDocument,
ImportFormatMode.UseDestinationStyles);
var builder = new DocumentBuilder(targetDocument);
builder.Writeln("spacing paragraph");
foreach (var table in sourceDocument.FirstSection.Body.Tables)
{
var imported = importer.ImportNode(table, true);
targetDocument.FirstSection.Body.InsertBefore(imported,
targetDocument.FirstSection.Body.LastParagraph);
builder.Writeln("spacing paragraph");
}
}
private static void ApplyLicense()
{
var wordsLicense = new License();
wordsLicense.SetLicense(@"path to licence");
}
}
I’m also attaching a zip with a sample solution and both src.docx and OldEmpty.docx. I think the difference comes from how the first row is created in Aspose, as the same odd interaction (first row direct formatting padding overridden, body direct formatting padding retained) happens when the tables are copied from src.docx into AsposeEmpty.docx manually.
Could you advise whether it is possible to apply first row style in a way that allows the direct formatting of paddings to be retained in Aspose?
Thanks
CellMarginsDirectFormatting.zip (34.1 KB)