StyleImportingMode Enumeration |
Specifies how style formatting is merged when importing content between different documents.
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax public enum StyleImportingMode
Public Enumeration StyleImportingMode
Members Member name | Value | Description |
---|
UseDestinationStyles | 0 |
Use the destination document styles with the same name, otherwise copy new styles. This is the default option.
|
KeepSourceFormatting | 1 |
Copy all required styles to the destination document, generate unique style names if needed.
|
KeepDifferentStyles | 2 |
Only copy styles that are different from those in the source document.
|
Example See Developer Guide: Import an Element with Styles from another document. Mode: UseDestinationStyles
Import an Element with Styles from another document. Mode: UseDestinationStyles using C#
using SautinSoft.Document;
using SautinSoft.Document.Tables;
using System.Linq;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
ImportUseDestinationStyles();
}
private static void ImportUseDestinationStyles()
{
DocumentCore source = DocumentCore.Load(@"..\..\..\SourceStyles.docx");
DocumentCore dest = new DocumentCore();
CharacterStyle chStyle = new CharacterStyle("Green");
chStyle.CharacterFormat.FontColor = Color.DarkGreen;
chStyle.CharacterFormat.Size = 24;
dest.Styles.Add(chStyle);
dest.Content.End.Insert(new Run(dest, "First ", new CharacterFormat() { Style = chStyle }).Content);
ImportSession session = new ImportSession(source, dest, StyleImportingMode.UseDestinationStyles);
Paragraph importedPar = dest.Import<Paragraph>((Paragraph)source.Sections[0].Blocks[0], true, session);
dest.Content.End.Insert(importedPar.Content);
string docPath = "UseDestinationStyles.docx";
dest.Save(docPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docPath) { UseShellExecute = true });
}
}
}
Import an Element with Styles from another document. Mode: UseDestinationStyles using VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Tables
Imports System.Linq
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
ImportUseDestinationStyles()
End Sub
Private Shared Sub ImportUseDestinationStyles()
Dim source As DocumentCore = DocumentCore.Load("..\..\..\SourceStyles.docx")
Dim dest As New DocumentCore()
Dim chStyle As New CharacterStyle("Green")
chStyle.CharacterFormat.FontColor = Color.DarkGreen
chStyle.CharacterFormat.Size = 24
dest.Styles.Add(chStyle)
dest.Content.End.Insert((New Run(dest, "First ", New CharacterFormat() With {.Style = chStyle})).Content)
Dim session As New ImportSession(source, dest, StyleImportingMode.UseDestinationStyles)
Dim importedPar As Paragraph = dest.Import(Of Paragraph)(CType(source.Sections(0).Blocks(0), Paragraph), True, session)
dest.Content.End.Insert(importedPar.Content)
Dim docPath As String = "UseDestinationStyles.docx"
dest.Save(docPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docPath) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
See Also