procedure TForm1.Button1Click(Sender: TObject);
var
Document: TvVectorialDocument;
Page: TvTextPageSequence;
BoldTextStyle: TvStyle;
HeaderParagraph, Paragraph: TvParagraph;
DaysTable: TvTable;
Row: TvTableRow;
Cell, Cell2: TvTableCell;
intRow, intTotalRows: integer;
DaysArray, HoursWorkedArray: array of string;
begin
//
DaysArray := ['DAYS', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
HoursWorkedArray := ['HOURS WORKED', '4', '7', '8', '8', '4', '8', '0'];
// Create the document
Document := TvVectorialDocument.Create;
//
try
// Adds the defaut Paragraph Styles
// StyleTextBody, StyleHeading1,
// StyleHeading2 & StyleHeading3
Document.AddStandardTextDocumentStyles(vfUnknown);
// Add our own Style
BoldTextStyle := Document.AddStyle();
BoldTextStyle.Kind := vskTextSpan;
BoldTextStyle.Name := 'Bold';
BoldTextStyle.Font.Bold := True;
BoldTextStyle.SetElements := BoldTextStyle.SetElements + [spbfFontBold];
// Add a page and a paragraph
Page := Document.AddTextPageSequence;
//
HeaderParagraph := Page.AddParagraph;
HeaderParagraph.Style := Document.StyleHeading1Centralized;
HeaderParagraph.AddText('WORK SCHEDULE');
HeaderParagraph := Page.AddParagraph;
// Add the Days table
DaysTable := Page.AddTable;
DaysTable.PreferredWidth := Dimension(100, dimPercent);
DaysTable.ColWidthsUnits := dimMillimeter;
// Add 2 columns
DaysTable.AddColWidth(50);
DaysTable.AddColWidth(50);
// Get the number of rows to add to the table
intTotalRows := Length(DaysArray);
//
for intRow := 0 to Pred(intTotalRows) do
begin
Row := DaysTable.AddRow;
if intRow = 0 then
begin
Row.BackgroundColor := RGBToFPColor(192, 192, 192); // Grey Shading
Row.Header := True; // Tell the table this is a Header Row
end;
Cell := Row.AddCell;
Paragraph := Cell.AddParagraph;
Paragraph.Style := Document.StyleTextBody;
Paragraph.AddText(DaysArray[intRow]).Style := BoldTextStyle;
end;
try
// Save the document
Document.WriteToFile('Work schedule.docx', vfDOCX);
except
raise;
end;
finally
Document.Free;
end;
end;