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.");
        }
        public List <Sheet> RenderExcelWorksheetsAsImage(string FileName)
        {
            // Load the Excel workbook
            Workbook book       = new Workbook(Server.MapPath(Path.Combine("~/Documents", FileName)));
            var      workSheets = new List <Sheet>();
            // Set image rendering options
            ImageOrPrintOptions options = new ImageOrPrintOptions();

            options.HorizontalResolution        = 200;
            options.VerticalResolution          = 200;
            options.AllColumnsInOnePagePerSheet = true;
            options.OnePagePerSheet             = true;
            options.TextCrossType = TextCrossType.Default;
            options.ImageType     = Aspose.Cells.Drawing.ImageType.Png;

            string imagePath = "";
            string basePath  = Server.MapPath("~/");

            // Create Excel workbook renderer
            WorkbookRender wr = new WorkbookRender(book, options);

            // Save and view worksheets
            for (int j = 0; j < book.Worksheets.Count; j++)
            {
                imagePath = Path.Combine("/Documents/Rendered", string.Format("sheet_{0}.png", j));
                wr.ToImage(j, basePath + imagePath);
                workSheets.Add(new Sheet {
                    SheetName = string.Format("{0}", book.Worksheets[j].Name), Path = imagePath
                });
            }

            return(workSheets);
        }
示例#3
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);
                }
            }
        }
        public static void Run()
        {
            // ExStart:SpecifyJobNameWhilePrinting
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source 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();
            }

            string jobName = "Job Name while Printing with Aspose.Cells";

            // Print workbook using WorkbookRender
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());

            try
            {
                wr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

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

            // Print worksheet using SheetRender
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());

            try
            {
                sr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:SpecifyJobNameWhilePrinting
        }
示例#5
0
        public static void Run()
        {
            Console.WriteLine("SpecifyJobWhilePrinting Started Now.");

            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Create workbook object from source Excel file
            Workbook workbook = new Workbook(sourceDir + "sampleSpecifyJobWhilePrinting.xlsx");

            string printerName = "doPDF 8";

            string jobName = "My Job Name";

            // Print workbook using WorkbookRender
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());

            try
            {
                wr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Write("Press Enter to continue...");
            Console.ReadLine();

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

            // Print worksheet using SheetRender
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());

            try
            {
                sr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("SpecifyJobWhilePrinting executed successfully.");
        }
示例#6
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

            // Create workbook from source Excel file
            Workbook workbook = new Workbook(sourceDir + "samplePrintingRangeOfPages.xlsx");

            string printerName = "doPDF 8";

            Console.Write("PrintingRangeOfPages example with WorkbookRender: ");

            // Print the worbook specifying the range of pages. Here we are printing pages 2-3
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());

            try
            {
                wr.ToPrinter(printerName, 3, 4);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine();
            Console.Write("Press Enter to continue - PrintingRangeOfPages example with SheetRender: ");
            Console.ReadLine();

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

            // Print the worksheet specifying the range of pages. Here we are printing pages 2-3
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());

            try
            {
                sr.ToPrinter(printerName, 1, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("PrintingRangeOfPages executed successfully.");
        }
        public static void Run()
        {
            // ExStart:PrintingSpecificRangeOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook from source 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();
            }

            // Print the worbook specifying the range of pages. Here we are printing pages 2-3
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());

            try
            {
                wr.ToPrinter(printerName, 1, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

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

            // Print the worksheet specifying the range of pages. Here we are printing pages 2-3
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());

            try
            {
                sr.ToPrinter(printerName, 1, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:PrintingSpecificRangeOfPages
        }
        public static void Run()
        {
            // ExStart:SpecifyJobNameWhilePrinting
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source 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();
            }

            string jobName = "Job Name while Printing with Aspose.Cells";

            // Print workbook using WorkbookRender
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());
            try
            {
                wr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

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

            // Print worksheet using SheetRender
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());
            try
            {
                sr.ToPrinter(printerName, jobName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:SpecifyJobNameWhilePrinting
        }
        public void Print(string pdfFileName, string printer, bool IsDupex = true)
        {
            if (!File.Exists(pdfFileName))
            {
                return;
            }
            Workbook       workbook  = new Workbook(pdfFileName);
            Worksheet      worksheet = workbook.Worksheets[0];
            WorkbookRender wr        = new WorkbookRender(workbook, new ImageOrPrintOptions());

            PrinterSettings setting = new PrinterSettings();

            //在界面设置里设置不管用 设置双面打印
            setting.Duplex      = IsDupex ? Duplex.Vertical : Duplex.Default;
            setting.PrinterName = printer;
            Helper.SetDefaultPrinter(printer);
            wr.ToPrinter(printer);
        }
        public static void Run()
        {
            // ExStart:PrintingSpecificRangeOfPages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook from source 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();
            }

            // Print the worbook specifying the range of pages. Here we are printing pages 2-3
            WorkbookRender wr = new WorkbookRender(workbook, new ImageOrPrintOptions());
            try
            {
                wr.ToPrinter(printerName, 1, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

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

            // Print the worksheet specifying the range of pages. Here we are printing pages 2-3
            SheetRender sr = new SheetRender(worksheet, new ImageOrPrintOptions());
            try
            {
                sr.ToPrinter(printerName, 1, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:PrintingSpecificRangeOfPages
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx");

            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.ImageType = Drawing.ImageType.Tiff;

            WorkbookRender wr = new WorkbookRender(wb, opts);

            wr.ToImage(outputDir + "outputUseWorkbookRenderForImageConversion.tiff");

            Console.WriteLine("UseWorkbookRenderForImageConversion executed successfully.");
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            //Open an Excel file.
            Workbook workbook = new Workbook(sourceDir + "sampleSetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions.xlsx");

            //Rendering to PNG file format while setting the CheckWorkbookDefaultFont attribue to false.
            //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook.
            ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();

            imgOpt.ImageType = Drawing.ImageType.Png;
            imgOpt.CheckWorkbookDefaultFont = false;
            imgOpt.DefaultFont = "Times New Roman";
            SheetRender sr = new SheetRender(workbook.Worksheets[0], imgOpt);

            sr.ToImage(0, outputDir + "out1_imagePNG.png");

            //Rendering to TIFF file format while setting the CheckWorkbookDefaultFont attribue to false.
            //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook.
            imgOpt.ImageType = Drawing.ImageType.Tiff;
            WorkbookRender wr = new WorkbookRender(workbook, imgOpt);

            wr.ToImage(outputDir + "out1_imageTIFF.tiff");

            //Rendering to PDF file format while setting the CheckWorkbookDefaultFont attribue to false.
            //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook.
            PdfSaveOptions saveOptions = new PdfSaveOptions();

            saveOptions.DefaultFont = "Times New Roman";
            saveOptions.CheckWorkbookDefaultFont = false;
            workbook.Save(outputDir + "out1_pdf.pdf", saveOptions);

            Console.WriteLine("SetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions executed successfully.\r\n");
        }
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            Workbook            workbook = new Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx");
            ImageOrPrintOptions opts     = new ImageOrPrintOptions();

            opts.PageSavingCallback = new TestTiffPageSavingCallback();
            opts.ImageType          = ImageType.Tiff;

            WorkbookRender wr = new WorkbookRender(workbook, opts);

            wr.ToImage(outputDir + "DocumentConversionProgressForTiff_out.tiff");
            // ExEnd:1

            Console.WriteLine("DocumentConversionProgressForTiff executed successfully.");
        }
        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
        }
示例#15
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 CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\FinancialPlan.xls";

        Workbook workbook = new Workbook(path);

        ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

        imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

        imgOptions.HorizontalResolution = 100;

        imgOptions.VerticalResolution = 100;

        imgOptions.OnePagePerSheet = true;

        WorkbookRender bookRender = new WorkbookRender(workbook, imgOptions);

        //Create a memory stream object.
        MemoryStream memorystream = new MemoryStream();

        bookRender.ToImage(memorystream);

        memorystream.Seek(0, SeekOrigin.Begin);

        //Set Response object to stream the image file.
        byte[] data = memorystream.ToArray();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "image/tiff";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=WorkbookImage.tiff");
        HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length);

        //End response to avoid unneeded html after xls
        HttpContext.Current.Response.End();
    }