preserve numbered list when saving from RTF to TXT

  • Is there a simple way to preserve the RTF numbered lists when exporting to text format?

    I'm using the stringbuilder to build out my text output but in every case I lose the numbers from my numbered lists.

    For an example, create a numbered list in the WordPad5 demo and save as text. The numbers will be lost, but the text preserved.

    What is the recommended method?

    • Offizieller Beitrag

    Hi,

    You need to extract line after line in a loop over all paragraphs. (par := FirdstPar; wile par <> nil ... )

    In this loop use the TParagraph Method GetAllText:

    {:: This function reads the text of this paragraph or cell and of
    all sub paragraphs, i.e. paragraphs in a multi line cell.
    The paragraphs are seperated by #13#10 codes. }
    function GetAllText(ObjectSymbol: Boolean = FALSE;
    NumberText: Boolean = FALSE): WideString;


    Julian

  • That seems to work fine, thanks.

    like this

    Code
    str:=TWPStringBuilder.Create;  par:=DBWPRichText3.FirstPar;  while par<>nil do begin    str.Append(par.GetAllText(false,true));    str.Append(#13#10);    par:=par.next;  end;


    One possible alteration.

    I've been doing something similar to write out text files where the lines were a fixed width.
    Like this:

    Code
    str:=TWPStringBuilder.Create;
      par:=DBWPRichText3.FirstPar;
      while par<>nil do begin
        for i:=0 to par.LineCount-1 do begin
          str.Append(par.GetLineText(i);
          str.Append(#13#10);
        end;
        par:=par.next;
      end;

    Any way to combine the two so I can have my fixed width lines with the numbers?

    • Offizieller Beitrag

    Hi,

    a) You should use
    par:=par.NextPar;

    Otherwise you get the text in table cells double. (Or use GetText instead of GetAllText)

    b)

    The number text can be retrieved like this:

    var
    s: String;
    NumberStyle: TWPTextStyle;
    begin
    s := GetNumberText(NumberStyle);
    if Result <> '' then s:= s+ #32;

    This can be used for the Line #0

    Julian