Most likely some kind of document initialisation problem but nothing I have done appears to help. Do I need to explictly start a service for page numbering perhaps?
The program below is based on Bernard Marcelly's TestOpen program written for Delphi.
Code: Select all
// Initialisation
procedure ConnectOpenOffice;
begin
if IsOpenOfficeConnected then exit;
Screen.Cursor:= crHourglass; Application.ProcessMessages;
try
OpenOffice:= CreateOleObject('com.sun.star.ServiceManager');
if isNullEmpty(OpenOffice) then Raise EOOoError.Create(OOo_connectKO);
StarDesktop:= CreateUnoService('com.sun.star.frame.Desktop');
disp:= CreateUnoService('com.sun.star.frame.DispatchHelper');
OOoIntrospection:= CreateUnoService('com.sun.star.beans.Introspection');
OOoReflection:= CreateUnoService('com.sun.star.reflection.CoreReflection');
finally
Screen.Cursor:= crDefault;
end;
end;
// Program body
v := VarArrayCreate ([0, -1], varVariant);
MyDoc := StarDesktop.loadComponentFromURL('private:factory/swriter', '_blank', 0, v);
MyText:= MyDoc.Text;
MyCursor:= MyText.createTextCursor;
{ Sort out the page styles and turn the header and footer on. }
MyPageStyles := MyDoc.StyleFamilies.getByName ('PageStyles');
MyStdPage := MyPageStyles.getByName ('Standard');
MyStdPage.FooterIsOn := true;
MyStdPage.FooterHeight := 1000;
{ Write the footer text. }
MyFooter := MyStdPage.FooterText;
MyFooterText := MyFooter.Text;
MyFooterCursor := MyFooterText.createTextCursor;
MyFooterCursor.breakType := _styleBreakTypeNONE;
MyFooterCursor.charHeight := 10;
MyFooterCursor.charWeight := _awtFontWeightNORMAL;
MyFooterCursor.charFontName := 'Verdana';
MyPageNumber := MyDoc.createInstance ('com.sun.star.text.TextField.PageNumber');
MyPageNumber.NumberingType := _styleNumberingTypeARABIC;
MyFooterText.insertString (MyFooterCursor, 'PPPPage ', FALSE);
MyFooterText.insertTextContent (MyFooterCursor, MyPageNumber, FALSE);
{ Generate a couple of pages of data. }
MyText.insertString(MyCursor, OOoMess111, false);
MyText.insertControlCharacter (MyCursor, _textControlCharacterPARAGRAPH_BREAK, false);
for i := 1 to 70 do
begin
MyText.insertString(MyCursor, 'xxxxxxxx' + Tab + 'yy' + Tab + 'zzzzzzzzzz' + Tab + 'ASASA' + Tab + '66612.34566', false);
MyText.insertControlCharacter (MyCursor, _textControlCharacterPARAGRAPH_BREAK, false);
end;
The footer on the second page contains PPPPage 2
TIA, any thoughts will be most gratefully received.