Get white picture from sheet

Hi,

with following code I get an white picture.

xlsLic.SetLicense(“Aspose.Total.lic”);
wordlic.SetLicense(“Aspose.Total.lic”);

        string fileName = @"SOCIETA_DATA.xlsx";
        Workbook workbook = new Workbook(fileName);
        //workbook.Settings.CultureInfo = new CultureInfo("en-US");
        CultureInfo cult = new CultureInfo("en-US");

        //workbook.Settings.NumberGroupSeparator = '.';
        //workbook.Settings.NumberDecimalSeparator = ','; // workbook.Settings.CultureInfo.NumberFormat.NumberDecimalSeparator[0];

        Worksheet worksheet = workbook.Worksheets["CAPITOLO A.1.2"];
        worksheet.DisplayRightToLeft = true;

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.AllColumnsInOnePagePerSheet = true;
        options.ImageFormat = ImageFormat.Emf;
        options.OnePagePerSheet = true;
        options.HorizontalResolution = 600;
        options.VerticalResolution = 600;
        options.OnlyArea = true;

        Aspose.Cells.PageSetup pageSetup = worksheet.PageSetup;
        pageSetup.IsPercentScale = false;
        pageSetup.SetFitToPages(1, 1);
        pageSetup.PrintArea = "F50:N69"; // “A1:H161”;

        SheetRender sr = new SheetRender(worksheet, options);
        sr.ToImage(0, "output graph.emf");

here is the document SOCIETA_DATA.zip (126.4 KB)

It works with the range of BIPLI_1.

Can you check why it does not work ?

Kind regards,

@Nachti,

Thanks for the sample code and template file.

I have evaluated your scenario/ case a bit. I opened your template file into Ms Excel manually. When I take the print preview of the sheet while checking your specified range (for chart) in the third page, it also shows blank/area (white space) instead of the original chart. Please note, as you are printing the underlying chart, so it is better to save the specified chart to image directly instead of rendering range to image, see the updated sample code that works fine:
e.g
Sample code:

......
string fileName = "e:\\test2\\SOCIETA_DATA.xlsx";
        Workbook workbook = new Workbook(fileName);
        //workbook.Settings.CultureInfo = new CultureInfo("en-US");
        CultureInfo cult = new CultureInfo("en-US");

        //workbook.Settings.NumberGroupSeparator = '.';
        //workbook.Settings.NumberDecimalSeparator = ','; // workbook.Settings.CultureInfo.NumberFormat.NumberDecimalSeparator[0];

        Worksheet worksheet = workbook.Worksheets["CAPITOLO A.1.2"];
        worksheet.DisplayRightToLeft = true;

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.AllColumnsInOnePagePerSheet = true;
        options.ImageFormat = ImageFormat.Emf;
        options.OnePagePerSheet = true;
        options.HorizontalResolution = 600;
        options.VerticalResolution = 600;
        options.OnlyArea = true;

        //Get the chart
        Chart chart = worksheet.Charts["Grafico 3"];
        chart.ToImage("e:\\test2\\output graph1.emf", options); 

Hope, this helps a bit.

Hi,

but I need not only the graph but also some text written to some cells.
Any clue why the page is blank ?

Regards,
Guido

@Nachti,

We evaluated your issue in details and found Shape.IsPrintable attribute was false for chart “Grafico 3” and “Grafico 2” chart. If you could check the size & properties for chart (shape) area in Ms Excel manually for these two charts, you will find “Print object” attribute (checkbox) is not checked. You need to set this attribute on before rendering to image files, see the updated code segment that works fine as I tested:
e.g
Sample code:

string fileName = "e:\\test2\\SOCIETA_DATA.xlsx";
        Workbook workbook = new Workbook(fileName);
        //workbook.Settings.CultureInfo = new CultureInfo("en-US");
        CultureInfo cult = new CultureInfo("en-US");

        //workbook.Settings.NumberGroupSeparator = '.';
        //workbook.Settings.NumberDecimalSeparator = ','; // workbook.Settings.CultureInfo.NumberFormat.NumberDecimalSeparator[0];

        Worksheet worksheet = workbook.Worksheets["CAPITOLO A.1.2"];
        worksheet.DisplayRightToLeft = true;

        ShapeCollection shapes = worksheet.Shapes;

        foreach (Shape shape in shapes)
        {
            if (!shape.IsPrintable)
            {
                Console.WriteLine("Chart [{0}] is not printable.", shape.Name);
                shape.IsPrintable = true;
            }
        }   

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.AllColumnsInOnePagePerSheet = true;
        options.ImageFormat = ImageFormat.Emf;
        options.OnePagePerSheet = true;
        options.HorizontalResolution = 600;
        options.VerticalResolution = 600;
        options.OnlyArea = true;

        Aspose.Cells.PageSetup pageSetup = worksheet.PageSetup;
        pageSetup.IsPercentScale = false;
        pageSetup.SetFitToPages(1, 1);
        pageSetup.PrintArea = "F50:N69"; // “A1:H161”;


        SheetRender sr = new SheetRender(worksheet, options);
        sr.ToImage(0, "e:\\test2\\output graph.emf");

Hope, this helps a bit.