• Delphi 操作word 表格


    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;

  • 相关阅读:
    【小米OJ-找多少个等差数列】动态规划
    【小米OJ-找出可能的合的组合】深搜(dfs)
    【小米OJ-移除k位得到最小值】栈的应用
    【小米OJ-小米兔的轨迹】顺时针蛇形矩形
    Qt常用类
    file_operations
    Proc文件系统
    memset
    Source Insight快捷键大全
    内核内存分配
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/5249487.html
Copyright © 2020-2023  润新知