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

Free Support Forum - aspose.com

Sheet to image rendering - Get shifted image if scale and layout is set to 125%

Hi,

it seems that scaling and layout has an impact on rendering the image:

see my code below:
Workbook w2 = new Workbook(“XL_V6.xlsx”);
Worksheet excelWorksheet = w2.Worksheets[“Sheet1”];
Aspose.Cells.Range range = excelWorksheet.Workbook.Worksheets.GetRangeByName(“BIPLI_PARTECIPOGRAMMA”);
string startCell = CellsHelper.CellIndexToName(range.FirstRow, range.FirstColumn);
string endCell = CellsHelper.CellIndexToName(range.FirstRow + range.RowCount - 1, range.FirstColumn + range.ColumnCount - 1);
string rangeAddress = string.Format("{0}:{1}", startCell, endCell);

        ImageOrPrintOptions options = new ImageOrPrintOptions();
        options.AllColumnsInOnePagePerSheet = true;
        options.ImageType = Aspose.Cells.Drawing.ImageType.Emf;
        //options.ImageFormat = ImageFormat.Emf;
        options.OnePagePerSheet = true;
        options.HorizontalResolution = 600;
        options.VerticalResolution = 600;
        options.OnlyArea = true;

        Aspose.Cells.PageSetup pageSetup = excelWorksheet.PageSetup;


        pageSetup.PrintArea = rangeAddress;
        using (MemoryStream imageStream = new MemoryStream())
        {
            SheetRender sr = new SheetRender(excelWorksheet, options);
            sr.ToImage(0, imageStream);
            Image.FromStream(imageStream).Save("pic.png", ImageFormat.Emf);
            //imagePartsList.Add(rangeName, );
        };

have a look at the result here result.zip (147.9 KB). Check the display settings. If I set it 125%, the image get shifted.
If I set it to 100%, it is ok. Can i suppress this setting ?

Kind regards,
Guido

@Nachti,

Please note, for rendering features (e.g. Excel to PDF, Sheet to image, etc.), Aspose.Cells only supports to render in 100% display settings. You may specify the DPI at the start of your program for your requirements:
e.g.
Sample code:

.......
CellsHelper.DPI = 96;//This should be first line and before your actual code and it will be equal to 100% display settings of your os/machine. 
//........
// your code goes here.
//.......

Using the above line will ensure to get the same results (for output PDF/image) as you could generate (Save as PDF) in “100%” display settings.