Group:  Microsoft Word ยป microsoft.public.word.oleinterop
Thread: ApplyTheme partially works in Office2003

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

ApplyTheme partially works in Office2003
Olivier B. 28.07.2006 13:55:01
Hi,

I've got a weird problem. I create a word document by copying the content of
an existing one using the OrganizerCopy and Range methods (C#, .NET 1.1).
Then I copy the theme of the source document using the ActiveTheme property
and then the ApplyTheme method.

Everything works fine, but when I open the copy the theme isn't applied.
When I check in "Format -> Theme", I see it is selected with the parameters I
applied.

Here is the code of my SaveCopyAs method :
**********************************************************
public override void SaveCopyAs(string fileName)
{
DocumentWrapper doc =
(DocumentWrapper)ApplicationWrapper.GetApplicationWrapper(this.GetProperty("Application")).Documents.Add(false);

//Copy styles
StylesWrapper styles = doc.Styles;

for (int i=1;i<=styles.Count;i++)
{
if(styles[i].InUse)
{
ApplicationWrapper m_app = (ApplicationWrapper) ApplicationWrapper.GetApplicationWrapper(this.GetProperty("Application"));
m_app.OrganizerCopy( this.FullName,doc.FullName,styles[i].NameLocal,ApplicationWrapper.WdOrganizerObject.wdOrganizerObjectStyles
);
}
}

//Copy datas in the new document
//Remark : the range object returns the text but with a carriage return
character at the end of the range (/r)
//This character must be removed
if (Characters.Count > 1)
{
RangeWrapper range = Range(0,Characters.Count-1);
range.Copy();
range = doc.Range();
range.Paste();
}

//Copy the headers and the footers in the new document
//Remark : the range object returns the text but with a carriage return
character at the end of the range (/r)
//This character must be removed. Unfortunately the range property of the
headerfooter object allows only
//to retrieve the complete text. So we use the text property to put the
right text in the clipboard.
for (int i=1;i<=Sections[1].Headers.Count;i++)
{
string header = Sections[1].Headers[i].Range.Text;
if (header.Substring(0,header.Length-1)!="")
{
System.Windows.Forms.DataObject dobj = new
System.Windows.Forms.DataObject(header.Substring(0,header.Length-1));
System.Windows.Forms.Clipboard.SetDataObject(dobj);
doc.Sections[1].Headers[i].Range.Paste();
}
}

for (int i=1;i<=Sections[1].Footers.Count;i++)
{
string footer = Sections[1].Footers[i].Range.Text;
if (footer.Substring(0,footer.Length-1)!="")
{
System.Windows.Forms.DataObject dobj = new
System.Windows.Forms.DataObject(footer.Substring(0,footer.Length-1));
System.Windows.Forms.Clipboard.SetDataObject(dobj);
doc.Sections[1].Footers[i].Range.Paste();
}
}

//Copy Theme
doc.ApplyTheme(this.ActiveTheme);

//Save document
doc.SaveAs(fileName);
doc.Close();

//Empty the clipboard
System.Windows.Forms.Clipboard.SetDataObject(new
System.Windows.Forms.DataObject());

}
************************************************************

I'm quite sure I did it right ...

Does anybody knows if there is a known bug about that ? What else could I do ?

Thanks.

Olivier

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net