Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Hi ,

I am using word Automation to export to word .

I am getting a exception like

ex.message gives :- Command only available in print layout view.

ex.stacktrace gives :- at Word.View.set_SeekView(WdSeekView prop)

My code is I am trying to add a Image to Header ...

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;

Can you please help me out...

I am using word 2003 and windows server 2003

Can you please help me out...

Can you please help me out...
Posted

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 
C#
oWord.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument

Arasu Elango

 
Share this answer
 
v2
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900