//導出Word
procedure TFrm_Computing.ExportWord;
var
wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, cell: variant;
strAdd: string;
wdPar,wdRange:OleVariant;
iCol, iRow, I, J: Integer;orm
beginip
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;string
wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
wdRange.Collapse(wdCollapseEnd);
iRow := 12;
iCol := 2;
wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
wrdtable.Cell(1, 1).Merge(wrdtable.Cell(1, 2));
wrdtable.Cell(2, 1).Merge(wrdtable.Cell(2, 2));
wrdtable.Cell(1,1).Range.Text:= '打印時間:' + FormatDateTime('yyyy年hh月dd日 hh時MM分ss秒', Now);
wrdtable.Cell(2,1).Range.Text:= '進樣時間:' + FormatDateTime('yyyy年hh月dd日 hh時MM分ss秒', Now);
wrdtable.Cell(3,1).Range.Text:= '質檢(E)字第()號';
wrdtable.Cell(4,1).Range.Text:= '送樣單位:' + 'XXX公司';
wrdtable.Cell(4,2).Range.Text:= '儀器型號:' + 'SC-1001-09A';
wrdtable.Cell(5,1).Range.Text:= '取樣日期:' + FormatDateTime('yyyy年hh月dd日 ', Now);
wrdtable.Cell(5,2).Range.Text:= '收樣日期:' + FormatDateTime('yyyy年hh月dd日 ', Now);
wrdtable.Cell(6,1).Range.Text:= '樣品批號:' + '';
wrdtable.Cell(6,2).Range.Text:= '樣品名稱:' + '固液';
wrdtable.Cell(7,1).Range.Text:= '樣品罐號:' + 'A-1-2';
wrdtable.Cell(8,1).Range.Text:= '儀器文件控制參數:' + '#1111';
wrdtable.Cell(9,1).Range.Text:= '';
wrdtable.Cell(10,1).Range.Text:= 'C:\AAAAAAA\111.bmp';
wrdtable.Cell(11,1).Range.Text:= '';
wrdtable.Cell(12,1).Range.Text:= '';it
wordApp.selection.TypeParagraph;//換行
wordApp.selection.TypeParagraph;//換行io
wordApp.selection.movedown(wdLine, 17);table
wordApp.selection.paste;
wordApp.selection.TypeParagraph;//換行
wordApp.selection.TypeParagraph;//換行
wordApp.selection.TypeParagraph;//換行ast
wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
wdRange:=wdPar.Range;
wdRange := wordApp.ActiveDocument.Content;
wdRange.Collapse(wdCollapseEnd);
iRow := SGrid_PeakResult.RowCount;
iCol := SGrid_PeakResult.ColCount;
wrdtable1 := 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
//ShowMessage(SGrid_PeakResult.Cells[J, I]);
wrdtable1.Cell(I +1,J + 1).Range.Text:= SGrid_PeakResult.Cells[J, I];
end;
end;select
wrdtable1.columns.item(2).width := 80;
wrdtable1.rows.item(2).Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle; //控制單行是否有線
wrdtable1.rows.item(2).Borders.Item(wdBorderTop).LineWidth:= wdLineWidth150pt; //控制單行的樣式的線寬
wrdtable1.Rows.Item(1).Cells.VerticalAlignment:=wdCellAlignVerticalCenter;
wrdtable1.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
wrdtable1.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
wrdtable1.Borders.Item(wdBorderTop).LineWidth:= wdLineWidth150pt; //
wrdtable1.Borders.Item(wdBorderBottom).LineWidth:= wdLineWidth150pt; //
wrdtable1.Borders.Item(wdBorderBottom).LineStyle:= wdLineStyleSingle; //map
// wrdtable1.Borders.Item(wdBorderLeft).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderRight).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderTop).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderBottom).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderHorizontal).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderVertical).LineStyle:=wdLineStyleSingle;
// wrdtable1.Borders.Item(wdBorderVertical).LineWidth:= wdLineWidth150pt; //im
//選擇左邊的表格
//Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
//Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
//選擇右邊的表格
////Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
end;