/// <summary> /// Clones a TImageExportInfo even if it is null. /// </summary> /// <param name="source"></param> /// <returns></returns> public static TOneImgExportInfo Clone(TOneImgExportInfo source) { if (source == null) { return(null); } TOneImgExportInfo Result = new TOneImgExportInfo(); Result.FCurrentPage = source.FCurrentPage; Result.FTotalPages = source.FTotalPages; Result.FCurrentPrintArea = source.FCurrentPrintArea; if (source.FPaintClipRect != null) { Result.FPaintClipRect = new RectangleF[source.FPaintClipRect.Length]; for (int i = 0; i < source.FPaintClipRect.Length; i++) { Result.FPaintClipRect[i] = source.FPaintClipRect[i]; //struct } } Result.FPagePrintRange = (TXlsCellRange)source.FPagePrintRange.Clone(); Result.FPageBounds = source.FPageBounds; //struct if (source.FPrintRanges != null) { Result.FPrintRanges = new TXlsCellRange[source.FPrintRanges.Length]; for (int i = 0; i < source.FPrintRanges.Length; i++) { Result.FPrintRanges[i] = (TXlsCellRange)source.FPrintRanges[i].Clone(); } } return(Result); }
private TImgExportInfo GetExportInfo(IFlxGraphics aCanvas) { TImgExportInfo Result = new TImgExportInfo(); if (AllVisibleSheets) { int FirstVisibleSheet = -1; int SaveActiveSheet = Workbook.ActiveSheet; try { Result.Sheets = new TOneImgExportInfo[Workbook.SheetCount]; for (int sheet = 1; sheet <= Workbook.SheetCount; sheet++) { Workbook.ActiveSheet = sheet; if (Workbook.SheetVisible != TXlsSheetVisible.Visible) { continue; } if (FirstVisibleSheet < 0) { FirstVisibleSheet = sheet; } TOneImgExportInfo OneResult = new TOneImgExportInfo(); OneResult.FPrintRanges = FRenderer.InternalCalcPrintArea(FPrintRange); TPaperDimensions pd = GetRealPageSize(); OneResult.FPageBounds = new RectangleF(0, 0, pd.Width, pd.Height); FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out OneResult.FPaintClipRect, out OneResult.FTotalPages, out OneResult.FPagePrintRange); Result.Sheets[sheet - 1] = OneResult; } } finally { Workbook.ActiveSheet = SaveActiveSheet; } Result.CurrentSheet = FirstVisibleSheet; } else { TOneImgExportInfo OneResult = new TOneImgExportInfo(); OneResult.FPrintRanges = FRenderer.InternalCalcPrintArea(FPrintRange); TPaperDimensions pd = GetRealPageSize(); OneResult.FPageBounds = new RectangleF(0, 0, pd.Width, pd.Height); FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out OneResult.FPaintClipRect, out OneResult.FTotalPages, out OneResult.FPagePrintRange); Result.Sheets = new TOneImgExportInfo[1]; Result.Sheets[0] = OneResult; Result.CurrentSheet = Workbook.ActiveSheet; } Result.ResetCurrentPage(); LastInitSheet = 0; return(Result); }
/// <summary> /// Returns a deep copy of a TImgExportInfo. This method will work even if the source object is null. /// </summary> /// <param name="source"></param> /// <returns></returns> public static TImgExportInfo Clone(TImgExportInfo source) { if (source == null) { return(null); } TImgExportInfo Result = (TImgExportInfo)source.MemberwiseClone(); if (source.FSheets != null) { Result.FSheets = new TOneImgExportInfo[source.FSheets.Length]; for (int i = 0; i < source.FSheets.Length; i++) { Result.FSheets[i] = TOneImgExportInfo.Clone(source.FSheets[i]); } } return(Result); }
/// <summary> /// Exports the associated xls workbook to a graphics stream. You need to provide a /// Graphics object with the correct dimensions. (To get the needed dimensions, use <see cref="GetRealPageSize()"/> /// </summary> /// <param name="imgData">Graphics where the image will be stored. Set it to null to skip the page.</param> /// <param name="exportInfo"> Information needed to export, cached for speed. The first time you call this method (or when you change xls.ActiveSheet), make exportInfo=null</param> public bool ExportNext(Graphics imgData, ref TImgExportInfo exportInfo) { FRenderer.CreateFontCache(); try { Bitmap bmp = null; try { if (imgData == null) { bmp = BitmapConstructor.CreateBitmap(1, 1); imgData = Graphics.FromImage(bmp); imgData.PageUnit = GraphicsUnit.Point; } IFlxGraphics aCanvas = new GdiPlusGraphics(imgData); GraphicsUnit OriginalUnits = imgData.PageUnit; try { imgData.PageUnit = GraphicsUnit.Point; FRenderer.SetCanvas(aCanvas); try { if (exportInfo == null) { exportInfo = GetExportInfo(aCanvas); } exportInfo.IncCurrentPage(); if (exportInfo.CurrentPage > exportInfo.TotalPages) { return(false); } int SaveActiveSheet = Workbook.ActiveSheet; try { Workbook.ActiveSheet = exportInfo.CurrentSheet; int CurrentLogicalPage = -1; if (ResetPageNumberOnEachSheet) { CurrentLogicalPage = exportInfo.ActiveSheet.FCurrentPage; } else { CurrentLogicalPage = exportInfo.CurrentPage; } TOneImgExportInfo OneResult = exportInfo.ActiveSheet; if (LastInitSheet != exportInfo.CurrentSheet) { TXlsCellRange ra; int p; RectangleF[] r; FRenderer.InitializePrint(aCanvas, OneResult.PageBounds, OneResult.PageBounds, OneResult.PrintRanges, out r, out p, out ra); LastInitSheet = exportInfo.CurrentSheet; } if (bmp == null) { OnBeforePaint(new ImgPaintEventArgs(imgData, CalcPageBounds(exportInfo.ActiveSheet.PageBounds), exportInfo.CurrentPage, exportInfo.ActiveSheet.CurrentPage, exportInfo.TotalPages)); } FRenderer.GenericPrint(aCanvas, OneResult.PageBounds, OneResult.PrintRanges, CurrentLogicalPage, OneResult.PaintClipRect, exportInfo.TotalLogicalPages(ResetPageNumberOnEachSheet), bmp == null, OneResult.PagePrintRange, ref OneResult.FCurrentPrintArea); aCanvas.ResetClip(); if (bmp == null) { OnAfterPaint(new ImgPaintEventArgs(imgData, CalcPageBounds(exportInfo.ActiveSheet.PageBounds), exportInfo.CurrentPage, exportInfo.ActiveSheet.CurrentPage, exportInfo.TotalPages)); } } finally { Workbook.ActiveSheet = SaveActiveSheet; } } finally { FRenderer.SetCanvas(null); } } finally { imgData.PageUnit = OriginalUnits; } } finally { if (bmp != null) { bmp.Dispose(); imgData.Dispose(); } } } finally { FRenderer.DisposeFontCache(); } return(true); }