📄 crtableu.pas
字号:
1: ;
2: ;
3: ;
4: ;
5: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_NET');
end;
6: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_VAT');
end;
7: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'PAR_TOTAL');
par.ASetCharStyle(true, WPSTY_BOLD);
par.SetText(FloatToStr(FTotal));
end;
end;
end else // Data Rows ------------------------------
begin
case ColNr of
1: begin
par.SetText(IntToStr(RowNr - 1));
par.ASet(WPAT_ParProtected, 1);
end;
2: par.SetText(prods[RowNr - 1]);
3: par.SetText(IntToStr(prices[RowNr - 1]));
4: par.SetText(IntToStr(counts[RowNr - 1]));
5: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(2)*left(1)');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_NET');
FPrice := Round((counts[RowNr - 1] * prices[RowNr - 1]) * 100) / 100;
par.SetText(FloatToStr(FPrice));
// par.ASet(WPAT_ParProtected,1);
end;
6: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(1)*0.16');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_VAT');
vat := Round((counts[RowNr - 1] * prices[RowNr - 1]) * 0.16 * 100) / 100;
FPrice := FPrice + vat;
// par.ASet(WPAT_ParProtected,1);
par.SetText(FloatToStr(vat));
end;
7: begin
par.ASetStringProp(WPAT_PAR_COMMAND, 'left(2)+left(1)');
par.ASetStringProp(WPAT_PAR_NAME, 'PAR_TOTAL');
// par.ASet(WPAT_ParProtected,1);
par.SetText(FloatToStr(FPrice));
FTotal := FTotal + FPrice;
end;
end;
end;
end;
procedure TForm1.CreateNamedTableClick(Sender: TObject);
var par: TParagraph;
begin
FPrice := 0;
FTotal := 0;
WPRichText1.Clear;
WPRichText1.CheckHasBody;
par := WPRichText1.ActiveParagraph;
par.SetText('Use "Modify Table" to insert a row!');
par := WPRichText1.ActiveText.AppendPar(nil, par);
par.SetText('(With the calculation interface included "WPReporter" the sums would automatically update)');
par.ASet(WPAT_CharFontSize, 900);
par := WPRichText1.ActiveText.AppendPar(nil, par);
par.SetText('');
WPRichText1.BeginTable('NAME', 0, 0, 0);
par := WPRichText1.TableAdd(7, 7, [wptblActivateBorders, wptblAppendTableAtEnd], nil, InvoiceDemoCell);
WPRichText1.EndTable;
par := WPRichText1.ActiveText.AppendPar(nil, par);
par.SetText('some text');
par := WPRichText1.ActiveText.AppendPar(nil, par);
par.SetText('some text');
// ---------------------------------------------------------------------------
WPRichText1.HeaderFooter.RecalcText(true, true);
end;
procedure TForm1.ModifyNamedTableClick(Sender: TObject);
begin
WPRichText1.BeginUpdate; // Temporarily disable protection!
if not WPRichText1.MoveToTable('NAME') then
ShowMessage('Table "NAME" was not found')
else
begin
WPRichText1.TableRowNumber := WPRichText1.TableRowCount - 2;
WPRichText1.InsertRow;
WPRichText1.InputString(IntToStr(WPRichText1.TableRowNumber));
WPRichText1.TableColNumber := 2;
WPRichText1.InputString(IntToStr(Random(1000) + 1));
WPRichText1.TableColNumber := 3;
WPRichText1.InputString(IntToStr(Random(3) + 1));
end;
WPRichText1.EndUpdate;
end;
procedure TForm1.ModifyNamedTable2Click(Sender: TObject);
var par, row: TParagraph;
begin
{ TIP:
par := WPRichText1.FindParWithText('Product');
works if the table has no name but you know the text in one of the cells! }
par := WPRichText1.FindTable('NAME');
if par = nil then ShowMessage('Table "NAME" was not found') else
begin
// Get the second row from the end
row := par.Rows[par.RowCount - 2];
// Duplicate it
row := row.RowAppend;
// and add some text. The properties and formulas have been automatically duplicated!
if row <> nil then
begin
row.Cols[0].SetText(IntToStr(row.RowNr));
row.Cols[2].SetText(IntToStr(Random(1000) + 1));
row.Cols[3].SetText(IntToStr(Random(3) + 1));
end;
end;
// ---------------------------------------------------------------------------
WPRichText1.Refresh;
end;
procedure TForm1.BorderAndBackgroundsClick(Sender: TObject);
begin
// from unit WPCreateDemoText
// TWPCreateDemoText = (wpNewText, wpAppendText, wpInsertText);
CreateDemoText(WPRichText1, wpNewText);
WPRichText1.SaveToFile('c:\a.rtf');
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure TForm1.CreateTableWithImageClick(Sender: TObject);
var tbl: TParagraph;
obj: TWPTextObj;
img: TWPOImage;
imagefilename: string;
rowoffset: Integer;
begin
// Select the image from file or use a local image
imagefilename := '';
if SelectImageFile.Checked then
begin
if OpenPictureDialog1.Execute then
imagefilename := OpenPictureDialog1.FileName
else exit;
end;
// Create the image object
img := TWPOImage.Create(WPRichText1); // uses WPObj_Image
try
if imagefilename = '' then img.Picture.Assign(Image2.Picture)
else img.LoadFromFile(imagefilename);
except
img.Free; // We cannot load this image
raise;
end;
// This code is required if we do *not* use the wptblAppendTableAtEnd option.
// since than an existing table is enlarged
tbl := WPRichText1.Table;
if tbl <> nil then
begin
rowoffset := tbl.RowCount;
WPRichText1.ActiveParagraph := tbl.LastChild.ColFirst;
end
else rowoffset := 0;
// Create the table and after that modify the cells
// makes sure a new table is created at the end!
tbl := WPRichText1.TableAdd(2, 1, [wptblActivateBorders], nil, nil);
// Set text of fisrt column
tbl.Rows[rowoffset + 0].Cols[0].SetText(imagefilename);
// Create the TWPTextObj (which is the reference to image)
obj := tbl.Rows[rowoffset + 0].Cols[1].AppendNewObject(wpobjImage, false, false, 0);
obj.ObjRef := img;
obj.Frame := [wpframeFine];
// Set the size of the image
obj.Width := img.ContentsWidth * 2;
obj.Height := img.ContentsHeight * 2;
// Empty row, no borders - move cursor to first cell
WPRichText1.ActiveParagraph := tbl.ColFirst;
tbl := WPRichText1.TableAdd(2, 1, [], nil, nil);
WPRichText1.ActiveParagraph := tbl.ColFirst;
// Format and display changed text
WPRichText1.Refresh;
end;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
procedure TForm1.CreateTableCellCallBackHF(RowNr, ColNr: Integer; par: TParagraph);
begin
if RowNr = -1 then // This is the header !
begin
par.ASetColor(WPAT_BGColor, clBtnFace);
if ColNr = 1 then par.ASet(WPAT_COLWIDTH, WPCentimeterToTwips(1.5))
else par.SetText('HEADER');
end
else if RowNr = -2 then // This is the footer !
begin
par.ASetColor(WPAT_BGColor, clBtnFace);
if ColNr = 1 then par.ASet(WPAT_COLWIDTH, WPCentimeterToTwips(1.5))
else par.SetText('FOOTER');
end else
begin
if (RowNr and 1) = 0 then par.ASetColor(WPAT_BGColor, clYellow);
if ColNr = 1 then
begin
par.ASetColor(WPAT_BGColor, clBtnFace);
par.ASet(WPAT_COLWIDTH, WPCentimeterToTwips(1.5));
par.SetText(IntToStr(RowNr));
include(par.prop, paprInActive);
end else
begin
par.SetText(IntToStr(FCellNr));
inc(FCellNr);
end;
end;
end;
procedure TForm1.CreateTableWithHeaderFooterClick(Sender: TObject);
var mode : TWPTableAddOptions;
begin
WPRichText1.Clear;
FRowCount := 200;
WPRichText1.FormatOptions := [wpDisableSpeedReformat, wpfDontBreakTableRows];
mode := [wptblActivateBorders];
if MakeHeader.Checked then include(mode, wptblCreateHeaderRow);
if MakeFooter.Checked then include(mode, wptblCreateFooterRow);
WPRichText1.TableAdd(
4, FRowCount,
mode, nil, CreateTableCellCallBackHF);
WPRichText1.Refresh;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -