We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

"ImageOrPrintOptions" class doesn't seem to have the definition "ImageFormat"

Hi Aspose,

I am trying to convert each Excel sheet into PNG file.
However I couldn’t build an application with the script below,
because “ImageOrPrintOptions” class doesn’t seem to have the definition “ImageFormat”.
Could you teach me how to get through this problem?

using System;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Rendering;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Aspose.Cells.License License_cells = new Aspose.Cells.License();

            try
            {
                License_cells.SetLicense("Aspose.Total.lic");   
                Console.WriteLine("License set successfully.");
            }
            catch (Exception e)
            {
                Console.WriteLine("/nThere was an error setting the license: " + e.Message);
            }

            Console.WriteLine("Process Starts!");

            String filepath = @"indir\input.xlsx";
            String filename = Path.GetFileName(filepath);
            String Outdir = @"outdir";
                        
            ExcelFunc(filepath, filename, Outdir);

            static void ExcelFunc(String filepath, String filename, String Outdir)
            {      
                // Make directories
                Directory.CreateDirectory(Outdir + "/" + filename);

                Workbook workbook = new Workbook(filepath);

                // Make all sheets invisible except first worksheet
                for (int i = 1; i < workbook.Worksheets.Count; i++)
                {
                    workbook.Worksheets[i].IsVisible = false;
                }


                for (int j = 0; j < workbook.Worksheets.Count; j++)
                {
                    Worksheet ws = workbook.Worksheets[j];

                    String sheet_outpath = Outdir + "/" + filename + "/" + ws.Name;
                    Directory.CreateDirectory(sheet_outpath);                    
                    String png_outpath = Outdir + "/" + filename + "/" + ws.Name + "/" + "png";
                    Directory.CreateDirectory(png_outpath);

                    ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
                    imgOpt.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
                    imgOpt.CheckWorkbookDefaultFont = true;
                    // imgOpt.DefaultFont = "Times New Roman";
                    SheetRender sr = new SheetRender(ws, imgOpt);
                    sr.ToImage(0, png_outpath + "/" + ws.Name + ".png");
                   
                }
            }
        }
    }
}

@shun1985,

ImageOrPrintOptions.ImageFormat is obsolete, please try using ImageOrPrintOptions.ImageType attribute instead. See the updated code segment for your reference:
e.g
Sample code:

.......
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
                    imgOpt.ImageType = Aspose.Cells.Drawing.ImageType.Png;
                    imgOpt.CheckWorkbookDefaultFont = true;
                    // imgOpt.DefaultFont = "Times New Roman";
                    SheetRender sr = new SheetRender(ws, imgOpt);
                    sr.ToImage(0, png_outpath + "/" + ws.Name + ".png");

options.ImageType = ImageType.Png; 

Hope, this helps a bit.

@Amjad_Sahi

Thank you very much !!
Because I will get back to work after about 10 days holiday,
I will try this code then and report it back.

@shun1985,
You are welcome and take your time to test the code.