zoukankan      html  css  js  c++  java
  • delphi 712 Word 2

    //导出Word
    procedure TFrm_Computing.ExportWord(aFileName: string; aFileType: string);
    var
    wordApp, WordDoc, WrdSelection, wrdtable, wrdtable1, cell: variant;
    strAdd: string;
    wdPar,wdRange:OleVariant;
    iCol, iRow, I, J: Integer;
    vNode: TcxTreeListNode;
    vcolumn: TcxTreeListColumn;
    str: string;
    begin

    try
    wordApp := CreateOleObject('Word.Application');
    except
    Application.MessageBox('Word没有安装', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
    Exit;
    end;
    Self.cht_Edit.CopyToClipboardBitmap;
    wordApp.Visible := false;
    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;

    wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
    wdRange:=wdPar.Range;
    wdRange := wordApp.ActiveDocument.Content;
    //该方法用于将指定区域折叠到起始位置或结束位置。
    wdRange.Collapse(wdCollapseEnd);

    iRow := RzRichEdit_ReportTop.Lines.Count;
    iCol := 1;
    wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
    for I := 0 to RzRichEdit_ReportTop.Lines.Count -1 do
    begin
    wrdtable.Cell(I, 1).Range.Text := RzRichEdit_ReportTop.Lines.Strings[I];
    end;

    wordApp.selection.TypeParagraph;//换行

    wordApp.selection.movedown(wdLine, 17);


    wordApp.selection.paste;
    wordApp.selection.TypeParagraph;//换行
    wordApp.selection.TypeParagraph;//换行


    wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
    wdRange:=wdPar.Range;
    wdRange := wordApp.ActiveDocument.Content;
    wdRange.Collapse(wdCollapseEnd);

    iRow := SGrid_PeakResult.Count;
    iCol := SGrid_PeakResult.ColumnCount;
    wrdtable1 := wordDoc.Tables.Add(wdRange,iRow, iCol);
    for I := 0 to SGrid_PeakResult.Count -1 do
    begin
    vNode := SGrid_PeakResult.Items[I];
    for J := 0 to SGrid_PeakResult.ColumnCount -1 do
    begin
    vcolumn := SGrid_PeakResult.Columns[J];
    wrdtable1.Cell(I +1,J + 1).Range.Text:= vNode.Texts[vcolumn.ItemIndex];
    end;
    end;

    wrdtable1.columns.item(2).width := 60;
    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.columns.item(3).width := 60;
    wrdtable1.columns.item(4).width := 60;
    wrdtable1.columns.item(8).width := 60;

    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; //

    wdPar:=WordApp.ActiveDocument.Paragraphs.Add;
    wdRange:=wdPar.Range;
    wdRange := wordApp.ActiveDocument.Content;
    //该方法用于将指定区域折叠到起始位置或结束位置。
    wdRange.Collapse(wdCollapseEnd);

    iRow := RzRichEdit_ReportBottom.Lines.Count;
    iCol := 1;
    wrdtable := wordDoc.Tables.Add(wdRange,iRow, iCol);
    for I := 0 to RzRichEdit_ReportBottom.Lines.Count -1 do
    begin
    wrdtable.Cell(I, 1).Range.Text := RzRichEdit_ReportBottom.Lines.Strings[I];
    end;


    wordApp.Visible := True;
    if AnsiSameText(aFileType, 'doc') then
    begin
    wordDoc.saveas(aFileName, wdFormatDocument);
    end
    else if AnsiSameText(aFileType, 'rtf') then
    begin
    str := aFileName;
    str := ChangeFileExt(str , '.rtf');
    wordDoc.saveas(str, wdFormatRTF);
    end;

    end;

  • 相关阅读:
    SpringCloud-Bus总线的其他应用场景(发布-订阅)
    Java的静态代理和动态代理
    为什么重写equals还要重写hashcode?(转载)
    js通过replace()方法配合正则去除空格
    2016-08-15T16:00:00.000Z 格式转换成yyyy-MM-dd HH:mm:ss格式
    js任意数组按下标相加
    学习笔记《Java多线程编程实战指南》四
    学习笔记《Java多线程编程实战指南》三
    学习笔记《Java多线程编程实战指南》二
    学习笔记《Java多线程编程实战指南》一
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/5385980.html
Copyright © 2011-2022 走看看