zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    Spring(九)之事件处理
    Spring(八)之基于Java配置
    Spring(七)之基于注解配置
    Spring(六)之自动装配
    Spring(五)之Bean定义继承和依赖注入
    Spring(四)之Bean生命周期、BeanPost处理
    开源 视频会议 收藏
    摄像头拍照录相代码,没摄像头测试,
    什么是ICE (Internet Communications Engine)
    AForge.NET Framework-2.2.5
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/5249487.html
Copyright © 2011-2022 走看看