Word自动化问题导出到Word [英] Word Automation Problem Exporting to Word

查看:183
本文介绍了Word自动化问题导出到Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Word Automation导出为word.

I am using word Automation to export to word .

我遇到了

示例消息给出:-仅在打印版式视图中可用的命令.

ex.stacktrace在Word.View.set_SeekView(WdSeekView prop)上给出:-

我的代码是我正在尝试向页眉添加图片...

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

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

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

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

logoCustom.Select(

logoCustom.Select(

logoCustom.Name =

logoCustom.Name =

logoCustom.Left =(

logoCustom.Left = (

String logoPath = GetImgPath(); ref oFalse,ref oTrue,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing); ref oMissing);"CustomLogo"; float)WdShapePosition.wdShapeLeft;

String logoPath = GetImgPath();ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);ref oMissing);"CustomLogo";float)WdShapePosition.wdShapeLeft;

oWord.ActiveWindow.ActivePane.View.SeekView =

oWord.ActiveWindow.ActivePane.View.SeekView =

WdSeekView.wdSeekMainDocument;

WdSeekView.wdSeekMainDocument;

你能帮我吗...

我正在使用Word 2003和Windows Server 2003

I am using word 2003 and windows server 2003

你能帮我吗...

推荐答案

在查看错误时,文档活动窗口似乎在NormalView中或ReadingView.在继续执行oWord.ActiveWindow.ActivePane.View.SeekView命令之前,您必须将视图"设置为wdPrintView(或其他选择之一).

On looking at the error, it looks like the document active window is in the NormalView or ReadingView. You would have to set the View to wdPrintView (or one of the other choices) before proceeding to the oWord.ActiveWindow.ActivePane.View.SeekView command.

oWord.ActiveWindow.ActivePanel.View = wdPrintView

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

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

logoCustom.Select(

logoCustom.Name = 

logoCustom.Left = (String logoPath = GetImgPath();ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);ref oMissing);"CustomLogo";float)WdShapePosition.wdShapeLeft;

//SETTING FOCUES BACK TO DOCUMENT 

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

Arasu Elango

Arasu Elango


您好

感谢您的回应,终于我解决了,这是我的代码

//创建新的Word文档并添加标题,然后复制temp Location文档的内容并保存
试试
{
//缺少空值"的对象
对象oMissing = System.Reflection.Missing.Value;

对象oEndOfDoc ="\\ endofdoc"; /* \ endofdoc是预定义的书签*/

Word.ApplicationClass oWord = null;
Word.Document oWordDoc = null;
Word.Document oWordDoc1 = null;


//虚假和真实的对象
对象oTrue = true;
对象oFalse = false;


oWord =新的Word.ApplicationClass();

//使应用程序可见
oWord.Visible = false;

//为应用程序添加新文档
oWordDoc = oWord.Documents.Add(ref oMissing,ref oMissing,ref oMissing,ref oMissing);



//打开内容文档
oWordDoc1 =新的Word.Document();
对象getPath = GetUploadErrDirPath()+ sbuilder.ToString();
oWordDoc1 = oWord.Documents.Open(ref getPath,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing);

//将内容复制到新文档
oWordDoc1.ActiveWindow.Selection.WholeStory();
oWordDoc1.ActiveWindow.Selection.Copy();
oWordDoc.ActiveWindow.Selection.PasteAndFormat(WdRecoveryType.wdPasteDefault);

Word.Sections mySections = oWordDoc.Sections;
Word.HeaderFooter myHeader = mySections.First.Headers [Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
myHeader.Range.Select();
对象oLine = Word.WdUnits.wdLine;
oWord.Selection.EndKey(ref oLine,ref oFalse);
对象oRange = oWord.Selection.Range;
字符串sImgPath = GetImgPath();
oWord.Selection.InlineShapes.AddPicture(sImgPath.Trim(),ref oFalse,ref oTrue,ref oRange);


oWordDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oWordDoc.ShowSpellingErrors = false;



////需要保存文件的位置
sbuilder.Remove(0,sbuilder.Length);
sbuilder.Append("POTemplate");
sbuilder.Append(Session.SessionID);
sbuilder.Append(DateTime.Now.Ticks.ToString());
sbuilder.Append(.doc");
对象oSaveAsFile =(Object)GetUploadErrDirPath()+ sbuilder.ToString();
oWordDoc.SaveAs(ref oSaveAsFile,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing);
Hi

Thanks for the Response finally i solved it here is my code

//Creating a new word doc and adding header and copying the content of temp Location doc and saving
try
{
//OBJECT OF MISSING "NULL VALUE"
Object oMissing = System.Reflection.Missing.Value;

object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */

Word.ApplicationClass oWord = null;
Word.Document oWordDoc = null;
Word.Document oWordDoc1 = null;


//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
Object oFalse = false;


oWord = new Word.ApplicationClass();

//MAKING THE APPLICATION VISIBLE
oWord.Visible = false;

//ADDING A NEW DOCUMENT TO THE APPLICATION
oWordDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);



//Open Content Document
oWordDoc1 = new Word.Document();
object getPath = GetUploadErrDirPath() + sbuilder.ToString();
oWordDoc1 = oWord.Documents.Open(ref getPath,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

//Copy the Contents to New Document
oWordDoc1.ActiveWindow.Selection.WholeStory();
oWordDoc1.ActiveWindow.Selection.Copy();
oWordDoc.ActiveWindow.Selection.PasteAndFormat(WdRecoveryType.wdPasteDefault);

Word.Sections mySections = oWordDoc.Sections;
Word.HeaderFooter myHeader = mySections.First.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
myHeader.Range.Select();
object oLine = Word.WdUnits.wdLine;
oWord.Selection.EndKey(ref oLine, ref oFalse);
object oRange = oWord.Selection.Range;
string sImgPath = GetImgPath();
oWord.Selection.InlineShapes.AddPicture(sImgPath.Trim(), ref oFalse, ref oTrue, ref oRange);


oWordDoc.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
oWordDoc.ShowSpellingErrors = false;



////THE LOCATION WHERE THE FILE NEEDS TO BE SAVED
sbuilder.Remove(0, sbuilder.Length);
sbuilder.Append("POTemplate");
sbuilder.Append(Session.SessionID);
sbuilder.Append(DateTime.Now.Ticks.ToString());
sbuilder.Append(".doc");
Object oSaveAsFile = (Object)GetUploadErrDirPath() + sbuilder.ToString();
oWordDoc.SaveAs(ref oSaveAsFile, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);


这篇关于Word自动化问题导出到Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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