zoukankan      html  css  js  c++  java
  • 通过程序预览Office文档

    我承认,标题是夸大了,就是为了吸引注意力。这里只有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

  • 相关阅读:
    hdu6315 Naive Operations
    noi.ac #525 神树的权值
    JSOI2018 潜入行动
    GXOI/GZOI2019 旅行者
    Educational Codeforces Round #67
    [六省联考2017] 分手是祝愿
    NOI2014 随机数生成器
    NOI2012 随机数生成器
    USACO19JAN Redistricting
    HNOI2015 菜肴制作
  • 原文地址:https://www.cnblogs.com/findumars/p/5393781.html
Copyright © 2011-2022 走看看