Cannot get Picture images to print accurately in Aspose.Cells

Hello,We use Aspose.Cells to generate Excel documents containing images. In many cases the images are of maps that must print without any scaling of the original image. In Excel, one can achieve this by putting the current sheet into Page Layout View and then inserting the picture.I am trying to do the same thing programmatically using Aspose.Cells but cannot get the picture image so that it is 100% unscaled in Page Layout view. For example the following code:

      Worksheet sheetLayout = workbook.Worksheets.Add("Map Image Layout View");
sheetLayout.ViewType = ViewType.PageLayoutView;
sheetLayout.Pictures.Add(0, 0, imageStream);

If I then open the workbook and look at the Map Image Layout View sheet, right mouse click on the image and select Size and Properties, the dialog show that the width has been scaled to 105% and it does not print properly. If I keep the ViewType as ViewType.Normal the Size and Propreties dialog shows 100% for the width and height, but now the image prints out flattened.

In the attached Excel file, there are two sheets with images added with the Aspose code from below. There is an additional worksheet that has the same image inserted manually while in Page Layout view. This sheet will print properly. So my question is: How can I add pictures so that the scale properties are 100% when the image is viewed in Page Layout View? I have experimented with the Picture.WidthScale/HeightScale properties to no avail.

Please let me know how I would go about programmatically adding arbitrary images so that they have 100% width and height scaling when in Page Layout View.

    private void buttonCreate_Click(object sender, EventArgs e)
{
// Get Map Bitmap resource...
Bitmap image = Properties.Resources.MapImage;
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Bmp);


Workbook workbook = new Workbook();


// Add map image to sheet with NormalView.
// The image will have 100% width and height scaling, but this
// does not print the image accurately.
Worksheet sheetNormal = workbook.Worksheets.Add("Map Image Normal View");
sheetNormal.ViewType = ViewType.NormalView;
sheetNormal.Pictures.Add(0, 0, imageStream);


// Here I try to insert the image to a worksheet that is in
// PageLayout view. However, the image will have 105% width
// when viewed in Page Layout view. It will not print accurately either.
Worksheet sheetLayout = workbook.Worksheets.Add("Map Image Layout View");
sheetLayout.ViewType = ViewType.PageLayoutView;
int index = sheetLayout.Pictures.Add(0, 0, imageStream);
var mapPicture = sheetLayout.Pictures[index];
// The following lines make no difference. The image properties will show
// the width being 105% in Page Layout view.
mapPicture.HeightScale = 100;
mapPicture.WidthScale = 100;


String outputPath = "MapImageTest.xlsx";
workbook.Save(outputPath, SaveFormat.Xlsx);

System.Diagnostics.Process.Start(outputPath);
}
 
Regards,
Sig Isaac

Hi,

Thanks for your posting and using the Aspose.Cells for .NET

Please download and try the latest version:
Aspose.Cells
for .NET v7.1.1.5



Please try the following properties and see if it resolves your problem.


worksheet.PageSetup.FitToPagesTall = 1;

worksheet.PageSetup.FitToPagesWide = 1;



Thanks for your reply.

I followed your suggestions and downloaded Aspose.Cells for .NET v7.1.1.5 and changed my code:

      Worksheet sheetLayout = workbook.Worksheets.Add("Map Image Layout View");
sheetLayout.ViewType = ViewType.PageLayoutView;
sheetLayout.PageSetup.FitToPagesTall = 1;
sheetLayout.PageSetup.FitToPagesWide = 1;
int index = sheetLayout.Pictures.Add(0, 0, imageStream);
var mapPicture = sheetLayout.Pictures[index];
 
This did not make any difference -- the image width still comes out to 105% in Excel's Page Layout View.
Also, note that the FitToPagesTall and FitToPagesWidth properties already had values of 1.
Please advise of other options.
Regards,
Sig Isaac
 

Hi,

Thanks for your feedback.

We have logged your issue in our database. We will look into it and get back to you asap.

This issue has been logged as CELLSNET-40455.

Hi,

This issue is caused by the following reason:

The column width in PageLayout View (the column width is 67) is different with the width in Normal view(the column width is 64).

We will look into how to fix the issue.

Hi,

We have fixed this issue. Please download and try this fix: Aspose.Cells for .NET v7.1.2.1

The fix looks good. Thank you very much for your quick response.

Hi,

It’s good to know your issue has been resolved. We have closed this ticket.

If you get any other question or face any issue, please feel free to post, we will help you asap.

The issues you have found earlier (filed as CELLSNET-40455) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.