Hello, I am testing the component for the first time, looking for a solution that meets me, I need is change a few words in an RTF document and insert a table of items that are in a TStringGrid, the document already exists, must open to changes to save, without user intervention. I've seen some examples nothing like this can give me the ropes?
Thank you very much!
Change RTF document
Re: Change RTF document
I have an RTF file that has header and footer when he open in a TRichViewEdit does not show the header and footer, is not supported?darkducke wrote:Hello, I am testing the component for the first time, looking for a solution that meets me, I need is change a few words in an RTF document and insert a table of items that are in a TStringGrid, the document already exists, must open to changes to save, without user intervention. I've seen some examples nothing like this can give me the ropes?
Thank you very much!
need to change text in .docx documents or RTF and add tables,
which component to use?
TRichViewEdit? TSRichViewEdit?
Thanks!
-
- Site Admin
- Posts: 17561
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1) About headers and footers.
If you will use ScaleRichView, you can define headers and footers in a single editor, TSRichViewEdit. This is the simplest solution.
If you use TRichViewEdit, you need a separate editor for each header and footer. In the simplest case: one TRichViewEdit for the main document, one TRichViewEdit for header, one TRichViewEdit for footer. However, documents may have special headers for the first page and for even pages, so you need up to 7 TRichViewEdit controls. You can find an example in Demos\DelphiUnicode\Assorted\Printing\Headers
2) This procedure creates a table from a string grid:
Adding to the end of TRichViewEdit:
Adding to the end of TSRichViewEdit:
3) For RTF, both loading and saving is supported. For DocX, only saving (it's possible to load DocX using converters and TRVOfficeConverter component, but converters may lose some formatting)
If you will use ScaleRichView, you can define headers and footers in a single editor, TSRichViewEdit. This is the simplest solution.
If you use TRichViewEdit, you need a separate editor for each header and footer. In the simplest case: one TRichViewEdit for the main document, one TRichViewEdit for header, one TRichViewEdit for footer. However, documents may have special headers for the first page and for even pages, so you need up to 7 TRichViewEdit controls. You can find an example in Demos\DelphiUnicode\Assorted\Printing\Headers
2) This procedure creates a table from a string grid:
Code: Select all
function ConvertStringGridToTable(Grid: TStringGrid; Edit: TCustomRichViewEdit;
StyleNo, ParaNo: Integer): TRVTableItemInfo;
var r,c: Integer;
begin
Result := TRVTableItemInfo.CreateEx(Grid.RowCount, Grid.ColCount, Edit.RVData);
for r := 0 to Grid.RowCount-1 do
for c := 0 to Grid.ColCount-1 do begin
Result.Cells[r,c].Clear;
Result.Cells[r,c].AddTextNL(Grid.Cells[c,r], StyleNo, ParaNo, ParaNo);
end;
end;
Code: Select all
var Table: TRVTableItemInfo;
begin
Table := ConvertStringGridToTable(StringGrid1, RichViewEdit1, 0, 0);
// define table properties, including column widths, here
RichViewEdit1.AddItem('', Table);
RichViewEdit1.Format;
end;
Code: Select all
var Table: TRVTableItemInfo;
begin
Table := ConvertStringGridToTable(StringGrid1, SRichViewEdit1.RichViewEdit, 0, 0);
// define table properties, including column widths, here
SRichViewEdit1.RichViewEdit.AddItem('', Table);
SRichViewEdit1.Format;
end;