- Offizieller Beitrag
Q: How do I get text from WPRichText with the CRs intact?
A: The ANSI writer creates \r\n at the end of every paragraph (not line!) :
Code
function TWPTextWriter.WriteParagraphEnd(par : TParagraph; ParagraphType : TWPParagraphType; NeedNL :Boolean): Boolean;begin if NeedNL then Result := WriteString(#13+#10) else Result := TRUE;end;
If you need to get CR NL for every wrapped line use this code:
Code
var par : TParagraph;
lin : Integer;
str : TWPStringBuilder;
begin
str := TWPStringBuilder.Create;
par := WPRichText1.BodyText.FirstPar;
while par<>nil do
begin
if not (par.ParagraphType in [wpIsTable, wpIsTableRow]) then
for lin := 0 to par.LineCount-1 do
begin
str.Append(par.GetSubText(
par.LineOffset(lin),
par.LineLength(lin)) );
str.Append(#13+#10);
end;
par := par.next;
end;
ShowMessage(str.GetString);
str.Free;
end;
Alles anzeigen