C
Chris Ellis
Hi,
I'm writing an add-in for Word 2007 in C#. I saw an add-ins newsgroup,
but I'm a beginner at this, and I think my question more pertains to the
object model for Word, etc... I am trying to copy a section of a document to
a new document, formatting and all. This is the code I currently have:
public static Document[] SplitDocsOnSectionBreaks( Document doc )
{
Application app = Globals.ThisAddIn.Application;
Sections sections = doc.Sections;
object missing = Type.Missing;
Document[] ret = new Document[ sections.Count ];
int x = 0;
// walk through the separate sections of the document copying the entire
contents of
// the section into a new document
foreach( Section curSec in sections )
{
Document newDoc = app.Documents.Add( ref missing, ref missing, ref
missing, ref missing );
object zero = (int)0;
newDoc.Range( ref zero, ref zero ).FormattedText =
curSec.Range.FormattedText;
ret[ x++ ] = newDoc;
}
return ret;
}
On some documents this works perfectly, but on other documents the
formatting is incorrect in the new documents (wrong font and font size). Am
I going about this the wrong way? I could use the clipboard I suppose, but
I would prefer not to if it can be avoided.
Thank you in advance for your help,
Chris
I'm writing an add-in for Word 2007 in C#. I saw an add-ins newsgroup,
but I'm a beginner at this, and I think my question more pertains to the
object model for Word, etc... I am trying to copy a section of a document to
a new document, formatting and all. This is the code I currently have:
public static Document[] SplitDocsOnSectionBreaks( Document doc )
{
Application app = Globals.ThisAddIn.Application;
Sections sections = doc.Sections;
object missing = Type.Missing;
Document[] ret = new Document[ sections.Count ];
int x = 0;
// walk through the separate sections of the document copying the entire
contents of
// the section into a new document
foreach( Section curSec in sections )
{
Document newDoc = app.Documents.Add( ref missing, ref missing, ref
missing, ref missing );
object zero = (int)0;
newDoc.Range( ref zero, ref zero ).FormattedText =
curSec.Range.FormattedText;
ret[ x++ ] = newDoc;
}
return ret;
}
On some documents this works perfectly, but on other documents the
formatting is incorrect in the new documents (wrong font and font size). Am
I going about this the wrong way? I could use the clipboard I suppose, but
I would prefer not to if it can be avoided.
Thank you in advance for your help,
Chris