Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

For martynjpearson: SetDifferentFirstPageHeaderFooter...why do I get run error ??

Posted on 2003-11-24
9
349 Views
Last Modified: 2013-11-20
martyn,

Appreciate your help here again....here is my code so far for header with logo that is to be displayed on first page only:
                  COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                  //Creates new doc
                  Documents documents = application.GetDocuments();
                  _Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
            Selection selection(application.GetSelection());

                  Window oWin = application.GetActiveWindow();
                  Pane oPane = oWin.GetActivePane();
                  View oView = oPane.GetView();
                  oView.SetSeekView(wdSeekCurrentPageHeader);
                  //since a doc has already been opened, just find the active one
                  _Document oDocument = application.GetActiveDocument();//
                  PageSetup oPageSetup = oDocument.GetPageSetup();
                  //This initializes oPageSetup properly
                  oPageSetup.SetDifferentFirstPageHeaderFooter(1);                   
                  Selection oSel = application.GetSelection();
                  Shapes oShapes = oSel.GetInlineShapes();
                  oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
  //**********************************

This all compiles fine, but I get a run error from the following line:
oPageSetup.SetDifferentFirstPageHeaderFooter(1);

it tells me the parameter in incorrect: Why is this so...and can you help me out on this please ? I've got to get this working for next monday. Thanks.
Bruce
0
Comment
Question by:pigeonbr
  • 3
  • 3
9 Comments
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9816637
You could try passing VARIANT_TRUE instead of 1 - that's what I pass when I call SetDifferentFirstPageHeaderFooter().

The other thing is that when I call the function, I've got my page setup from the section, rather than the document - i.e.
   Sections sections(document.GetSections());
   Section section(sections.Item(1));
   PageSetup pageSetup(section.GetPageSetup());
   pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
However, I'm sure that getting the page setup from the document is still valid.

All the best
Martyn
0
 

Author Comment

by:pigeonbr
ID: 9842916
martyn;

Ok..things are looking up... I need some help here. I've got my footer working. My header is the way I want it for the first page, but it is showing up on all pages. Here is my code:
/*                  //**************************************
                  //Header setup with logo
                  //**************************************
                  HeaderFooter header(headers.Item(1));
                  header.SetLinkToPrevious(FALSE);
                  Range rangeHeader(header.GetRange());

                  InlineShapes shapes(rangeHeader.GetInlineShapes());
                  shapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",&varEmpty,&varEmpty,&varEmpty);
                  rangeHeader.Collapse(&varCollapse);

                  rangeHeader.InsertAfter(strHeaderText1);
                  _Font font(rangeHeader.GetFont());
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(16.0);


                  rangeHeader.InsertAfter(strHeaderText);
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(14.0);
                  font.SetUnderline(VARIANT_TRUE);

                  //Insert blank lines to start displaying the table further down so
                  //as to get just the general info on first page.
                  for(lower;lower<26;lower++)
                  {
                        selection.InsertBreak(&varLineBreak);
                        selection.Collapse(&varCollapse);
                  }
                  lower=1;

so, from the code you wrote above, I see how you setup first page from the section. I still don't understand though...how do I apply the line
pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
to the appropriate header code ?? My guess is to set up two headers, say header1 and header2, with the appropriate code like my sample above, but this code is using the Range object, and you code uses Sections and Section object...I'm lost here. Can you explain the theory behind using two different and using one for the first page only, and please give some sample code. Thanks.
0
 
LVL 8

Accepted Solution

by:
martynjpearson earned 125 total points
ID: 9848703
It could be that you have to call SetDifferentFirstPageHeaderFooter before you do any work on the headers / footers. Alternatively, you could insert a section break after the first page - you can set the headers differently for different sections. So, after the first page, call

range.InsertBreak(wdSectionBreakNextPage);

Then, you can use the code to get the different headers and footers like this :

Sections sections(document.GetSections());
for (int nSection = 1; nSection < sections.GetCount(); nSection++)
{
   Section section(sections.Item(nSection));
   HeadersFooters headers(section.GetHeaders());
   HeaderFooter header(headers.Item(1));

  // And then you can work on your header!
}

Hope this helps
Martyn
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:pigeonbr
ID: 9851805
Hi Martyn;
Ok...just got your responses to my two questions...lots of info there to sink my teeth into..:) You have answered serveral questions I was having.

One thing I would like made a little clearer is if I'm in the middle of the report, say in the second section, how can I check if I'm "after the first page" to inser tsectionbreak in this particular section since the actual number of pages depends on the unknown amount of data coming from the database CStringArray ?? I can understand the logic being applied to the first page of the whole document in my case because I will allways have the same 24 lines of client info on the first page of the document, then I can put in a section break...but in the other sections of the document, this is not the case..so how do I know when to insert the SectionBreakNextPage ?? Can i use the number of lines  ??  I guess so...but how do I go about determining the number of lines on the page? And the last page of a section will not necessarily e full...can you give me some guidelines here please martyn ?? Thanks !
0
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9866051
It's difficult to tell where page breaks occur as this could vary due to differences in fonts, page setup, etc. Are you not inserting your section breaks based on your data - i.e. <some data> section break < some different data> section break < some more unrelated data> etc?
0
 

Author Comment

by:pigeonbr
ID: 9874914
See my otehr post as to how I set up my code please.:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 169
Define unique primary key 9 95
twoTwo  challenge 35 107
abstract class with all non abstract mentods 6 79
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question