I want to insert and scale a picture but leave it on the first row. I tried the following:
int temp = ws.Pictures.Add(0, 4, "zp_logo.jpg");
ws.Pictures[temp].HeightScale = 50;
ws.Pictures[temp].WidthScale = 50;
ws.Pictures[temp].Move(0, 4);
The first 3 lines work as expected and scale the picture. But then I want to move it back up again as the scaling apparently takes the lower left corner as reference (while the add method takes top left as reference btw), but the 4th line doesn't move the picture but scales it back to 100% height. How to move the picture?
In an attempt to work around this problem, I scaled the picture myself first and try to insert that. But when inserted, it scales the width to 178% and I cannot change that from aspose, in other words:
int picIndex = ws.Pictures.Add(0, 1, exeDir + "\\zp_logo_small.jpg");
ws.Pictures[picIndex].WidthScale = 100;
does not work.
Any ideas?
And when inserting works properly, I would actually like to position it with the top right corner instead of the top left corner. The picture is on top of cells B1 and C1 and I would like to align the right side to the right border of C1. Is that possible?
the jpg's are attached, 72 dpi both. First I tried zp_logo and scale that with aspose. It was included properly, but I can't scale and move it. Then I tried zp_logo_small, but I can't even add that properly, when added, width =178%, no way to chagne that. Setting height to 100, makes it 0%.
Further, as a workaround for using top right as reference, can aspose do the following (when knowing in advance that the pic (when properly scaled) is on top of B1 and C1, which I do know)?
> For aligning the picture, May the following code give you some insight, I tried it and it works fine:
It doesn't, sorry. It squeezes the pic and doesn't move it. So the left edge of the pic is moved to the right, but the right edge doesn't move so the pic gets squeezed. I'm using 4.3.0.4 .net1 that I got from Laurence in this thread.
BTW, the following is the test code. Maybe it seemed to work for you as you didn't change column widths as I did in the example that I try to get working.
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Sheet1"];
Cells cell = ws.Cells;
cell.SetColumnWidth(0, 45);
cell.SetColumnWidth(1, 28);
int temp = ws.Pictures.Add(0, 1, "zp_logo.jpg", 50, 50);
Could you create a sample spreadsheet using MS Excel and place your pic with your desired alignment and scaling factor and post us here, so that we may be able to figure our your issue according to your requirement.
it's attached. There is something funny still going on with scaling. I imported the full logo, but scaled it. The height is 78 originally, 39 pixels when imported. That's fine (test1.xls). But I'd prefer to scale the picture beforehand to avoid including redundant things and didn't scale it, but now the picture is imported much smaller (test2.xls). I can live with test1.xls for now. (Logo's also attached)
Import done with
int temp = ws.Pictures.Add(0, 1, "zp_logo.jpg",50,50);
(test1) and
int temp = ws.Pictures.Add(0, 1, "zp_logo_small.jpg");
(test2) respectively.
Notice that I adjusted the alignment manually to align right to column C. I hope this can be automated, depending on column B and C width (which might change in the future).
I see where the problem is with respect to the scaling: when inserting the zp_logo in excel (2003), it comes out 59 pixels high but it was 78. Does Excel use 95 dpi or so?
When scaling it to 50%, it does come out as 30 pixels high, just as when inserting the prescaled zp_logo_small with aspose.
So the strange thing comes in with the Add method of aspose. It doesn't scale as Excel does. Somehow, excel applies a scaling to every pic included, maybe due to dpi differences. Aspose does so too, but only when not specifying a scaling in the Add method.
But anyway, knowing this, we can find a workaround such that the pic comes out as we want. I hope you already have any success on right aligning it.
1,DPI , We use 96 DPI as the default DPI as MS Excel. I have checked your image and found the image had not Real DPI.Maybe you have to set HorizontalResolution and VerticalResolution in the image file.
2,Left,Height, We have fixed the problem.
3,Align to top-right corner, example: if the top-right corner is cell "G1",Please use method Picture. AlignTopRightCorner(0,6);
4,Please ignore Amjad's post about UpperDeltaX. DeltaX is in unit of 1/1024 of the width of the column. DeltaY is in unit of 1/256 of the height of the row.
5.Property LowerRightRow is used to set the lower row index; Property LowerDeltaY is used to set vertical offset from its lower row;
Property LowerRightColumn is used to set the right column index; Property LowerDeltaX is used to set horizonal offset from its right column;
You will see the difference in size while the small version is 50% of the normal version in windows and photoshop, it isn't in excel, but it might be a problem with the pics, but excel does treat them differently than aspose, see my post before in this thread.