Exemple #1
0
        /// <summary>
        /// This method will export all the visible sheets on an xls file to pdf.
        /// Different than calling ExportSheet for each sheet, this method can keep the page number growing on each sheet, without resetting it.
        /// </summary>
        /// <param name="bookmarkName">If not null, each sheet will be added as an entry on the Bookmarks in the pdf file, under the name specified here.
        /// If you want the Bookmark window to be visible when you open the pdf file, set <see cref="PdfWriter.PageLayout"/> = <see cref="TPageLayout"/>
        /// Also, use the <see cref="GetBookmarkInformation"/> event to further customize what goes in each of the entries.
        /// </param>
        /// <param name="resetPageNumberOnEachSheet">If true, each new sheet will reset the page number shown on Excel headers and footers.</param>
        public virtual void ExportAllVisibleSheets(bool resetPageNumberOnEachSheet, string bookmarkName)
        {
            if (PdfCanvas == null)
            {
                FlxMessages.ThrowException(FlxErr.ErrBeginExportNotCalled);
            }
            TBookmark ParentBookmark = new TBookmark(bookmarkName, new TPdfDestination(CurrentPage), false);

            OnGetBookmarkInformation(new GetBookmarkInformationArgs(PdfCanvas, 0, 0, ParentBookmark));

            int SaveActiveSheet = Workbook.ActiveSheet;

            try
            {
                int TotalPages = -1;
                if (!resetPageNumberOnEachSheet)
                {
                    TotalPages = 0;
                    //Calculate total pages on all sheets.
                    for (int sheet = 1; sheet <= Workbook.SheetCount; sheet++)
                    {
                        Workbook.ActiveSheet = sheet;
                        if (Workbook.SheetVisible != TXlsSheetVisible.Visible)
                        {
                            continue;
                        }
                        TotalPages += TotalPagesInSheet();
                    }
                }

                for (int sheet = 1; sheet <= Workbook.SheetCount; sheet++)
                {
                    Workbook.ActiveSheet = sheet;
                    if (Workbook.SheetVisible != TXlsSheetVisible.Visible)
                    {
                        continue;
                    }

                    int StartSheet = 1;
                    if (!resetPageNumberOnEachSheet)
                    {
                        StartSheet = CurrentPage;
                    }


                    if (bookmarkName != null)
                    {
                        TBookmark bmk = new TBookmark(Workbook.SheetName, new TPdfDestination(CurrentPage), false);
                        OnGetBookmarkInformation(new GetBookmarkInformationArgs(PdfCanvas, CurrentPage, CurrentPageInSheet, bmk));
                        ParentBookmark.AddChild(bmk);
                    }
                    ExportSheet(StartSheet, TotalPages);
                }
                if (bookmarkName != null)
                {
                    PdfCanvas.AddBookmark(ParentBookmark);
                }
            }
            finally
            {
                Workbook.ActiveSheet = SaveActiveSheet;
            }
        }