Exemplo n.º 1
0
        public static Bitmap GetImageSheet(byte[] filedata)
        {
            Bitmap bitmap = null;

            try
            {
                if (filedata == null)
                {
                    return(null);
                }
                using (MemoryStream ms = new MemoryStream(filedata))
                {
                    Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(ms);
                    if (book.Worksheets.Count > 0)
                    {
                        Aspose.Cells.Worksheet sheet      = book.Worksheets[0];
                        ImageOrPrintOptions    imgOptions = new ImageOrPrintOptions();
                        imgOptions.ImageFormat     = System.Drawing.Imaging.ImageFormat.Jpeg;
                        imgOptions.OnePagePerSheet = true;
                        imgOptions.IsCellAutoFit   = false;

                        SheetRender sr = new SheetRender(sheet, imgOptions);
                        bitmap = sr.ToImage(0);
                    }
                    ms.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return(bitmap);
        }
        public static void Run()
        {
            //Load sample Excel file containing the external resource e.g. linked image etc.
            Workbook wb = new Workbook(sourceDir + "sampleControlExternalResourcesUsingWorkbookSetting_StreamProvider.xlsx");

            //Provide your implementation of IStreamProvider
            wb.Settings.StreamProvider = new SP();

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

            //Specify image or print options, we need one page per sheet and png output
            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.OnePagePerSheet = true;
            opts.ImageType       = Drawing.ImageType.Png;

            //Create sheet render by passing required parameters
            SheetRender sr = new SheetRender(ws, opts);

            //Convert your entire worksheet into png image
            sr.ToImage(0, outputDir + "outputControlExternalResourcesUsingWorkbookSetting_StreamProvider.png");

            Console.WriteLine("ControlExternalResourcesUsingWorkbookSetting_StreamProvider executed successfully.");
        }
Exemplo n.º 3
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            //Create workbook
            Workbook wb = new Workbook();

            //Access first worksheet - it is empty sheet
            Worksheet ws = wb.Worksheets[0];

            //Specify image or print options
            //Since the sheet is blank, we will set OutputBlankPageWhenNothingToPrint to true
            //So that empty page gets printed
            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.ImageFormat = ImageFormat.Png;
            opts.OutputBlankPageWhenNothingToPrint = true;

            //Render empty sheet to png image
            SheetRender sr = new SheetRender(ws, opts);

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

            Console.WriteLine("OutputBlankPageWhenThereIsNothingToPrint executed successfully.\r\n");
        }
Exemplo n.º 4
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            // Load an Excel file
            Workbook wb = new Workbook(sourceDir + "sampleSetPixelFormatRenderedImage.xlsx");

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

            // Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type
            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.PixelFormat = PixelFormat.Format24bppRgb;
            opts.ImageType   = Drawing.ImageType.Tiff;

            // Instantiate SheetRender object based on the first worksheet
            SheetRender sr = new SheetRender(ws, opts);

            // Save the image (first page of the sheet) with the specified options
            sr.ToImage(0, outputDir + "outputSetPixelFormatRenderedImage.tiff");

            Console.WriteLine("SetPixelFormatRenderedImage executed successfully.");
        }
Exemplo n.º 5
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Open a template excel file
            Workbook book = new Workbook(dataDir + "Testbook.xlsx");
            // Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            // Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            // Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            // Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            // Save the image file
            bitmap.Save(dataDir + "SheetImage.out.jpg");
            // ExEnd:1
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            // Open a template excel file
            Workbook book = new Workbook(sourceDir + "sampleSpecificPagesToImages.xlsx");

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

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            // Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

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

            //Specify page index to be rendered
            int idxPage = 3;

            // Render the third image for the sheet
            Bitmap bitmap = sr.ToImage(idxPage);

            // Save the image file
            bitmap.Save(outputDir + "outputSpecificPagesToImage_" + (idxPage + 1) + ".jpg");

            Console.WriteLine("SpecificPagesToImage executed successfully.");
        }
Exemplo n.º 7
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);

            string filePath = dataDir + "Template.xlsx";

            //Create a workbook object from the template file
            Workbook book = new Workbook(filePath);

            //Convert each worksheet into svg format in a single page.
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            imgOptions.SaveFormat      = SaveFormat.SVG;
            imgOptions.OnePagePerSheet = true;

            //Convert each worksheet into svg format
            foreach (Worksheet sheet in book.Worksheets)
            {
                SheetRender sr = new SheetRender(sheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {
                    //Output the worksheet into Svg image format
                    sr.ToImage(i, filePath + sheet.Name + i + ".out.svg");
                    //ExEnd:1
                }
            }
        }
Exemplo n.º 8
0
        public static Bitmap GetImageSheet(string filename)
        {
            Bitmap bitmap = null;

            try
            {
                if (string.IsNullOrEmpty(filename))
                {
                    return(null);
                }
                Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(filename);
                if (book.Worksheets.Count > 0)
                {
                    Aspose.Cells.Worksheet sheet      = book.Worksheets[0];
                    ImageOrPrintOptions    imgOptions = new ImageOrPrintOptions();
                    imgOptions.ImageFormat     = System.Drawing.Imaging.ImageFormat.Jpeg;
                    imgOptions.OnePagePerSheet = true;
                    imgOptions.IsCellAutoFit   = false;

                    SheetRender sr = new SheetRender(sheet, imgOptions);
                    bitmap = sr.ToImage(0);
                }
            }
            catch (Exception ex)
            {
            }
            return(bitmap);
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

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

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

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

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            // Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

            // If you want entire sheet as a singe image
            imgOptions.OnePagePerSheet = true;

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

            // Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            // Save the image file
            bitmap.Save(dataDir + "SheetImage_out.jpg");
            // ExEnd:1
        }
Exemplo n.º 10
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //Instantiate a workbook
            //Open the template file
            Workbook book = new Workbook(dataDir + "MyTestBook1.xlsx");

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

            //Specify your print area if you want
            //sheet.PageSetup.PrintArea = "A1:H8";

            //To remove the white border around the image.
            sheet.PageSetup.LeftMargin   = 0;
            sheet.PageSetup.RightMargin  = 0;
            sheet.PageSetup.BottomMargin = 0;
            sheet.PageSetup.TopMargin    = 0;

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
            //Set only one page would be rendered for the image
            imgOptions.OnePagePerSheet = true;
            imgOptions.PrintingPage    = PrintingPageType.IgnoreBlank;

            //Create the SheetRender object based on the sheet with its
            //ImageOrPrintOptions attributes
            SheetRender sr = new SheetRender(sheet, imgOptions);

            //Convert the image
            sr.ToImage(0, dataDir + "img_MyTestBook1.emf");
        }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Create a new Workbook object and
            //open a template Excel file.
            Workbook book = new Workbook(dataDir + "MyTestBook1.xls");
            //Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Only one page for the whole sheet would be rendered
            imgOptions.OnePagePerSheet = true;

            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file specifying its image format.
            bitmap.Save(dataDir + "SheetImage.jpg");

            // Display result, so that user knows the processing has finished.
            System.Console.WriteLine("Conversion to Image(s) completed.");
        }
Exemplo n.º 12
0
        public static void Main()
        {
            //ExStart:1
            // The path to the documents directory.
            string dataDir  = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string filePath = dataDir + "aspose-sample.xlsx";

            //Create workbook from source file.
            Workbook workbook = new Workbook(filePath);

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

            //Set the print area with your desired range
            worksheet.PageSetup.PrintArea = "E12:H16";

            //Set all margins as 0
            worksheet.PageSetup.LeftMargin   = 0;
            worksheet.PageSetup.RightMargin  = 0;
            worksheet.PageSetup.TopMargin    = 0;
            worksheet.PageSetup.BottomMargin = 0;

            //Set OnePagePerSheet option as true
            ImageOrPrintOptions options = new ImageOrPrintOptions();

            options.OnePagePerSheet = true;
            options.ImageFormat     = ImageFormat.Jpeg;

            //Take the image of your worksheet
            SheetRender sr = new SheetRender(worksheet, options);

            sr.ToImage(0, dataDir + "output.out.jpg");
            //ExEnd:1
        }
Exemplo n.º 13
0
        public async void ExcelToImg(string ExcelPath)
        {
            Workbook book  = new Workbook(ExcelPath);
            var      list  = book.Worksheets;
            int      count = 0;

            foreach (var item in list)
            {
                count++;
                item.PageSetup.LeftMargin   = 0;
                item.PageSetup.RightMargin  = 0;
                item.PageSetup.BottomMargin = 0;
                item.PageSetup.TopMargin    = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat     = System.Drawing.Imaging.ImageFormat.Jpeg;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage    = PrintingPageType.IgnoreBlank;
                SheetRender sr       = new SheetRender(item, imgOptions);
                string      filepath = $@"{Path.GetDirectoryName(ExcelPath)}\{item.Name}.jpg";
                await Task.Run(() => sr.ToImage(0, filepath));
            }

            label2.ForeColor = Color.Green;
            label2.Text      = $"转换完成:图片已存放到{Path.GetDirectoryName(ExcelPath)}";
        }
Exemplo n.º 14
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source file
            Workbook wb = new Workbook(dataDir + "aspose-sample.xlsx");

            // Apply different image or print options
            var imgOption = new ImageOrPrintOptions();

            imgOption.ImageFormat          = ImageFormat.Png;
            imgOption.HorizontalResolution = 200;
            imgOption.VerticalResolution   = 200;
            imgOption.OnePagePerSheet      = true;

            // Apply transparency to the output image
            imgOption.Transparent = true;

            // Create image after apply image or print options
            var sr = new SheetRender(wb.Worksheets[0], imgOption);

            dataDir = dataDir + "output.png";
            sr.ToImage(0, dataDir);
            // ExEnd:1
            Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir);
        }
Exemplo n.º 15
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string filePath = dataDir + "Template.xlsx";

            //Create a workbook object from the template file
            Workbook book = new Workbook(filePath);

            //Convert each worksheet into svg format in a single page.
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            imgOptions.SaveFormat      = SaveFormat.SVG;
            imgOptions.OnePagePerSheet = true;

            //Convert each worksheet into svg format
            foreach (Worksheet sheet in book.Worksheets)
            {
                SheetRender sr = new SheetRender(sheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {
                    //Output the worksheet into Svg image format
                    sr.ToImage(i, filePath + sheet.Name + i + ".out.svg");
                }
            }
        }
Exemplo n.º 16
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.");
        }
Exemplo n.º 17
0
        public void ExcelToImg(string ExcelPath, string excelid)
        {
            testEntities db = new testEntities();

            LicenseHelper.ModifyInMemory.ActivateMemoryPatching();
            Workbook book = new Workbook(ExcelPath);
            var      list = book.Worksheets;

            foreach (var item in list)
            {
                item.PageSetup.LeftMargin   = 0;
                item.PageSetup.RightMargin  = 0;
                item.PageSetup.BottomMargin = 0;
                item.PageSetup.TopMargin    = 0;
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.ImageFormat     = System.Drawing.Imaging.ImageFormat.Png;
                imgOptions.OnePagePerSheet = true;
                imgOptions.PrintingPage    = PrintingPageType.IgnoreBlank;
                SheetRender sr           = new SheetRender(item, imgOptions);
                string      guid         = System.Guid.NewGuid().ToString();
                string      RelativePath = $@"/Upload/Sopimg/{guid}.png";//相对路径

                string filepath = Server.MapPath(RelativePath);
                sr.ToImage(0, filepath);
                db.Sop_Img.Add(new Sop_Img()
                {
                    imgid   = excelid,
                    imgpath = RelativePath
                });
                db.SaveChanges();
            }
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            string filePath = dataDir+ "aspose-sample.xlsx";

            // Create workbook from source file.
            Workbook workbook = new Workbook(filePath);

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

            // Set the print area with your desired range
            worksheet.PageSetup.PrintArea = "E12:H16";

            // Set all margins as 0
            worksheet.PageSetup.LeftMargin = 0;
            worksheet.PageSetup.RightMargin = 0;
            worksheet.PageSetup.TopMargin = 0;
            worksheet.PageSetup.BottomMargin = 0;

            // Set OnePagePerSheet option as true
            ImageOrPrintOptions options = new ImageOrPrintOptions();
            options.OnePagePerSheet = true;
            options.ImageFormat = ImageFormat.Jpeg;

            // Take the image of your worksheet
            SheetRender sr = new SheetRender(worksheet, options);
            dataDir = dataDir+ "output.out.jpg";
            sr.ToImage(0, dataDir);
            // ExEnd:1
            Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir);
            
        }
Exemplo n.º 19
0
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

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

            // Apply different image or print options
            var imgOption = new ImageOrPrintOptions();

            imgOption.ImageType            = Drawing.ImageType.Png;
            imgOption.HorizontalResolution = 200;
            imgOption.VerticalResolution   = 200;
            imgOption.OnePagePerSheet      = true;

            // Apply transparency to the output image
            imgOption.Transparent = true;

            // Create image after apply image or print options
            var sr = new SheetRender(wb.Worksheets[0], imgOption);

            sr.ToImage(0, outputDir + "outputCreateTransparentImage.png");
            // ExEnd:1

            Console.WriteLine("CreateTransparentImage executed successfully.");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            string filePath = dataDir + "Template.xlsx";

            //Create a workbook object from the template file
            Workbook book = new Workbook(filePath);

            //Convert each worksheet into svg format in a single page.
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.SaveFormat = SaveFormat.SVG;
            imgOptions.OnePagePerSheet = true;

            //Convert each worksheet into svg format
            foreach (Worksheet sheet in book.Worksheets)
            {
                SheetRender sr = new SheetRender(sheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {
                    //Output the worksheet into Svg image format
                    sr.ToImage(i, filePath + sheet.Name + i + ".out.svg");
                }
            }
        }
Exemplo n.º 21
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            string filePath = dataDir+ "aspose-sample.xlsx";

            //Create workbook from source file.
            Workbook workbook = new Workbook(filePath);

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

            //Set the print area with your desired range
            worksheet.PageSetup.PrintArea = "E12:H16";

            //Set all margins as 0
            worksheet.PageSetup.LeftMargin = 0;
            worksheet.PageSetup.RightMargin = 0;
            worksheet.PageSetup.TopMargin = 0;
            worksheet.PageSetup.BottomMargin = 0;

            //Set OnePagePerSheet option as true
            ImageOrPrintOptions options = new ImageOrPrintOptions();
            options.OnePagePerSheet = true;
            options.ImageFormat = ImageFormat.Jpeg;

            //Take the image of your worksheet
            SheetRender sr = new SheetRender(worksheet, options);
            sr.ToImage(0, dataDir+ "output.jpg");
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object from source file
            Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx");

            // Apply different image or print options
            var imgOption = new ImageOrPrintOptions();
            imgOption.ImageFormat = ImageFormat.Png;
            imgOption.HorizontalResolution = 200;
            imgOption.VerticalResolution = 200;
            imgOption.OnePagePerSheet = true;

            // Apply transparency to the output image
            imgOption.Transparent = true;

            // Create image after apply image or print options
            var sr = new SheetRender(wb.Worksheets[0], imgOption);

            dataDir = dataDir+ "output.png";
            sr.ToImage(0, dataDir);
            // ExEnd:1
            Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir);
        }
    public static void CreateStaticReport()
    {
        //Open template
        string path = System.Web.HttpContext.Current.Server.MapPath("~");
        path = path.Substring(0, path.LastIndexOf("\\"));
        path += @"\designer\MyTestBook1.xls";

        //Instantiate a new Workbook object.
        Workbook book = new Workbook(path);

        ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
        imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

        Worksheet sheet = book.Worksheets[0];
        SheetRender sheetRender = new SheetRender(sheet, imgOptions);

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

        //Convert worksheet to image.
        sheetRender.ToImage(0, 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/jpeg";
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=SheetImage.jpeg");
        HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length);

        //End response to avoid unneeded html after xls
        HttpContext.Current.Response.End();
    }
Exemplo n.º 24
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");
        }
Exemplo n.º 25
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Open a template Excel file.
            Workbook book = new Workbook(dataDir + "MyTestBook1.xls");
            // Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            // Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            // Only one page for the whole sheet would be rendered
            imgOptions.OnePagePerSheet = true;

            // Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            // Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            // Save the image file specifying its image format.
            bitmap.Save(dataDir + "SheetImage.out.jpg");

            // Display result, so that user knows the processing has finished.
            System.Console.WriteLine("Conversion to Image(s) completed.");
            // ExEnd:1
        }
Exemplo n.º 26
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            // Filter worksheets using CustomLoadFilter class
            LoadOptions loadOpts = new LoadOptions();

            loadOpts.LoadFilter = new CustomLoadFilter();

            // Load the workbook with filter defined in CustomLoadFilter class
            Workbook workbook = new Workbook(sourceDir + "sampleCustomFilteringPerWorksheet.xlsx", loadOpts);

            // Take the image of all worksheets one by one
            for (int i = 0; i < workbook.Worksheets.Count; i++)
            {
                // Access worksheet at index i
                Worksheet worksheet = workbook.Worksheets[i];

                // Create an instance of ImageOrPrintOptions
                // Render entire worksheet to image
                ImageOrPrintOptions imageOpts = new ImageOrPrintOptions();
                imageOpts.OnePagePerSheet = true;
                imageOpts.ImageFormat     = ImageFormat.Png;

                // Convert worksheet to image
                SheetRender render = new SheetRender(worksheet, imageOpts);
                render.ToImage(0, outputDir + "outputCustomFilteringPerWorksheet_" + worksheet.Name + ".png");
            }

            Console.WriteLine("CustomFilteringPerWorksheet executed successfully.");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Create a new Workbook object
            //Open a template excel file
            Workbook book = new Workbook(dataDir+ "Testbook.xlsx");
            //Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file
            bitmap.Save(dataDir+ "SheetImage.jpg");
            
            
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Instantiate and open an Excel file
            Workbook book = new Workbook(dataDir+ "book1.xlsx");

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Set the vertical and horizontal resolution
            imgOptions.VerticalResolution = 200;
            imgOptions.HorizontalResolution = 200;
            //One page per sheet is enabled
            imgOptions.OnePagePerSheet = true;

            //Get the first worksheet
            Worksheet sheet = book.Worksheets[0];
            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bmp = sr.ToImage(0);
            //Create a bitmap
            Bitmap thumb = new Bitmap(100, 100);
            //Get the graphics for the bitmap
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(thumb);

            //Draw the image
            gr.DrawImage(bmp, 0, 0, 100, 100);

            //Save the thumbnail
            thumb.Save(dataDir+ "mythumbnail.out.bmp");
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string filePath = dataDir + "Template.xlsx";

            //Create a workbook object from the template file
            Workbook book = new Workbook(filePath);

            //Convert each worksheet into svg format in a single page.
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.SaveFormat = SaveFormat.SVG;
            imgOptions.OnePagePerSheet = true;

            //Convert each worksheet into svg format
            foreach (Worksheet sheet in book.Worksheets)
            {
                SheetRender sr = new SheetRender(sheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {
                    //Output the worksheet into Svg image format
                    sr.ToImage(i, filePath + sheet.Name + i + ".out.svg");
                }
            }
        }
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            //Load the sample Excel file
            Workbook wb = new Workbook(sourceDir + "sampleImageOrPrintOptions_PageIndexPageCount.xlsx");

            //Access the first worksheet
            Worksheet ws = wb.Worksheets[0];

            //Specify image or print options
            //We want to print pages 4, 5, 6, 7
            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.PageIndex   = 3;
            opts.PageCount   = 4;
            opts.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;

            //Create sheet render object
            SheetRender sr = new SheetRender(ws, opts);

            //Print all the pages as images
            for (int i = opts.PageIndex; i < sr.PageCount; i++)
            {
                sr.ToImage(i, outputDir + "outputImage-" + (i + 1) + ".png");
            }

            Console.WriteLine("RenderLimitedNoOfSequentialPages executed successfully.\r\n");
        }
Exemplo n.º 31
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir  = Path.GetFullPath("../../../Data/");
            string filePath = dataDir + "aspose-sample.xlsx";

            //Create workbook from source file.
            Workbook workbook = new Workbook(filePath);

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

            //Set the print area with your desired range
            worksheet.PageSetup.PrintArea = "E12:H16";

            //Set all margins as 0
            worksheet.PageSetup.LeftMargin   = 0;
            worksheet.PageSetup.RightMargin  = 0;
            worksheet.PageSetup.TopMargin    = 0;
            worksheet.PageSetup.BottomMargin = 0;

            //Set OnePagePerSheet option as true
            ImageOrPrintOptions options = new ImageOrPrintOptions();

            options.OnePagePerSheet = true;
            options.ImageFormat     = ImageFormat.Jpeg;

            //Take the image of your worksheet
            SheetRender sr = new SheetRender(worksheet, options);

            sr.ToImage(0, dataDir + "output.jpg");
        }
Exemplo n.º 32
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Create a new Workbook object and
            //open a template Excel file.
            Workbook book = new Workbook(dataDir + "MyTestBook1.xls");
            //Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Only one page for the whole sheet would be rendered
            imgOptions.OnePagePerSheet = true;

            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file specifying its image format.
            bitmap.Save(dataDir + "SheetImage.jpg");

            // Display result, so that user knows the processing has finished.
            System.Console.WriteLine("Conversion to Image(s) completed.");
        }
Exemplo n.º 33
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
        }
Exemplo n.º 34
0
        public static void Run()
        {
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            // Open a template excel file
            Workbook book = new Workbook(sourceDir + "sampleConvertWorksheettoImageFile.xlsx");

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

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            imgOptions.OnePagePerSheet = true;

            // Specify the image format
            imgOptions.ImageType = Drawing.ImageType.Jpeg;

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

            // Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            // Save the image file
            bitmap.Save(outputDir + "outputConvertWorksheettoImageFile.jpg");

            Console.WriteLine("ConvertWorksheettoImageFile executed successfully.");
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Instantiate a workbook
            //Open the template file
            Workbook book = new Workbook(dataDir+ "MyTestBook1.xlsx");

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

            //Specify your print area if you want
            //sheet.PageSetup.PrintArea = "A1:H8";

            //To remove the white border around the image.
            sheet.PageSetup.LeftMargin = 0;
            sheet.PageSetup.RightMargin = 0;
            sheet.PageSetup.BottomMargin = 0;
            sheet.PageSetup.TopMargin = 0;

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
            //Set only one page would be rendered for the image
            imgOptions.OnePagePerSheet = true;
            imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;

            //Create the SheetRender object based on the sheet with its
            //ImageOrPrintOptions attributes
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Convert the image
            sr.ToImage(0, dataDir+ "img_MyTestBook1.emf");
            
        }
Exemplo n.º 36
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);
            }
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object.
            Workbook wb = new Workbook();

            // Set default font of the workbook to none
            Style s = wb.DefaultStyle;

            s.Font.Name     = "";
            wb.DefaultStyle = s;

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

            // Access cell A4 and add some text inside it.
            Cell cell = ws.Cells["A4"];

            cell.PutValue("This text has some unknown or invalid font which does not exist.");

            // Set the font of cell A4 which is unknown.
            Style st = cell.GetStyle();

            st.Font.Name     = "UnknownNotExist";
            st.Font.Size     = 20;
            st.IsTextWrapped = true;
            cell.SetStyle(st);

            // Set first column width and fourth column height
            ws.Cells.SetColumnWidth(0, 80);
            ws.Cells.SetRowHeight(3, 60);

            // Create image or print options.
            ImageOrPrintOptions opts = new ImageOrPrintOptions();

            opts.OnePagePerSheet = true;
            opts.ImageType       = Drawing.ImageType.Png;

            // Render worksheet image with Courier New as default font.
            opts.DefaultFont = "Courier New";
            SheetRender sr = new SheetRender(ws, opts);

            sr.ToImage(0, "out_courier_new_out.png");

            // Render worksheet image again with Times New Roman as default font.
            opts.DefaultFont = "Times New Roman";
            sr = new SheetRender(ws, opts);
            sr.ToImage(0, "times_new_roman_out.png");
            // ExEnd:1
        }
Exemplo n.º 38
0
        public static void Run()
        {
            // ExStart:1
            //Source directory
            string sourceDir = RunExamples.Get_SourceDirectory();

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

            // Instantiate and open an Excel file
            Workbook book = new Workbook(sourceDir + "sampleGenerateThumbnailOfWorksheet.xlsx");

            // Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

            // Specify the image format
            imgOptions.ImageType = Drawing.ImageType.Jpeg;

            // Set the vertical and horizontal resolution
            imgOptions.VerticalResolution   = 200;
            imgOptions.HorizontalResolution = 200;

            // One page per sheet is enabled
            imgOptions.OnePagePerSheet = true;

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

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

            // Render the image for the sheet
            Bitmap bmp = sr.ToImage(0);

            // Create a bitmap
            Bitmap thumb = new Bitmap(600, 600);

            // Get the graphics for the bitmap
            System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(thumb);

            if (bmp != null)
            {
                // Draw the image
                gr.DrawImage(bmp, 0, 0, 600, 600);
            }

            // Save the thumbnail
            thumb.Save(outputDir + "outputGenerateThumbnailOfWorksheet.bmp");
            // ExEnd:1

            Console.WriteLine("GenerateThumbnailOfWorksheet executed successfully.\r\n");
        }
Exemplo n.º 39
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Instantiate a new Workbook
            //Load an Excel file
            Workbook wb = new Workbook(dataDir+ "Book1.xlsx");
            //Instantiate SheetRender object based on the first worksheet
            //Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type
            SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions { PixelFormat = PixelFormat.Format24bppRgb, ImageFormat = ImageFormat.Tiff });
            //Save the image (first page of the sheet) with the specified options
            sr.ToImage(0, dataDir+ "outImage1.tiff");
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Instantiate a new Workbook
            //Load an Excel file
            Workbook wb = new Workbook(dataDir+ "Book1.xlsx");
            //Instantiate SheetRender object based on the first worksheet
            //Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type
            SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions { PixelFormat = PixelFormat.Format24bppRgb, ImageFormat = ImageFormat.Tiff });
            //Save the image (first page of the sheet) with the specified options
            sr.ToImage(0, dataDir+ "outImage1.out.tiff");
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            // Create workbook object.
            Workbook wb = new Workbook();

            // Set default font of the workbook to none
            Style s = wb.DefaultStyle;
            s.Font.Name = "";
            wb.DefaultStyle = s;

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

            // Access cell A4 and add some text inside it.
            Cell cell = ws.Cells["A4"];
            cell.PutValue("This text has some unknown or invalid font which does not exist.");

            // Set the font of cell A4 which is unknown.
            Style st = cell.GetStyle();
            st.Font.Name = "UnknownNotExist";
            st.Font.Size = 20;
            st.IsTextWrapped = true;
            cell.SetStyle(st);

            // Set first column width and fourth column height
            ws.Cells.SetColumnWidth(0, 80);
            ws.Cells.SetRowHeight(3, 60);

            // Create image or print options.
            ImageOrPrintOptions opts = new ImageOrPrintOptions();
            opts.OnePagePerSheet = true;
            opts.ImageFormat = ImageFormat.Png;

            // Render worksheet image with Courier New as default font.
            opts.DefaultFont = "Courier New";
            SheetRender sr = new SheetRender(ws, opts);
            sr.ToImage(0, "out_courier_new_out.png");

            // Render worksheet image again with Times New Roman as default font.
            opts.DefaultFont = "Times New Roman";
            sr = new SheetRender(ws, opts);
            sr.ToImage(0, "times_new_roman_out.png");
            // ExEnd:1           
            
        }
Exemplo n.º 42
0
        protected override Stream ExtractImage(int pageIndex)
        {
            var       stream = new MemoryStream();
            Worksheet sheet  = _book.Worksheets[pageIndex];

            sheet.PageSetup.LeftMargin   = 1;
            sheet.PageSetup.RightMargin  = 1;
            sheet.PageSetup.BottomMargin = 1;
            sheet.PageSetup.TopMargin    = 1;

            SheetRender sr = new SheetRender(sheet, _options);

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

            Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(dataDir + "Testbook1.xlsx", new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx));

            foreach (Worksheet ws in wb.Worksheets)
            {
                SheetRender sr = new SheetRender(ws, new ImageOrPrintOptions() { OnePagePerSheet = true, ImageFormat = ImageFormat.Jpeg });
                sr.ToImage(0, dataDir  + "Img_" + ws.Index + "_out.jpg");
            }
            // ExEnd:1
        }
        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.");
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Instantiate a new Workbook
            //Load an Excel file
            Workbook wb = new Workbook(dataDir + "Book1.xlsx");
            //Instantiate SheetRender object based on the first worksheet
            //Set the ImageOrPrintOptions with desired pixel format (24 bits per pixel) and image format type
            SheetRender sr = new SheetRender(wb.Worksheets[0], new ImageOrPrintOptions {
                PixelFormat = PixelFormat.Format24bppRgb, ImageFormat = ImageFormat.Tiff
            });

            //Save the image (first page of the sheet) with the specified options
            sr.ToImage(0, dataDir + "outImage1.out.tiff");
        }
Exemplo n.º 46
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");
            }
        }
        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");
            }
        }
Exemplo n.º 48
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 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
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Create workbook object from source file
            Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx");

            //Apply different image or print options
            var imgOption = new ImageOrPrintOptions();
            imgOption.ImageFormat = ImageFormat.Png;
            imgOption.HorizontalResolution = 200;
            imgOption.VerticalResolution = 200;
            imgOption.OnePagePerSheet = true;

            //Apply transparency to the output image
            imgOption.Transparent = true;

            //Create image after apply image or print options
            var sr = new SheetRender(wb.Worksheets[0], imgOption);
            sr.ToImage(0, dataDir+ "output.out.png");
        }
Exemplo n.º 51
0
        static void Main(string[] args)
        {
            string MyDir = @"Files\";

            //Create a new Workbook object
            //Open a template excel file
            Workbook book = new Workbook(MyDir+"Sheet to Image.xls");
            //Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file
            bitmap.Save(MyDir+"SheetImage.jpg");
        }
Exemplo n.º 52
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Create workbook object from source file
            Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx");

            //Apply different image or print options
            var imgOption = new ImageOrPrintOptions();
            imgOption.ImageFormat = ImageFormat.Png;
            imgOption.HorizontalResolution = 200;
            imgOption.VerticalResolution = 200;
            imgOption.OnePagePerSheet = true;

            //Apply transparency to the output image
            imgOption.Transparent = true;

            //Create image after apply image or print options
            var sr = new SheetRender(wb.Worksheets[0], imgOption);
            sr.ToImage(0, dataDir+ "output.png");
        }
Exemplo n.º 53
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Create a new Workbook object
            //Open a template excel file
            Workbook book = new Workbook(dataDir+ "Testbook.xlsx");
            //Get the first worksheet.
            Worksheet sheet = book.Worksheets[0];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file
            bitmap.Save(dataDir+ "SheetImage.jpg");
        }
        public void CreateStaticReport()
        {
            //Open template
            string path = System.Web.HttpContext.Current.Server.MapPath("~");
            path = path.Substring(0, path.LastIndexOf("\\"));

            string outpath = path;

            path += @"\designer\ProductList.xls";
            outpath += @"\designer\Output\";

            //Lnks will be used to get the output files for later use
            ArrayList lnks = new ArrayList();

            //Create a workbook object from the template file
            Workbook book = new Workbook(path);

            //Convert each worksheet into svg format in a single page.
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.SaveFormat = SaveFormat.SVG;
            imgOptions.OnePagePerSheet = true;

            //Convert each worksheet into svg format
            foreach (Worksheet worksheet in book.Worksheets)
            {
                SheetRender sr = new SheetRender(worksheet, imgOptions);

                for (int i = 0; i < sr.PageCount; i++)
                {

                    string svgFileName = "ProductList" + worksheet.Index + i + ".svg";
                    lnks.Add(svgFileName);

                    //Output the worksheet into Svg format
                    sr.ToImage(i, outpath + svgFileName);
                }
            }

            //Show links to all output svg files
            Literal ltr=new Literal();
            ltr.Text="<ul>";

            outPanel.Controls.Add(ltr);

            foreach (string lnk in lnks)
            {
                ltr = new Literal();
                ltr.Text = "<li>";
                outPanel.Controls.Add(ltr);

                HyperLink hyp = new HyperLink();
                hyp.ID = lnk;
                hyp.Text = lnk; ;
                hyp.NavigateUrl = "~/designer/Output/" + lnk;
                outPanel.Controls.Add(hyp);

                ltr = new Literal();
                ltr.Text = "</li>";
                outPanel.Controls.Add(ltr);
            }

            ltr = new Literal();
            ltr.Text = "</ul>";
            outPanel.Controls.Add(ltr);
        }
Exemplo n.º 55
0
        /// <summary>
        /// Excel转为图片
        /// </summary>
        /// <param name="source">源文件路径</param>
        /// <param name="target">图片保存的文件夹路径</param>
        /// <param name="dpi">dpi</param>
        /// <param name="format">图片格式</param>
        public static bool ConverToImage(string source, string target, int resolution = 300, AsposeConvertDelegate d = null)
        {
            double percent = 0.0;
            int page = 0;
            int total = 0;
            double second = 0;
            string path = "";
            string message = "";
            DateTime startTime = DateTime.Now;
            if (!FileUtil.CreateDirectory(target))
            {
                throw new DirectoryNotFoundException();
            }
            if (!File.Exists(source))
            {
                throw new FileNotFoundException();
            }
            if (d != null)
            {
                second = (DateTime.Now - startTime).TotalSeconds;
                percent = 0.1;
                message = "正在解析文件!";
                d.Invoke(percent, page, total, second, path, message);
            }

            LoadOptions loadOptions = new LoadOptions(LoadFormat.Auto);
            Workbook workbook = new Workbook(source, loadOptions);
            total = workbook.Worksheets.Count;

            if (d != null)
            {
                second = (DateTime.Now - startTime).TotalSeconds;
                percent = 0.2;
                message = "开始转换文件,共" + total + "页!";
                d.Invoke(percent, page, total, second, path, message);
            }
            logger.Info("ConverToImage - source=" + source + ", target=" + target + ", pageCount=" + total);
            for (page = 0; page < total; page++)
            {
                Worksheet sheet = workbook.Worksheets[page];
                ImageOrPrintOptions op = new ImageOrPrintOptions();
                op.ImageFormat = ImageFormat.Png;
                op.HorizontalResolution = resolution;
                op.VerticalResolution = resolution;
                SheetRender sr = new SheetRender(sheet, op);
                for (int j = 0; j < sr.PageCount; j++ )
                {
                    Bitmap bitmap = sr.ToImage(j);
                    path = target + "\\" + (page + 1) + "_" + (j + 1) + ".png";
                    bitmap.Save(path);
                    if (d != null)
                    {
                        second = (DateTime.Now - startTime).TotalSeconds;
                        percent = 0.2 + (page + 1) * 0.8 / total;
                        message = "正在转换第" + (page + 1) + "/" + total + "页!";
                        d.Invoke(percent, (page + 1), total, second, path, message);
                    }
                }
            }
            return true;
        }