I still am losing the image quality


#1


It appears as though I was able to get the image to work using this workbook and this code but I still am losing the image quality. When I import the image manually using Excel, it comes in fine and there is no image quality loss. When I use the method there is tremendous image quality loss. Did you test it with no image size change or quality loss? If so can you forward me the code you used to test it. Here are the images and the files and the code I used to get the image to work. Check for yourself.

On further testing the problem seems to be that you want me to use the Add(upperX, upperY, lowerX, lowerY) method and that’s fine except for I cannot get the columns on the top to be 1.57 in width, it rounds to 2. That is what the problem is. If I can get the file to have the columns 1.57 or be able to set the columns at 1.57 then I think it will work but every time the image is created it is distorted.

Here are the files

SourceExcelFile.xls (has the file with the columns set to 1.57)

Image Inserted into Source Manually.xls (is the desired result [notice the columns align with the red stripes])

ResultFromAspose.xls (is the result from the code supplied, [notice the columns are larger than the red stripes])

Code.txt is the code used to generate the results.

Your help is appreciated. My suspicion is if we can get the column widths to be set to 1.57 the image will be inserted fine, or if the program can set the image width properly it will work, or if we can have the program honor the original sheet in the template supplied without resetting it to 8. Please advise.


1. You need a float column width but currently it’s an integer one so we need fix it.
2. Image quality. Your following code must distort your image as it is simliar to change image size in Microsoft Excel:

sheet.Pictures.Add(0, 0, 100, 99, @“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Chart.png”);

We recommend you to write code like this:

sheet.Pictures.Add(0, 0, @“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Chart.png”);

Soon we will deliver a fix as well as sample code to you. Thanks for your patience.




#2

Ok I changed the code to the suggested code and the result is the image is losing quality. The image is fuzzy. When I use insert picture commands in excel the image is inserted without losing quality whatsoever. When I use ASPOSE components the image does not look as it should. I will send you the files separately.

This is using the patch that you gave me. In the patch you explicitly said to use the

Pictures.Add(upperX, upperY, lowerX, lowerY, fileName) method, not the one you mentioned in the post I am replying to.

So please tell me if your system will be able to import the image without distortion or not. The image must be inserted programmatically into the file EXACTLY the way it appears (just like if the user did it themselves) without losing any quality or looking fuzzy.

See the separate email attachments.


#3

Dear Stevew,

Thanks for your consideration.

Yes. It’s a bug.

When I designed the Aspose Excel, I planned to supply two methods to insert a picture.

// add a picture without distortion
public int Add(int upperLeftRow, int upperLeftColumn, string fileName)

// add a picture in the specified area, the picture may be distorted
public int Add(int upperLeftRow, int upperLeftColumn, int lowerRightRow, int lowerRightColumn, string fileName)

At first I didn’t think about allowing user to set row height or column width in float values. That causes the bug.

I will fix the problem as soon as possible. Ben will send the fixed dll to you.


#4

So basically there are two bugs:


1. The Pictures.Add(UpperX, UpperY, FileName) bug – this needs to be modified so that the image is aligned in the upper left and top of the specified cell coordinates for the method above. This should put the image into the file and not distort the image and the quality should be the same regardless. (this is the bug I reported a few weeks ago).

2. The second bug is that the column width should allow for a float instead of a byte so that the columns can be added as fractions.

When I read the column width information about excel I noticed that the width is in fact calculated based on characters of the default font. So for example a width of 8 (the default) will allow 8 characters [based on 0] in the column. A width of [1] will allow one to be visible. I also noticed that the width is translated into the nearest 8 pixels internally. This makes the program scroll better. What is odd is that the row eight is calculated in pixels, but the width is in characters. Anyway the important thing is that Excel allows for fractional column widths. Your program needs to support that as well.


3. Another suggestion is this: My template I fixed the width to 1.57 and also setup freeze panes etc and printing options. It would be nice if your program initialized all of the values from my original file so that I don’t have to set them programmatically. This is not a requirement only a suggestion. Basically when the file is opened all of the file settings are saved, then whatever changes are made to the file are changed then the file is output normally. That would be the ideal situation.

Can you give me an estimate as to when the bug (1 and/or 2) are fixed. I will give you a 3rd party test. If we can get this to work we’d like to buy the OEM license from you.

Thanks.
Steve


#5

Dear Steve,

Here is the latest hot fix for you.

Please let me know what happens.


#6


Dear Steve,

This is the sample code:

[Visual Basic]

Dim excel As Excel = New Excel()

'open workbook with default columns set to 1.57.
excel.Open(“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Source.xls”)


'get the main sheet
Dim sheet As Worksheet = excel.Worksheets.GetAt(0)

'show the new column width of the first column in the cell as set to 8 by ASPOSE
Response.Write("reset width by ASPOSE: " + sheet.Cells.GetColumnWidth(0).ToString())


'prepare to reset the columns needed to 1.57
Dim dWidthInDecimals As Double = 1.57


Dim i As Integer
For i = 0 To 99- 1 Step i + 1
sheet.Cells.SetColumnWidth(Convert.ToByte(i), dWidthInDecimals)

Next

'show column being rounded to 2 by ASPOSE even though it should be 1.57 as supplied
Response.Write("
width: " + sheet.Cells.GetColumnWidth(0).ToString())


'Cell cell = sheet.Cells.GetAt(0,0);

'insert picture set start at 0,0 and 100
Dim index As Integer = sheet.Pictures.Add(0,0,“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Chart.png”)


'save file out
excel.Save(“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files.xls”, FileFormatType.Default)

[C#]
Excel excel = new Excel();

//open workbook with default columns set to 1.57.
excel.Open(@“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Source.xls”);


//get the main sheet
Worksheet sheet = excel.Worksheets.GetAt(0);

//show the new column width of the first column in the cell as set to 8 by ASPOSE
Response.Write("reset width by ASPOSE: " + sheet.Cells.GetColumnWidth(0).ToString());


//prepare to reset the columns needed to 1.57
double dWidthInDecimals = 1.57;


for(int i = 0; i < 99; i++)
{
sheet.Cells.SetColumnWidth(Convert.ToByte(i), dWidthInDecimals);

}

//show column being rounded to 2 by ASPOSE even though it should be 1.57 as supplied
Response.Write("
width: " + sheet.Cells.GetColumnWidth(0).ToString());


//Cell cell = sheet.Cells.GetAt(0,0);

//insert picture set start at 0,0 and 100
int index = sheet.Pictures.Add(0, 0, @“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files\Chart.png”);


//save file out
excel.Save(@“C:\InetPub\wwwroot\ProjectInsight.WebApp\Sites\Files.xls”, FileFormatType.Default);


#7

Dear Steve,

Bug 1 and 2 are fixed in the latest fix.

I will think about your 3rd suggestion.

Thanks.