I am practically done with my application and all I’m missing right now
is being able to unlink previous headers/footers so I can customize
each header/footer for each sectioned new page. I need to have total
control of the headers and footers. Please tell me that I can access
this class through Classic ASP? Thank you.
There are two overloads for this method in the API:
- HeadersFooters.LinkToPrevious Method (Boolean),
- HeadersFooters.LinkToPrevious Method (HeaderFooterType, Boolean).
Have you tried to access them LinkToPrevious and LinkToPrevious_2?
Look like there’s hope But I’m still not sure how to access the LinkToPrevious method.
This is a short
code which tests the LinkToPrevious method, hopefully someone
can spot the error:
----BEGIN----
'Load a document
Dim Word, Doc
Set Word = CreateObject(“Aspose.Word.Word”)
Set Doc = Word.Open(“C:\Inetpub\wwwroot\template.doc”)
'Create a DocumentBuilder
Dim Builder
Set Builder = CreateObject(“Aspose.Word.DocumentBuilder”)
Builder.Document = Doc
'MAIN LOGIC
Builder.Writeln “Start Aspose.Word programming here”
Builder.InsertBreak 5 '–BreakType.SectionBreakNewPage
Builder.Writeln “The cursor is in the new page”
Builder.Writeln “Lets try to unlink the current header/footer”
Builder.HeadersFooters.LinkToPrevious = 0 ’ – ERROR
–END–
I tried changing the – ERROR line to various lines such as:
Builder.HeadersFooters.LinkToPrevious = 0
Builder.HeadersFooters.LinkToPrevious 0
Builder.LinkToPrevious = 0
Builder.LinkToPrevious 0
Doc.HeadersFooters.LinkToPrevious = 0
Doc.HeadersFooters.LinkToPrevious 0
But it says the object doesn’t support HeadersFooters or LinkToPrevious.
Ok, now I've got what your problem is. HeadersFooters is actually a document section property, not of the document itself. So you need to call it with Doc.Sections(0).HeadersFooters.
I tried changing it to:
Doc.Sections(1).HeadersFooters.LinkToPrevious 0
Doc.Sections(1).HeadersFooters.LinkToPrevious = 0
Doc.Sections(1).HeadersFooters.LinkToPrevious False
Doc.Sections(1).HeadersFooters.LinkToPrevious = False
But all four lines still generates an error saying that I’m using Sections improperly.
The good news is that at least Doc.Sections object works and that I’m
just using it improperly.
So what can I do to fix the code?
Sections is a 0-based array. Which means that if you want to address the first section you need to refer it as Doc.Sections(0). Use Doc.Sections.Count to check how many sections are actually in the document. Maybe you are just trying to address section that does not exist yet.
Doc.Sections.Count returned the value 3 so I guess I’m able to access
Doc.Sections(0-2). I tried all numbers between:
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious = 0
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious 0
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious False
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious = False
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious_1 = 0
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious_1 0
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious_2 = 0
Doc.Sections(0 -
2).HeadersFooters.LinkToPrevious_2 0
but still no success. The error still says I'm using Sections improperly.
I have also tried:
Doc.HeaderFooter(1).IsLinkedToPrevious = 0
Doc.HeaderFooter(1).IsLinkedToPrevious 0
Doc.HeadersFooters(1).LinkToPrevious = 0
Doc.HeadersFooters(1).LinkToPrevious 0
Still no luck.
LinkToPrevious is a method so I guess you need to refer it as
doc.Sections(0).HeadersFooters.LinkToPrevious(True)
doc.Sections(0).HeadersFooters.LinkToPrevious(True)
Stilll doesn't work. Same improper usage of "Sections" error.
In the wiki it says
Currently there are 4 publicly creatable COM objects. Their ProgIDs are:
* "Aspose.Words.Word"
* "Aspose.Words.Document"
* "Aspose.Words.DocumentBuilder"
* "Aspose.Words.License"
I looked under Aspose.Words.Document members and I can find the
Sections Public Instance Properties. If I look at Sections Members I can't find a HeadersFooters Method but I did find a Count Property which explains why I could get a result from the section count I did earlier.
Since HeadersFooters is not a Public Instance Method of
Aspose.Words.Document or Sections, is it to my dismay and realization
that it is impossible to call the HeadersFooters.LinkToPrevious method?
To access an indexer propery from classic ASP you need to do this:
Doc.Sections.Item(0)
this code works for me:
Dim Section
Set Section = Doc.Sections.Item(0)
Section.HeadersFooters.LinkToPrevious true
If you have to deal with .NET components from a COM application, I suggest you read articles on MSDN related to .NET and COM Interop.
Yes, it works perfectly now! I suspected that I needed to Set Section = also but wasn’t sure, it would have been my last attempt. Thank you!