Trying delete first page from a DOCX

Questions and answers on how to use DOCXReadWrite
Post Reply
aristeo
Posts: 9
Joined: Sun Sep 17, 2017 8:47 pm

Trying delete first page from a DOCX

Post by aristeo »

I'm trying delete first page of a document with this code:

Code: Select all

var
  i:Integer;
  Temp:String;
begin
  F:TForm;
  with TDOCXReadWrite.Create(nil) do
    try
      LoadFromFile(Path);
      F:=TForm.Create(nil);
      try
        with TAXWPreviewVcl.Create(nil) do
         try
           Parent:=F;
           Document:=Editor;
           Paint;
           Editor.Pages.Delete(0);           
           ShowMessage(IntToStr(Editor.Pages.Count));
           SaveToFile(Path);
         finally
           Free;
         end;
      finally
        FreeANdNil(F);
      end;
    finally
      Free;
    end;
end;
When ShowMessage is executed, the page count showed is ok... The Editor.Pages.Delete(0) worked ok however when the document is saved the first page isn't delete.

What's the problem? Thanks
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Trying delete first page from a DOCX

Post by larsa »

Hello

To delete a specific page, use code like this:

Code: Select all

DOCX.Editor.MainDoc.Selections.Add(DOCX.Editor.MainDoc.Pages[0].FirstPos.Para,
                                   DOCX.Editor.MainDoc.Pages[0].FirstPos.CharPos,
                                   DOCX.Editor.MainDoc.Pages[0].LastPos.Para,
                                   DOCX.Editor.MainDoc.Pages[0].LastPos.CharPos);
DOCX.Editor.MainDoc.Selections.Delete;
Lars Arvidsson, Axolot Data
Post Reply