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