word document and its pages.

N

nitm

hi,

i stumbled upon a weird behavior while trying iterate over the pages of a
word document.

i have a word 2007 document (Microsoft.Office.Interop.Word.DocumentClass)
that i get from a dsoFramer (using frame.ActiveDocument).
when i check how many pages the document has i get 37 (using:
wordDocument.ActiveWindow.ActivePane.Pages.Count), but when i try to get a
page (using: wordDocument.ActiveWindow.ActivePane.Pages, while 0 <= i <
37) i get the following exception: The requested member of the collection
does not exist.

so, i decided to try another approach:
IEnumerator enumerator =
wordDocument.ActiveWindow.ActivePane.Pages.GetEnumerator();
while (enumerator.MoveNext())
....
this results with one iteration, though i have 37 pages...

what i'm trying to do is this:
in my application the user adds an existing word (2007) document.
the application then open this document in a dsoFramer and analyze this
document, an operation that takes a while.. so i want to show the user a
ProgressBar that show how many pages the application has already analyzed.

i thought that the problem might have to do with the fact the i'm using
threads, so the thread that is doing the analyzing cant access the pages of
the document, so i fixed that using delegates and BeginInvoke and now the
thread that is iterating over the pages is the same thread that started the
document.. still the same result.

the only thing left that i can think of that is causing this weird behavior
is that the dsoFramer is not visible, that is the UserControl that holds the
dsoFramer is already constructed but is not displayed (i want to display that
control only after the document is analyzed).

can anyone think of why this is happening and how to solve this?
thanks a lot, nitzan
 
A

Andrei Smolin [Add-in Express]

Hello

You can try the ...Pages.Item(i) syntax. Also note that Office collections
starts from 1.

Regards from Belarus (GMT+2),

Andrei Smolin
Add-in Express Team Leader
www.add-in-express.com
 
N

nitm

hi,

thanks for your reply.

i figured that the collections starts from one, so now i dont have to use
the enumerator but i still only get one page while there are 37.

as for the Item syntax, it's not working.. the Pages collection dont have
that method, unless you're talking about another Pages collection (which is
not from DocumentClass.ActiveWindow.ActivePane.Pages)

thanks, nitzan.
 
T

Tony Jollans

Let me say up fron that I don't know the answer, I don't know c#, and I
don't know dsoFramer - so what I say may be no help at all; on the other
hand ...

Word doesn't really work with Page units, and determines (at run time) what
constitutes a page by reference to the current printer driver and will, at
some point in the process of delivering a page, have to repaginate according
to that driver. There is a setting (Options.Pagination) that says whether or
not this should happen in the background but it is more relevant to people
using screens than to code running. There is also a document.Repaginate
method that forces repagination. I don't know what may happen if you don't
have a printer.

The number of pages (your 37) is saved as a document property from the last
time the document was repaginated and, from what you say, you are picking
this up but it has no meaning because the Page Collection hasn't been built
in the current instance.

All I can do is suppose, but maybe you could test out some of this in your
environment - see whether explicit repagination helps, for example; it may,
however, slow things down.

Alternatively, do you actually need pages at all? Or could you use another
metric for the analysis and the progres bar? Paragraphs or Words, perhaps.

--
Enjoy,
Tony

nitm said:
hi,

i stumbled upon a weird behavior while trying iterate over the pages of a
word document.

i have a word 2007 document (Microsoft.Office.Interop.Word.DocumentClass)
that i get from a dsoFramer (using frame.ActiveDocument).
when i check how many pages the document has i get 37 (using:
wordDocument.ActiveWindow.ActivePane.Pages.Count), but when i try to get a
page (using: wordDocument.ActiveWindow.ActivePane.Pages, while 0 <= i <
37) i get the following exception: The requested member of the collection
does not exist.

so, i decided to try another approach:
IEnumerator enumerator =
wordDocument.ActiveWindow.ActivePane.Pages.GetEnumerator();
while (enumerator.MoveNext())
....
this results with one iteration, though i have 37 pages...

what i'm trying to do is this:
in my application the user adds an existing word (2007) document.
the application then open this document in a dsoFramer and analyze this
document, an operation that takes a while.. so i want to show the user a
ProgressBar that show how many pages the application has already analyzed.

i thought that the problem might have to do with the fact the i'm using
threads, so the thread that is doing the analyzing cant access the pages
of
the document, so i fixed that using delegates and BeginInvoke and now the
thread that is iterating over the pages is the same thread that started
the
document.. still the same result.

the only thing left that i can think of that is causing this weird
behavior
is that the dsoFramer is not visible, that is the UserControl that holds
the
dsoFramer is already constructed but is not displayed (i want to display
that
control only after the document is analyzed).

can anyone think of why this is happening and how to solve this?
thanks a lot, nitzan
 
N

nitm

thanks for your reply tony,

im aware that word does not work with page units and figures that out at run
time, but i do need to work with page objects...
i do have an object of my own for that, which holds information (like the
range in the DocumentClass) from word related objects.

the number of pages that i get (37) is not a document property... its the
length of a collection (DocumentClass.ActiveWindow.ActivePane.Pages.Count),
so if im getting 37 length collection it shoud have 37 members in it, no? i
mean, if what you say is true then im not getting a collection but a
pseudo-collection which is a very poor implementation from microsoft.

i will try what you suggested and hope that it helps...
thanks again, nitzan.

Tony Jollans said:
Let me say up fron that I don't know the answer, I don't know c#, and I
don't know dsoFramer - so what I say may be no help at all; on the other
hand ...

Word doesn't really work with Page units, and determines (at run time) what
constitutes a page by reference to the current printer driver and will, at
some point in the process of delivering a page, have to repaginate according
to that driver. There is a setting (Options.Pagination) that says whether or
not this should happen in the background but it is more relevant to people
using screens than to code running. There is also a document.Repaginate
method that forces repagination. I don't know what may happen if you don't
have a printer.

The number of pages (your 37) is saved as a document property from the last
time the document was repaginated and, from what you say, you are picking
this up but it has no meaning because the Page Collection hasn't been built
in the current instance.

All I can do is suppose, but maybe you could test out some of this in your
environment - see whether explicit repagination helps, for example; it may,
however, slow things down.

Alternatively, do you actually need pages at all? Or could you use another
metric for the analysis and the progres bar? Paragraphs or Words, perhaps.

--
Enjoy,
Tony

nitm said:
hi,

i stumbled upon a weird behavior while trying iterate over the pages of a
word document.

i have a word 2007 document (Microsoft.Office.Interop.Word.DocumentClass)
that i get from a dsoFramer (using frame.ActiveDocument).
when i check how many pages the document has i get 37 (using:
wordDocument.ActiveWindow.ActivePane.Pages.Count), but when i try to get a
page (using: wordDocument.ActiveWindow.ActivePane.Pages, while 0 <= i <
37) i get the following exception: The requested member of the collection
does not exist.

so, i decided to try another approach:
IEnumerator enumerator =
wordDocument.ActiveWindow.ActivePane.Pages.GetEnumerator();
while (enumerator.MoveNext())
....
this results with one iteration, though i have 37 pages...

what i'm trying to do is this:
in my application the user adds an existing word (2007) document.
the application then open this document in a dsoFramer and analyze this
document, an operation that takes a while.. so i want to show the user a
ProgressBar that show how many pages the application has already analyzed.

i thought that the problem might have to do with the fact the i'm using
threads, so the thread that is doing the analyzing cant access the pages
of
the document, so i fixed that using delegates and BeginInvoke and now the
thread that is iterating over the pages is the same thread that started
the
document.. still the same result.

the only thing left that i can think of that is causing this weird
behavior
is that the dsoFramer is not visible, that is the UserControl that holds
the
dsoFramer is already constructed but is not displayed (i want to display
that
control only after the document is analyzed).

can anyone think of why this is happening and how to solve this?
thanks a lot, nitzan

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top