delphi TMS FlexCel 导出PDF2

TMS FlexCel 导出PDF2

属性和方法

TFlexCelPdfExport.Workbook

property Workbook: TExcelFile

要打印的 Excel 文件。

TFlexCelPdfExport.CurrentPage

property CurrentPage: Integer

返回要打印的下一页。

TFlexCelPdfExport.CurrentPageInSheet

property CurrentPageInSheet: Integer

返回当前工作表上要打印的下一页。当不打印多页时,相当于CurrentPage

TFlexCelPdfExport.GetBookmarkInformation

property GetBookmarkInformation: TGetBookmarkInformationEventHandler

使用此事件可在导出Excel 文件的多个工作表时自定义书签中的内容。

导出多个工作表时触发事件,调用 TFlexCelPdfExport.Export 时不触发。

导出Excel 文件或导出每个工作表时触发一次。

TGetBookmarkInformationArgs

TFlexCelPdfExport.GetBookmarkInformation 上传递的参数

unit

FlexCel.Render

TGetBookmarkInformationArgs.DataFile

property DataFile: TPdfWriter

包含PDF数据的文件。

TGetBookmarkInformationArgs.CurrentPage

property CurrentPage: Integer

当前正在打印的页面。 0 表示所有工作表的全局书签父级。相当于TFlexCelPdfExport.CurrentPage

TGetBookmarkInformationArgs.CurrentPageInSheet

property CurrentPageInSheet: Integer

当前工作表正在打印的页面。相当于TFlexCelPdfExport.CurrentPageInSheet

TGetBookmarkInformationArgs.Bookmark

property Bookmark: TBookmark

要加入的书签。

TBookmark

PDF 文件的书签列表中的条目。

unit

FlexCel.Pdf

TBookmark.Title

property Title: string

书签项的标题。

TBookmark.ChildrenCollapsed

property ChildrenCollapsed: Boolean

如果为 true,则此书签的所有子书签将被折叠。

TBookmark.TextColor

书签项的文本颜色。

property TextColor: TUIColor

TBookmark.TextStyle

property TextStyle: Set of TBookmarkStyle

书签项的文本样式。

例子

合并导出PDF

TForm1private中增加方法PdfGetBookmarkInformation

uses VCL.FlexCel.Core, FlexCel.XlsAdapter, FlexCel.Render, FlexCel.Pdf;

private
  procedure PdfGetBookmarkInformation(const sender: TObject; const e: TGetBookmarkInformationArgs);

procedure TForm1.PdfGetBookmarkInformation(const sender: TObject;
  const e: TGetBookmarkInformationArgs);
begin
  //通过CurrentPage是否为0判断正在导出Excel还是Sheet
  if e.CurrentPage = 0 then
  begin
    Memo1.Lines.Add('--------------------');
    //调用ExportAllVisibleSheets导出全部工作表时,Excel书签名称为参数bookmarkName的名称
    Memo1.Lines.Add('bookmarkName名称 ' + e.Bookmark.Title);
    //设置标签字体颜色为红色
    e.Bookmark.TextColor := TUIColor(TColor(clRed));
  end
  else
  begin
    //导出Sheet时,标签名称默认为Sheet名称
    Memo1.Lines.Add('Sheet名称 ' + e.Bookmark.Title);
    Memo1.Lines.Add('书签指向的页码 ' + e.CurrentPage.ToString);
    Memo1.Lines.Add('当前Sheet中的页码 ' + e.CurrentPageInSheet.ToString);
  end;
end;

procedure TForm1.Button19Click(Sender: TObject);
var
  Xls1, Xls2: TXlsFile;
  Pdf: TFlexCelPdfExport;
  Stream: TMemoryStream;
begin
  //读取Excel文件
  Xls1 := TXlsFile.Create('C:\Users\Administrator\Desktop\ceshi2.xlsx');
  Xls2 := TXlsFile.Create('C:\Users\Administrator\Desktop\ceshi3.xlsx');
  //关联导出的文档
  Pdf := TFlexCelPdfExport.Create(Xls1, True);
  Stream := TMemoryStream.Create;
  try
    //设置导出PDF自定义书签事件
    Pdf.GetBookmarkInformation := PdfGetBookmarkInformation;
    //设置页面布局
    Pdf.PageLayout := TPageLayout.Outlines;
    //准备导出
    Pdf.BeginExport(Stream);
    //导出第1个Excel文件
    Pdf.ExportAllVisibleSheets(False, '第1个Excel文件');
    //导出第2个Excel文件
    Pdf.Workbook := Xls2;
    Pdf.ExportAllVisibleSheets(False, '第2个Excel文件');
    //结束导出
    Pdf.EndExport;
    //将流数据保存到文件
    Stream.SaveToFile('C:\Users\Administrator\Desktop\ceshi.pdf');
  finally
    Pdf.Free;
    Xls1.Free;
    Xls2.Free;
    Stream.Free;
  end;
end;
posted @ 2022-09-02 16:26  txgh  阅读(252)  评论(0编辑  收藏  举报