I want to have a line below the heading:
section.Headers.EnableHeaders:=[htDefault];
paragraph:=section.Headers.DefaultHeader.AddParagraph;
paragraph.Alignment:=taRight;
paragraph.AddText('www.nutritional-software.at :: Online Rezept Rechner :: '+FormatDateTime('dd.MM.yyyy hh:mm',now));
paragraph.Border.Borders:=[boBottom];
paragraph.Border.Bottom.Value:=bsSingle;
But this does not work. What am I missing?
Hi,
You are adding the line to the heading of that section. This seems to work here. Could you provide a code sample and maybe a word document of what you want to achieve?
On the form I have a TMSFNCWXDocx1: TTMSFNCWXDocx;
I try to compose a Word doc, the methods at the bottom are just to set default options. See the comments about the lines in the code.
Thank you for your support
The ZIP contains the docx as it is created by the code.
docxdemo.zip (7.3 KB)
!
procedure TForm2.CreateWordDoc;
var
section: TTMSFNCWXDocxSection;
paragraph: TTMSFNCWXDocxParagraph;
table: TTMSFNCWXDocxTable;
tableCell: TTMSFNCWXDocxTableCell;
TableRow: TTMSFNCWXDocxTableRow;
parText: TTMSFNCWXDocxText;
H1Font: TTMSFNCGraphicsFont;
h2font: TTMSFNCGraphicsFont;
i, j: Integer;
parfont: TTMSFNCGraphicsFont;
begin
H1Font := TTMSFNCGraphicsFont.Create;
H1Font.Size := 14;
H1Font.Style := H1Font.Style + [fsBold];
H1Font.Name := 'calibri';
h2font := TTMSFNCGraphicsFont.Create;
h2font.Size := 10;
h2font.Style := H1Font.Style + [fsBold];
h2font.Name := 'calibri';
parfont := TTMSFNCGraphicsFont.Create;
parfont.Size := 10;
parfont.Name := 'calibri';
TMSFNCWXDocx1.Document.Sections.Clear;
section := TMSFNCWXDocx1.Document.AddSection;
section.Page.Orientation := poPortrait;
section.Headers.EnableHeaders := [htDefault];
paragraph := section.Headers.DefaultHeader.AddParagraph;
paragraph.Alignment := taRight;
paragraph.AddText('www.nutritional-software.at :: Online Rezept Rechner :: ' +
FormatDateTime('dd.MM.yyyy hh:mm', now));
// How to add a bottom line?
paragraph.Border.Borders := [boBottom];
paragraph.Border.Bottom.Value := bsSingle;
section.Footers.EnableFooters := [htDefault];
paragraph := section.Footers.DefaultFooter.AddParagraph;
paragraph.Alignment := taRight;
paragraph.AddText('Seite ');
paragraph.AddPageNumber();
// How to add a top line?
paragraph.Border.Borders := [boTop];
//
paragraph := section.AddParagraph;
SetH1Paragraph(paragraph);
paragraph.AddText('Rezeptname').Font := H1Font;
//
paragraph := section.AddParagraph;
SetH2Paragraph(paragraph);
paragraph.AddText('Über das Rezept:').Font := h2font;
table := section.AddTable;
table.Width.Size := 50;
table.Width.WidthType := wtPercentage;
for i := 0 to 3 do begin
TableRow := table.AddRow;
tableCell := TableRow.AddCell;
// How to remove the lines?
tableCell.Borders.Borders:=[];
tableCell.Borders.Left.Size:=0;
tableCell.Width.WidthType := wtPercentage;
tableCell.Width.Size:=60;
paragraph := tableCell.AddParagraph;
paragraph.AddText('row ' + IntToStr(i) + ' cell ' + IntToStr(j));
tableCell := TableRow.AddCell;
tableCell.Width.WidthType := wtPercentage;
tableCell.Width.Size:=40;
paragraph := tableCell.AddParagraph;
paragraph.AddText('row ' + IntToStr(i) + ' cell ' + IntToStr(j));
end;
//
paragraph := section.AddParagraph;
SetH2Paragraph(paragraph);
paragraph.AddText('Zutaten:').Font := h2font;
//
paragraph := section.AddParagraph;
SetH2Paragraph(paragraph);
paragraph.AddText('Anleitung:').Font := h2font;
paragraph := section.AddParagraph;
SetTextParagraph(paragraph);
paragraph.AddText('lkifds vldkfj vlkedrf jvoef jvoefj voe').Font := parfont;
//
paragraph := section.AddParagraph;
SetH2Paragraph(paragraph);
paragraph.AddText('Nährwerte:').Font := h2font;
paragraph := section.AddParagraph;
paragraph.Heading := hlNone;
paragraph.AddText('Text Text').Font := parfont;
paragraph.AddText('Text1 Text1').Font := parfont;
paragraph.AddText('Text2 Text2').Font := parfont;
paragraph := section.AddParagraph;
paragraph.AddText('Text2 Text2').Font := parfont;
paragraph := section.AddParagraph;
table := section.AddTable;
table.Width.Size := 100;
table.Width.WidthType := wtPercentage;
for i := 0 to 3 do begin
TableRow := table.AddRow;
for j := 0 to 3 do begin
tableCell := TableRow.AddCell;
paragraph := tableCell.AddParagraph;
paragraph.AddText('row ' + IntToStr(i) + ' cell ' + IntToStr(j));
end;
end;
TMSFNCWXDocx1.GetDocxAsFile('docxdemo.docx');
end;
procedure TForm2.SetH1Paragraph(var paragraph: TTMSFNCWXDocxParagraph);
begin
paragraph.Heading := hlHeading1;
paragraph.Spacing.Before := 0;
paragraph.Spacing.After := 200;
end;
procedure TForm2.SetH2Paragraph(var paragraph: TTMSFNCWXDocxParagraph);
begin
paragraph.Heading := hlHeading2;
paragraph.Spacing.Before := 500;
paragraph.Spacing.After := 100;
end;
procedure TForm2.SetTextParagraph(var paragraph: TTMSFNCWXDocxParagraph);
begin
paragraph.Heading := hlNone;
paragraph.Spacing.Before := 100;
paragraph.Spacing.After := 100;
end;
Ahh! I need to set all properties, then the border is drawn.
paragraph.Border.Borders := [boBottom];
paragraph.Border.Bottom.Value := bsSingle;
paragraph.Border.Bottom.Size:=2;
paragraph.Border.Bottom.Color:='black';
However, still there is the question how to REMOVE the border from the cells.
Hi,
We've improved the component with better base values so when you add a border to the Borders property you don't need to set Value, Size & Color. These values now have base values of respectively: bsSingle, 1 & '000000'.
This change will be included in the newest update coming this week.
With kind regards