我承认,标题是夸大了,就是为了吸引注意力。这里只有Word文档和Excel文档的预览代码。
Word:
//此部分来源:http://princed.mblogger.cn/posts/11885.aspx
//uses ActiveX;
procedure TForm1.MenuPreviewClick(Sender: TObject);
var
IOO: IOleInPlaceObject ;
begin
OleContainer1.DoVerb(ovShow);
if OleContainer1.State in [osUIActive] then
begin
OleContainer1.OleObjectInterface.QueryInterface(IOleInPlaceObject,IOO);
IOO.UIDeactivate;
IOO :=nil;
end;
OleContainer1.OleObject.PrintPreview;
OleContainer1.DoVerb(ovShow);
OleContainer1.Align := OleContainer1.Align;
end;
Excel:
//Excel可以通过把OleContainer1.OleObject.PrintPreview换成OleContainer1.OleObject.ActiveSheet.PrintPreview显示预览窗,但预览窗体严重走位,更严重的是程序没有是响应。
//正确的做法是:
procedure TForm1.MenuPreviewClick(Sender: TObject);
var
ExcelApp: Variant;
begin
ExcelApp := CreateOleObject( ‘Excel.Application‘ );
ExcelApp.WorkBooks.Open( FileName{文件名} );
ExcelApp.Visible:=True;
ExcelApp.ActiveSheet.PrintPreview;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
http://blog.csdn.net/nhconch/article/details/497352