Example #1
0
        /// <summary>
        /// 打印excel文档
        /// </summary>
        /// <param name="worksheet">工作表</param>
        /// <param name="PrinterName">打印机名称,为空默认打印机</param>
        private void PrintExcelBySheet(Worksheet worksheet, string FileName, int PrintCount)
        {
            worksheet.PageSetup.Orientation  = PageOrientationType.Portrait;
            worksheet.PageSetup.Zoom         = 100;//打印时页面设置,缩放比例
            worksheet.PageSetup.LeftMargin   = 0;
            worksheet.PageSetup.RightMargin  = 0;
            worksheet.PageSetup.BottomMargin = 0;
            worksheet.PageSetup.TopMargin    = 0;

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.PrintWithStatusDialog = false;
            options.OnePagePerSheet       = true;
            options.PrintingPage          = PrintingPageType.IgnoreBlank;
            options.ImageFormat           = ImageFormat.Emf;
            SheetRender sr             = new SheetRender(worksheet, options);
            string      strPrinterName = _PrintName;

            if (_PrintName.Length == 0)
            {
                System.Drawing.Printing.PrinterSettings printSettings = new System.Drawing.Printing.PrinterSettings();
                strPrinterName = printSettings.PrinterName;
            }
            if (FileName.Length == 0)
            {
                FileName = "document";
            }
            //sr.ToImage(0, @"d:\" + FileName + ".jpg");
            for (int i = 0; i < PrintCount; i++)
            {
                sr.ToPrinter(strPrinterName, FileName);
            }
        }
Example #2
0
        public void PrintFile(Window owner, string fullFileName)
        {
            Workbook workbook = new Workbook(string.IsNullOrEmpty(fullFileName) ? FileName : fullFileName);

            if (string.IsNullOrEmpty(PrinterName) && string.IsNullOrWhiteSpace(PrinterName))
            {
                MessageBox.Show(owner, "Please select your printer name.", "Atention", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                // Apply different Image/Print options.
                Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
                options.ImageFormat  = System.Drawing.Imaging.ImageFormat.Png;
                options.PrintingPage = PrintingPageType.Default;

                // To print a whole workbook, iterate through the sheets and print them, or use the WorkbookRender class.
                WorkbookRender wr = new WorkbookRender(workbook, options);

                // Print the workbook.
                try
                {
                    // Setting the number of pages to which the width of the worksheet will be spanned
                    wr.ToPrinter(PrinterName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(owner, string.Format("An error has occurred while printing document: {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Example #3
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_Shapes();
            //ExStart:ImageAsEMF
            Workbook  book  = new Workbook(dataDir + "chart.xlsx");
            Worksheet sheet = book.Worksheets[0];

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution   = 200;
            options.ImageFormat          = System.Drawing.Imaging.ImageFormat.Emf;

            //Save the workbook to stream
            SheetRender  sr   = new SheetRender(sheet, options);
            Presentation pres = new Presentation();

            pres.Slides.RemoveAt(0);

            String EmfSheetName = "";

            for (int j = 0; j < sr.PageCount; j++)
            {
                EmfSheetName = dataDir + "test" + sheet.Name + " Page" + (j + 1) + ".out.emf";
                sr.ToImage(j, EmfSheetName);

                var    bytes    = File.ReadAllBytes(EmfSheetName);
                var    emfImage = pres.Images.AddImage(bytes);
                ISlide slide    = pres.Slides.AddEmptySlide(pres.LayoutSlides.GetByType(SlideLayoutType.Blank));
                var    m        = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, pres.SlideSize.Size.Width, pres.SlideSize.Size.Height, emfImage);
            }

            pres.Save(dataDir + "Saved.pptx", Aspose.Slides.Export.SaveFormat.Pptx);

            //ExEnd:ImageAsEMF
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Instantiate a workbook with an Excel file.
            Workbook workbook = new Workbook(sourceDir + "samplePrintingUsingWorkbookRender.xlsx");

            string printerName = "doPDF 8";

            // Apply different Image/Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.ImageFormat  = System.Drawing.Imaging.ImageFormat.Tiff;
            options.PrintingPage = PrintingPageType.Default;

            // To print a whole workbook, iterate through the sheets and print them, or use the WorkbookRender class.
            WorkbookRender wr = new WorkbookRender(workbook, options);

            try
            {
                // Print the workbook.
                wr.ToPrinter(printerName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("PrintingUsingWorkbookRender executed successfully.");
        }
Example #5
0
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            Workbook book = new Workbook(sourceDir + "sampleConvertWorksheetToImageByPage.xlsx");

            Worksheet sheet = book.Worksheets[0];

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution   = 200;
            options.ImageType            = Drawing.ImageType.Tiff;

            // Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);

            for (int j = 0; j < sr.PageCount; j++)
            {
                sr.ToImage(j, outputDir + "outputConvertWorksheetToImageByPage_" + (j + 1) + ".tif");
            }
            // ExEnd:1

            Console.WriteLine("ConvertWorksheetToImageByPage executed successfully.");
        }
Example #6
0
        /// <summary>
        /// 打印
        /// </summary>
        private void printFile()
        {
            PageSetup pageSetup = DetailSheet.PageSetup;

            pageSetup.Orientation  = PageOrientationType.Landscape;
            pageSetup.LeftMargin   = 0.3;
            pageSetup.RightMargin  = 0.5;
            pageSetup.BottomMargin = 0.5;
            pageSetup.PaperSize    = PaperSizeType.Custom;
            pageSetup.PrintArea    = "A1:H26";
            //Apply different Image / Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();

            options.OnlyArea = true;
            // options.ImageFormat = ImageFormat.Jpeg;
            //  options.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Set the Printing page property
            options.PrintingPage          = PrintingPageType.IgnoreStyle;
            options.PrintWithStatusDialog = false;
            // options.Quality = 10;
            //Render the worksheet
            SheetRender sr = new SheetRender(DetailSheet, options);

            //System.Drawing.Printing.PrinterSettings printSettings = new System.Drawing.Printing.PrinterSettings();
            //string strPrinterName = printSettings.PrinterName;

            ////send to printer
            //Image map = sr.ToImage(1);

            //   sr.ToPrinter(strPrinterName);
            sr.ToImage(0, "sstest.Jpeg");
        }
Example #7
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Instantiate a workbook with Excel file.
            Workbook workbook = new Workbook(sourceDir + "samplePrintingUsingSheetRender.xlsx");

            string printerName = "doPDF 8";

            // Access first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            // Apply different Image/Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.PrintingPage = PrintingPageType.Default;
            SheetRender sr = new SheetRender(worksheet, options);

            // Print the sheet.
            try
            {
                sr.ToPrinter(printerName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("PrintingUsingSheetRender executed successfully.");
        }
Example #8
0
        /// <summary>
        /// 把给定的json数据解析到对应的excle中
        /// </summary>
        /// <param name="strContent">数据格式</param>
        /// {"count":12,"done":[{"que_no":"1005","win_no":"1"},{"que_no":"1004","win_no":"1"},{"que_no":"1003","win_no":"1"},{"que_no":"1002","win_no":"1"},{"que_no":"1001","win_no":"1"}],"wait":"1006,1007,1008,1009"}
        public void writeXLS(string strContent)
        {
            try
            {
                //   string Template_File_Path = @".\wj_led.xlsx";
                string Template_File_Path = @".\Template\wj_led.xlsx";

                //  打开 Excel 模板
                Workbook CurrentWorkbook = File.Exists(Template_File_Path) ? new Workbook(Template_File_Path) : new Workbook();

                //  打开第一个sheet
                Worksheet DetailSheet = CurrentWorkbook.Worksheets[0];
                //得到对应的json数据,定义json格式如下
                //{"count":12,"done":[{"que_no":"1005","win_no":"1"},{"que_no":"1004","win_no":"1"},{"que_no":"1003","win_no":"1"},{"que_no":"1002","win_no":"1"},{"que_no":"1001","win_no":"1"}],"wait":"1006,1007,1008,1009"}
                JObject jobj   = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(strContent);
                int     istart = 5;
                foreach (JObject jo in jobj["done"])
                {
                    DetailSheet.Cells[$"B{istart}"].PutValue($"请{jo["que_no"]}号到{jo["win_no"]}号窗口办理业务");
                    istart++;
                }
                string[] arrWait = jobj["wait"].ToString().Split(','); //得到等待队列
                for (int i = 0; i < arrWait.Length; i++)
                {
                    int iIndex = i / 2 + 5;
                    if (i % 2 == 0) //双数  F
                    {
                        DetailSheet.Cells[$"E{iIndex}"].PutValue(arrWait[i]);
                    }
                    else //单数  E
                    {
                        DetailSheet.Cells[$"F{iIndex}"].PutValue(arrWait[i]);
                    }
                }
                DetailSheet.Cells["E4"].PutValue($"({jobj["count"]}位等待)");

                PageSetup pageSetup = DetailSheet.PageSetup;
                pageSetup.Orientation  = PageOrientationType.Portrait;
                pageSetup.LeftMargin   = 0.3;
                pageSetup.RightMargin  = 0.5;
                pageSetup.BottomMargin = 0.5;
                pageSetup.PaperSize    = PaperSizeType.Custom;
                pageSetup.PrintArea    = "A1:H13";
                Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
                options.OnlyArea              = true;
                options.ImageFormat           = System.Drawing.Imaging.ImageFormat.Png;
                options.PrintingPage          = PrintingPageType.IgnoreStyle;
                options.PrintWithStatusDialog = false;
                SheetRender sr = new SheetRender(DetailSheet, options);
                sr.ToImage(0, "sstest.png");
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Example #9
0
        /// <summary>
        /// 生成缩略图,只生成第一张页面的缩略图
        /// </summary>
        /// <param name="fileBuffer">文件的字节数组</param>
        /// <param name="fileType">文件类型,目前支持:Word、Excel、PDF</param>
        public static byte[] ConvertToSnap(byte[] fileBuffer, string fileType)
        {
            var snapStream = new MemoryStream();

            if (fileType == "xls" || fileType == "xlsx")
            {
                var book       = new Aspose.Cells.Workbook(new MemoryStream(fileBuffer));
                var sheet      = book.Worksheets[0];
                var imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions
                {
                    OnePagePerSheet      = true,
                    VerticalResolution   = 400,
                    HorizontalResolution = 300,
                    ImageFormat          = System.Drawing.Imaging.ImageFormat.Jpeg
                };
                var sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);
                sr.ToImage(0, snapStream);
            }
            else if (fileType == "doc" || fileType == "docx")
            {
                var doc        = new Aspose.Words.Document(new MemoryStream(fileBuffer));
                var imgOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Jpeg)
                {
                    Resolution = 400,
                };
                doc.Save(snapStream, imgOptions);
            }
            else if (fileType == "pdf")
            {
                //aspose有性能问题
                //var converter = new Aspose.Pdf.Facades.PdfConverter();
                //converter.BindPdf(new Aspose.Pdf.Document(new MemoryStream(fileBuffer)));
                //converter.DoConvert();
                //converter.GetNextImage(snapStream, new Aspose.Pdf.PageSize(200, 150), System.Drawing.Imaging.ImageFormat.Jpeg,30);

                //换用ghostscript
                //GhostscriptRasterizer rasterizer = new GhostscriptRasterizer();
                //rasterizer.Open(new MemoryStream(fileBuffer));
                //Image page = rasterizer.GetPage(96, 96, 1);
                //page.Save(snapStream, ImageFormat.Jpeg);

                PDFFile pdfFile = PDFFile.Open(new MemoryStream(fileBuffer));
                Bitmap  bitmap  = pdfFile.GetPageImage(0, 56 * (int)Definition.Two);
                bitmap.Save(snapStream, ImageFormat.Jpeg);
            }

            var result = snapStream.ToArray();

            snapStream.Close();
            return(result);
        }
Example #10
0
        private Bitmap ConvertSheetToImage(Worksheet sheet)
        {
            // Apply different Image/Print options.
            ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();

            options.ImageFormat  = System.Drawing.Imaging.ImageFormat.Png;
            options.PrintingPage = PrintingPageType.Default;

            SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);

            Bitmap bitmap = sr.ToImage(0);

            return(bitmap);
        }
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            //Output directory
            string outputDir = RunExamples.Get_OutputDirectory();

            //Open template
            Workbook book = new Workbook(sourceDir + "sampleWorksheetToAnImage.xlsx");

            // Get the first worksheet
            Worksheet sheet = book.Worksheets[0];

            // Apply different Image and Print options
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();

            // Set Horizontal Resolution
            options.HorizontalResolution = 300;

            // Set Vertical Resolution
            options.VerticalResolution = 300;

            // Set TiffCompression
            options.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;

            // Set Autofit options
            options.IsCellAutoFit = false;

            // Set Image Format
            options.ImageType = Drawing.ImageType.Tiff;

            // Set printing page type
            options.PrintingPage = PrintingPageType.Default;

            // Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, options);

            // Render/save the image for the sheet
            int pageIndex = 3;

            sr.ToImage(pageIndex, outputDir + @"outputWorksheetToAnImage_" + (pageIndex + 1) + ".tiff");
            // ExEnd:1

            Console.WriteLine("WorksheetToAnImage executed successfully.");
        }
Example #12
0
        public static int LeafletExcel2JPG(string excelPath, string fileID, string taskID)
        {
            curIndex = 1;
            int highHeightUnit = 0;
            var wb             = new Aspose.Cells.Workbook(new MemoryStream(GetFileBuffer(excelPath)));

            imgHeight = 0; listBitmaps = new Dictionary <string, Bitmap>();
            string root = Path.Combine(OfficeHelper.GetFolderPath(taskID, "Office"), fileID);

            if (!Directory.Exists(@root))
            {
                Directory.CreateDirectory(@root);
            }
            List <Bitmap> listImage = new List <Bitmap>();

            foreach (Aspose.Cells.Worksheet sheet in wb.Worksheets)
            {
                Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();

                ImageFormat imageFormat = ImageFormat.Jpeg;
                imgOptions.ImageFormat     = imageFormat;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage    = Aspose.Cells.PrintingPageType.IgnoreBlank;

                int         index = sheet.Index + 1;
                SheetRender sr    = new SheetRender(sheet, imgOptions);

                Bitmap bitmap = sr.ToImage(0);
                if (bitmap != null)
                {
                    listImage.Add(bitmap);
                }
            }
            highHeightUnit = MergerImageAndCut(listImage, root, true);

            foreach (KeyValuePair <string, Bitmap> bitmaps in listBitmaps)
            {
                Bitmap bitmap = bitmaps.Value;
                if (bitmap != null)
                {
                    ImageFormat imageFormat = ImageFormat.Jpeg;
                    bitmap.Save(bitmaps.Key, imageFormat);
                }
            }
            return(highHeightUnit);
        }
Example #13
0
        /// <summary>
        /// 打印excel文档
        /// </summary>
        /// <param name="worksheet">工作表</param>
        /// <param name="PrinterName">打印机名称,为空默认打印机</param>
        private void PrintExcelInternetBySheet(Worksheet worksheet, string FileName, int PrintCount)
        {
            if (IP.Length == 0 || Port <= 0)
            {
                return;
            }
            worksheet.PageSetup.Orientation = PageOrientationType.Portrait;
            worksheet.PageSetup.Zoom        = (int)(((decimal)200 / 85) * 100);//打印时页面设置,缩放比例,佳博打印机
            //worksheet.PageSetup.Zoom = 200;
            worksheet.PageSetup.LeftMargin   = 0;
            worksheet.PageSetup.RightMargin  = 0;
            worksheet.PageSetup.BottomMargin = 0;
            worksheet.PageSetup.TopMargin    = 0;

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.PrintWithStatusDialog = false;
            options.OnePagePerSheet       = true;
            options.PrintingPage          = PrintingPageType.IgnoreBlank;
            options.ImageFormat           = ImageFormat.MemoryBmp;
            options.ChartImageType        = ImageFormat.MemoryBmp;
            options.Quality = 100;
            SheetRender sr             = new SheetRender(worksheet, options);
            string      strPrinterName = _PrintName;

            if (_PrintName.Length == 0)
            {
                System.Drawing.Printing.PrinterSettings printSettings = new System.Drawing.Printing.PrinterSettings();
                strPrinterName = printSettings.PrinterName;
            }
            if (FileName.Length == 0)
            {
                FileName = "document";
            }
            Bitmap bmp = sr.ToImage(0);

            for (int i = 0; i < PrintCount; i++)
            {
                string    printMessage = "";
                IpPrinter ipp          = new IpPrinter(IP, Port);
                ipp.PrintBitmap(bmp, out printMessage);
            }
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            Workbook book = new Workbook(dataDir+ "TestData.xlsx");
            Worksheet sheet = book.Worksheets[0];
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution = 200;
            options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);
            for (int j = 0; j < sr.PageCount; j++)
            {

                sr.ToImage(j, dataDir+ "test" + sheet.Name + " Page" + (j + 1) + ".out.tif");
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            string    MyDir = @"Files\";
            Workbook  book  = new Workbook(MyDir + "Sheet to Image by Page.xls");
            Worksheet sheet = book.Worksheets[0];

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution   = 200;
            options.ImageFormat          = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);

            for (int j = 0; j < sr.PageCount; j++)
            {
                Bitmap pic = sr.ToImage(j);
                pic.Save(MyDir + sheet.Name + " Page" + (j + 1) + ".tiff");
            }
        }
Example #16
0
        static void Main(string[] args)
        {
            string MyDir = @"Files\";
            Workbook book = new Workbook(MyDir + "Sheet to Image by Page.xls");
            Worksheet sheet = book.Worksheets[0];
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution = 200;
            options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);
            for (int j = 0; j < sr.PageCount; j++)
            {

                Bitmap pic = sr.ToImage(j);
                pic.Save(MyDir + sheet.Name + " Page" + (j + 1) + ".tiff");
            }

        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            Workbook book = new Workbook(dataDir+ "TestData.xlsx");
            Worksheet sheet = book.Worksheets[0];
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution = 200;
            options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);
            for (int j = 0; j < sr.PageCount; j++)
            {

                sr.ToImage(j, dataDir+ "test" + sheet.Name + " Page" + (j + 1) + ".tif");
            }
        }
        public static void Run()
        {
            // ExStart:PrintingExcelWorkbookUsingSheetRender
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Instantiate a workbook with Excel file.
            Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx");

            string printerName = "";

            while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName))
            {
                Console.WriteLine("Please Enter Your Printer Name:");
                printerName = Console.ReadLine();
            }

            // Define a worksheet.
            Worksheet worksheet;

            // Get the second sheet.
            worksheet = workbook.Worksheets[1];

            // Apply different Image/Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.PrintingPage = PrintingPageType.Default;
            SheetRender sr = new SheetRender(worksheet, options);

            Console.WriteLine("Printing SampleBook.xlsx");
            // Print the sheet.
            try
            {
                sr.ToPrinter(printerName);
                Console.WriteLine("Pinting finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:PrintingExcelWorkbookUsingSheetRender
        }
Example #19
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            Workbook  book  = new Workbook(dataDir + "TestData.xlsx");
            Worksheet sheet = book.Worksheets[0];

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution   = 200;
            options.ImageFormat          = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);

            for (int j = 0; j < sr.PageCount; j++)
            {
                sr.ToImage(j, dataDir + "test" + sheet.Name + " Page" + (j + 1) + ".tif");
            }
        }
Example #20
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Open template
            Workbook book = new Workbook(dataDir + "Testbook1.xlsx");

            // Get the first worksheet
            Worksheet sheet = book.Worksheets[0];

            // Apply different Image and Print options
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();

            // Set Horizontal Resolution
            options.HorizontalResolution = 300;

            // Set Vertical Resolution
            options.VerticalResolution = 300;

            // Set TiffCompression
            options.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionLZW;

            // Set Autofit options
            options.IsCellAutoFit = false;

            // Set Image Format
            options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

            // Set printing page type
            options.PrintingPage = PrintingPageType.Default;

            // Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, options);

            // Render/save the image for the sheet
            sr.ToImage(0, dataDir + @"SheetImage_out.tiff");
            // ExEnd:1
        }
Example #21
0
        /// <summary>
        /// 将excel文件导出为图片
        /// </summary>
        /// <param name="worksheet">工作表</param>
        /// <param name="PrinterName">打印机名称,为空默认打印机</param>
        public Bitmap BitmapExcelBySheet(string TemplateFilePath, DataSet ds, DataTable dt)
        {
            Bitmap bmp = null;

            CreateExcelByData(TemplateFilePath, ds, dt, string.Empty);
            designer.Workbook.Worksheets[0].PageSetup.Orientation  = PageOrientationType.Portrait;
            designer.Workbook.Worksheets[0].PageSetup.Zoom         = 100;//打印时页面设置,缩放比例
            designer.Workbook.Worksheets[0].PageSetup.LeftMargin   = 0;
            designer.Workbook.Worksheets[0].PageSetup.RightMargin  = 0;
            designer.Workbook.Worksheets[0].PageSetup.BottomMargin = 0;
            designer.Workbook.Worksheets[0].PageSetup.TopMargin    = 0;

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.PrintWithStatusDialog = false;
            options.OnePagePerSheet       = true;
            options.PrintingPage          = PrintingPageType.IgnoreBlank;
            options.ImageFormat           = ImageFormat.Emf;
            SheetRender sr = new SheetRender(designer.Workbook.Worksheets[0], options);

            bmp = sr.ToImage(0);
            return(bmp);
        }
Example #22
0
        public static void Run()
        {
            // ExStart:PrintingExcelWorkbookUsingWorkbookRender
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Instantiate a workbook with an Excel file.
            Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx");

            string printerName = "";

            while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName))
            {
                Console.WriteLine("Please Enter Your Printer Name:");
                printerName = Console.ReadLine();
            }

            // Apply different Image/Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.ImageFormat  = System.Drawing.Imaging.ImageFormat.Tiff;
            options.PrintingPage = PrintingPageType.Default;

            // To print a whole workbook, iterate through the sheets and print them, or use the WorkbookRender class.
            WorkbookRender wr = new WorkbookRender(workbook, options);

            Console.WriteLine("Printing SampleBook.xlsx");
            // Print the workbook.
            try
            {
                wr.ToPrinter(printerName);
                Console.WriteLine("Pinting finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:PrintingExcelWorkbookUsingWorkbookRender
        }
        public static void Run()
        {
            // ExStart:PrintingExcelWorkbookUsingWorkbookRender
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Instantiate a workbook with an Excel file.
            Workbook workbook = new Workbook(dataDir + "SampleBook.xlsx");

            string printerName = "";

            while (string.IsNullOrEmpty(printerName) && string.IsNullOrWhiteSpace(printerName))
            {
                Console.WriteLine("Please Enter Your Printer Name:");
                printerName = Console.ReadLine();
            }

            // Apply different Image/Print options.
            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
            options.PrintingPage = PrintingPageType.Default;

            // To print a whole workbook, iterate through the sheets and print them, or use the WorkbookRender class.
            WorkbookRender wr = new WorkbookRender(workbook, options);

            Console.WriteLine("Printing SampleBook.xlsx");
            // Print the workbook.
            try
            {
                wr.ToPrinter(printerName);
                Console.WriteLine("Pinting finished.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:PrintingExcelWorkbookUsingWorkbookRender
        }
Example #24
0
        public static void Main(string[] args)
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            Workbook  book  = new Workbook(dataDir + "TestData.xlsx");
            Worksheet sheet = book.Worksheets[0];

            Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            options.HorizontalResolution = 200;
            options.VerticalResolution   = 200;
            options.ImageFormat          = System.Drawing.Imaging.ImageFormat.Tiff;

            //Sheet2Image By Page conversion
            SheetRender sr = new SheetRender(sheet, options);

            for (int j = 0; j < sr.PageCount; j++)
            {
                sr.ToImage(j, dataDir + "test" + sheet.Name + " Page" + (j + 1) + ".out.tif");
            }

            //ExEnd:1
        }
        ///<Summary>
        /// ConvertXlsToJpg method to convert XLS file to Jpg
        ///</Summary>

        public Response ConvertXlsToJpg(string fileName, string folderName, string userEmail)
        {
            return(ProcessTask(fileName, folderName, ".jpg", true, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(inFilePath);

                Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();
                imgOptions.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
                imgOptions.OnePagePerSheet = true;

                foreach (var sheet in workbook.Worksheets)
                {
                    string outfileName = sheet.Name + ".jpg";
                    outPath = zipOutFolder + "/" + outfileName;

                    Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, imgOptions);
                    System.Drawing.Bitmap bitmap = sr.ToImage(0);
                    if (bitmap != null)
                    {
                        bitmap.Save(outPath);
                    }
                }
            }));
        }