• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphi712Word2

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi-窗体创建过程发布时间:2022-07-18
下一篇:
[代码]Delphi实现检测程序是否在VMWare中运行发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap