Hello There,
When i draw a shape with below then excel is crashed
i assigned width from shapePathBottom.WidthPixel but it is return negative value
below is sample code for draw a line shape
ShapePath shapePathBottom = new ShapePath();
shapePathBottom.MoveTo(0F, 0F);
shapePathBottom.LineTo(0F, float.Parse("15"));
shapePathBottom.LineTo(float.Parse("242730.00000000012"), "15");
shapePathBottom.LineTo(float.Parse("242730.00000000012"), ("1038"));
Shape oShapeBottom = worksheet.Shapes.AddFreeform(0, 0, 0, 0, 0, 0, new ShapePath[] { shapePathBottom });
oShapeBottom.Width = shapePathBottom.WidthPixel; // -225457
oShapeBottom.Height = shapePathBottom.HeightPixel; // 1038
oShapeBottom.X = (int)(919412);
oShapeBottom.Y = (int)(1539);
@tejas.patel
Cause
The crash youāre experiencing when opening Excel is likely due to the negative width value returned by shapePathBottom.WidthPixel
. This can occur if the coordinates used to define the shape are incorrect or if the shape is defined in a way that results in invalid geometry.
Solution
To resolve this issue, ensure that the coordinates used to define the shape are valid and that the shape is constructed correctly. Here are a few steps to help you troubleshoot and fix the problem:
-
Check Coordinates: Verify that the coordinates you are using in the MoveTo
and LineTo
methods are correct and make sense in the context of your worksheet.
-
Validate Width and Height: Before assigning the width and height to the shape, check if they are non-negative. If they are negative, set them to a default value or handle the error accordingly.
-
Adjust Shape Creation: If the shape is not intended to be very large, consider using smaller values for the coordinates to avoid exceeding Excelās limits.
Code
Hereās a modified version of your code that includes checks for negative width and height:
ShapePath shapePathBottom = new ShapePath();
shapePathBottom.MoveTo(0F, 0F);
shapePathBottom.LineTo(0F, float.Parse("15"));
shapePathBottom.LineTo(float.Parse("242730.00000000012"), 15F);
shapePathBottom.LineTo(float.Parse("242730.00000000012"), 1038F);
Shape oShapeBottom = worksheet.Shapes.AddFreeform(0, 0, 0, 0, 0, 0, new ShapePath[] { shapePathBottom });
float width = shapePathBottom.WidthPixel;
float height = shapePathBottom.HeightPixel;
if (width < 0 || height < 0)
{
// Handle negative dimensions
width = 0; // or set to a default value
height = 0; // or set to a default value
}
oShapeBottom.Width = width;
oShapeBottom.Height = height;
oShapeBottom.X = (int)(919412);
oShapeBottom.Y = (int)(1539);
Next Steps
- Test the modified code to see if it resolves the crash.
- If the issue persists, simplify the shape or use smaller coordinate values.
- Review the Aspose.Cells documentation for any limitations regarding shape dimensions and coordinates.
Please implement these changes and let me know if you need further assistance!
@tejas.patel,
After initial testing, I am able to reproduce the issue as you mentioned by using the following sample code. I found MS Excel crashed when opening the output Excel file (generated by Aspose.Cells) into MS Excel that contains free form shape.
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
ShapePath shapePathBottom = new ShapePath();
shapePathBottom.MoveTo(0F, 0F);
shapePathBottom.LineTo(0F, float.Parse("15"));
shapePathBottom.LineTo(float.Parse("242730.00000000012"), float.Parse("15"));
shapePathBottom.LineTo(float.Parse("242730.00000000012"), float.Parse("1038"));
Aspose.Cells.Drawing.Shape oShapeBottom = worksheet.Shapes.AddFreeform(0, 0, 0, 0, 0, 0, new ShapePath[] { shapePathBottom });
oShapeBottom.Width = shapePathBottom.WidthPixel; // -225457
oShapeBottom.Height = shapePathBottom.HeightPixel; // 1038
oShapeBottom.X = (int)(919412);
oShapeBottom.Y = (int)(1539);
// Save the workbook
workbook.Save("e:\\test2\\out1.xlsx");
out1.zip (6.8 KB)
We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSNET-58774
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
1 Like
Thank you @amjad.sahi
i want to generate excel without crash any temporary solution you can suggest me for above code or functionality
@tejas.patel,
Please allow us some time to thoroughly assess/evaluate your issue first so we can either suggest code adjustments or resolve the API-related problemā¦
@amjad.sahi OK
when you get any solution or temporary solution then give me that solution
@tejas.patel,
Sure, we will do this. Once we have an update on the ticket, we will let you know here immediately.
@amjad.sahi
I have checked in detail
Working when i was used
shapePathBottom.LineTo(225457F, 0F); //225457
but not working when i was used
shapePathBottom.LineTo(225458F, 0F); //225458
i think LineTo function parameter allow value up to 225457
@tejas.patel
The width is too largeļ¼225457 pixels, about 2254 columns). Is it your need?
We have found the issue and will fix it soon.
@tejas.patel
Thank you for your feedback. You are welcome. We will notify you promptly once there are any updates.
Your issue(CELLSNET-58774) has been resolved and the fixed functionality will be released with version 25.8.
We have adjusted the valid range of insert values.
Here is the resulting file generated using the latest function:
CELLSNET-58774.zip (6.8 KB)
@duojie.yang
Thank you for informing us
can you give me range or max value now allowed to LineTo function?
and also now i can set below example value in shape? after update aspose to version 25.8
shapePathBottom.LineTo(225458F, 0F); //225458
@tejas.patel,
We will give details on max range value allowed for LineTo function.
Yes, you can set it using the upcoming (new) Aspose.Cells v25.8.
@amjad.sahi
Hello
CELLSNET-58774.zip in this document i canāt find the shape can you give me sample file which has shows the shape?
@tejas.patel,
The shape is there in the worksheet. I opened the file into MS Excel manually and clicked on āSelection Paneā¦ā option under Find & Select. See the screenshot for your reference.
sc_shot1.png (105.9 KB)
Moreover, please open the Excel file into MS Excel and take the print preview of the sheet, you should start finding the shape after page number 5,399 and till the end e.g., 5,415.
@amjad.sahi
Thank you once again for helping us
@tejas.patel,
You are welcome. We are here to assist you.
@tejas.patel
The parameters of LineTo are in unit of Pixels, but the value in xml of the xlsx file are in unit of EMUs(1pt = 12700 emu) , so the value you set should not be too large to avoid exceeding the range required by Excel.
You can set a value not exceeding 225457 in LineTo for the Aspose.Cells v25.7 and earlier versions.
You can set a value not exceeding 2863311488 in LineTo for the upcoming (new) Aspose.Cells v25.8.
The issues you have found earlier (filed as CELLSNET-58774) have been fixed in this update. This message was posted using Bugs notification tool by leoluo