MSWord:=CreateOLEObject('Word.Application');//连接Word
msword.documents.add;
msword.visible:=true;
msword.ActiveDocument.PageSetup.TopMargin:=2/0.035;
msword.ActiveDocument.PageSetup.BottomMargin := 2/0.035;
msword.ActiveDocument.PageSetup.LeftMargin := 2/0.035;
msword.ActiveDocument.PageSetup.RightMargin := 2/0.035;
msword.activedocument.range(start:=0,end:=0);
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.TypeText(Text:='yubing');
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
msword.ActiveDocument.Range.InsertAfter(Text:='Titleffffffffffffff');
msword.Selection.TypeParagraph;
msword.Selection.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
//插入页眉
If msword.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
msword.ActiveWindow.Panes(2).Close;
//If msword.ActiveWindow.ActivePane.View.Type=wdNormalView Or msword.ActiveWindow.ActivePane.View.Type=wdOutlineView Then
msword.ActiveWindow.ActivePane.View.Type:=wdPrintView;
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
msword.Selection.TypeText(Text:='hjgkj');
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;
//插入页脚
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
If msword.Selection.HeaderFooter.IsHeader = True Then
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageFooter
else
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
msword.Selection.TypeText(Text:='safsdfas');
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;
//MSWord.ActiveDocument.Range.InsertAfter(Text:='Titleffffffffffffff');
odoc:=msword.activedocument;
if (row<>0) and (col<>0) then
begin
odoc.tables.add(Range:=msword.Selection.Range, NumRows:=row+1,NumColumns:=col);
//odoc.tables.add(Range:=oDoc.Range(Start:=0, End:=0), NumRows:=row+1,NumColumns:=col);
vTable:=MSWord.ActiveDocument.Tables.Item(1);
vTable.PreferredWidthType := wdPreferredWidthPercent;
vTable.PreferredWidth := 80;
vTable.Rows.Alignment :=wdAlignRowCenter;
for j:=1 to row+1 do
for i:=1 to col do
begin
if j=1 then
vTable.Cell(j, i).Range.Text :=listview1.Columns[i-1].Caption
else
if i<=listview1.Items.Item[j-2].SubItems.Count+1 then
if i=1 then
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].Caption
else
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].SubItems[i-2];
end;
end;
//MSWord.Selection.Tables(1).Select;
//MSWord.Selection.Tables.PreferredWidthType := wdPreferredWidthPercent;
//MSWord.Selection.Tables.PreferredWidth := 80;
//MSWord.Selection.Columns.PreferredWidth:=CentimetersToPoints(3.2);
//msword.Selection.MoveDown(Unit:=wdLine, Count:=row+1);
msword.Selection.GoTo(What:=wdGoToLine, Which:=wdGoToFirst, Count:=row+3, Name:='');
msword.Selection.TypeText(Text:='yubing');
MSWord.Selection.ParagraphFormat.Alignment:=wdAlignParagraphRight;
MSWord.ActiveDocument.Range.InsertAfter(Text:='ssdd');
MSword.ActiveDocument.saveas(FileName:=filename,FileFormat:=wdFormatDocument,
LockComments:=False, Password:='', AddToRecentFiles:=True, WritePassword:='',
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False);
MSword.ActiveDocument.close;
msword.quit;