Esempio n. 1
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()
        {
            //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 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
        }
Esempio n. 4
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.");
        }
Esempio n. 5
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()
        {
            // 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
        }
Esempio n. 11
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
        }