From: https://www.cnblogs.com/zhangzhifeng/p/5249487.html
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCol, iRow, I, J: Integer; begin try wordApp := CreateOleObject('Word.Application'); except Application.MessageBox('Word没有安装', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL); Exit; end; Self.Chart_Edit.CopyToClipboardBitmap; wordApp.Visible := true; wordDoc:=WordApp.Documents.Add(); wordDoc.select; wrdSelection := WordApp.selection; strAdd:='XXX分析报告'; //strAdd:= Format(strAdd, [FormatDateTime('YYYY', Date), WeekofYear(Date)]); wrdSelection.ParagraphFormat.Alignment:=wdAlignParagraphCenter; // wrdSelection.Font.bold := true; // wrdSelection.Font.Size := 15; // wrdSelection.TypeText(strAdd); // wordApp.selection.TypeParagraph;//换行 // wrdSelection.Font.bold := false; // wrdSelection.Font.Size := 10; // wrdSelection.Font.bold := false; // wrdSelection.ParagraphFormat.Alignment:=wdAlignParagraphLeft; // wrdSelection.TypeText('打印时间:' + FormatDateTime('yyyy年hh月dd日 hh时MM分ss秒', Now)); // strAdd := '进样时间:' + FormatDateTime('yyyy年hh月dd日 hh时MM分ss秒', Now) + ' , 操作人:unknown'; // wrdSelection.TypeText(stradd); // wordApp.selection.TypeParagraph;//换行 // strAdd := '质检(E)字第()号'; // wrdSelection.TypeText(stradd); // wordApp.selection.TypeParagraph;//换行 // strAdd := '进样单位: ' + ' 仪器型号:SC-1001-09A'; // wrdSelection.TypeText(stradd); // wordApp.selection.TypeParagraph;//换行 // strAdd := '取样日期:' + FormatDateTime('yyyy年hh月dd日 ', Now) + ' 取样日期:' + FormatDateTime('yyyy年hh月dd日 ', Now); // wrdSelection.TypeText(stradd); // wordApp.selection.TypeParagraph;//换行 // strAdd := '样品批号: ' + ' 样品名称:固液' ; // wrdSelection.TypeText(stradd); // wordApp.selection.TypeParagraph;//换行 // strAdd := '样品罐号: ' ; // wrdSelection.TypeText(stradd); wordApp.selection.TypeParagraph;//换行 wordApp.selection.paste; wordApp.selection.TypeParagraph;//换行 wordApp.selection.TypeParagraph;//换行 wordApp.selection.TypeParagraph;//换行 wdPar:=WordApp.ActiveDocument.Paragraphs.Add; wdRange:=wdPar.Range; wdRange := wordApp.ActiveDocument.Content; wdRange.Collapse(wdCollapseEnd); iRow := SGrid_PeakResult.RowCount; iCol := SGrid_PeakResult.ColCount; wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol); for I := 0 to SGrid_PeakResult.RowCount -1 do begin for J := 0 to SGrid_PeakResult.ColCount -1 do begin wrdtable.Cell(I,J).Range.Text:= SGrid_PeakResult.Cells[J, I]; end; end; wrdtable.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleSingle; wrdtable.Borders.Item(wdBorderVertical).LineWidth:= wdLineWidth150pt; // end; |
