将模板附加到Word文档 [英] Attaching template to Word document

查看:193
本文介绍了将模板附加到Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

-我在Word 2007中有一个带有页眉/页脚的模板.
-我有Word文档(2007)
-我打开word文档并附加模板(使用C#)
-页眉/页脚未显示

有人知道为什么吗?它不应该出现吗? (当我尝试在Word中执行此操作时也不会显示)
(不过,字符样式已更新.只是没有页眉/页脚!)

问候,

VJ

Hi!

- I have a template in Word 2007 with a header/footer.
- I have a word document (2007)
- I open the word document and attach the template (with C#)
- The header/footer does not show up

Anyone know why? Is it not supposed to appear? (It does not show up when I try to do it in Word, either)
(The character-styles are updated, though. Just not the header/footer!)

Regards,

VJ

推荐答案

我不知道模板文件中的标头和页脚是否核心添加. 我使用此代码添加标头的任何方式,都对我造成了困扰
但我没有尝试附加文件
但无论如何,我希望这段代码对您有用.
//
//在文档中嵌入徽标

//在页面标题上设置焦点以嵌入水印

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;



//将LOGO分配给形状对象,以便我们可以使用所有

//当前针对形状对象的形状格式选项

Word.Shape logoCustom = null;



//要在标题中嵌入LOGO文件的路径

字符串logoPath ="C:\\ Document and Settings \\ MyLogo.jpg";

logoCustom = oWord.Selection.HeaderFooter.Shapes.AddPicture(logoPath,

ref oFalse,ref oTrue,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);



logoCustom.Select(ref oMissing);

logoCustom.Name ="CustomLogo";

logoCustom.Left =(float)Word.WdShapePosition.wdShapeLeft;



//将焦点返回到文档

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
i don''t know if in template file the header adn footer add corectly.
any way i used this code to add header and it wroked with me
but i didn''t tried to attach the file
but any way i hope this code to be useful to u .
//
//EMBEDDING LOGOS IN THE DOCUMENT

//SETTING FOCUES ON THE PAGE HEADER TO EMBED THE WATERMARK

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;



//THE LOGO IS ASSIGNED TO A SHAPE OBJECT SO THAT WE CAN USE ALL THE

//SHAPE FORMATTING OPTIONS PRESENT FOR THE SHAPE OBJECT

Word.Shape logoCustom = null;



//THE PATH OF THE LOGO FILE TO BE EMBEDDED IN THE HEADER

String logoPath = "C:\\Document and Settings\\MyLogo.jpg";

logoCustom = oWord.Selection.HeaderFooter.Shapes.AddPicture(logoPath,

ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);



logoCustom.Select(ref oMissing);

logoCustom.Name = "CustomLogo";

logoCustom.Left = (float)Word.WdShapePosition.wdShapeLeft;



//SETTING FOCUES BACK TO DOCUMENT

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;


非常感谢dabbourabd!

该代码完成了我想要的.

现在唯一的问题是在附加模板时使其正常工作. :confused:

(想象一下,有50个人都拥有一个名为"default.dotx"的模板,
当文档打开时,应附加模板,并且所有用户的文档格式应不同X | )
Thanks alot dabbourabd!

That code did what I wanted.

The only problem now is getting it to work when attaching templates. :confused:

(Imagine 50 people all having a template called "default.dotx",
when the document opens the template should be attached and the document be formatted differently for all users X| )


这篇关于将模板附加到Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆