PDF file cannot be opened after embedding it in Excel file in Azure function

@srinivasaraju.b,

Thanks for your feedback.

We will evaluate and get back to you soon.

@srinivasaraju.b,
1: The only shape is xlsm embedded object in embeddedXlsm.xlsx
2: As we could not include all icons of different file formats, it’s better that you can directly add correct icons for the embedded object with displayAsIcon as false.

Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap); 
g.DrawImage(iconImageg.DrawString(labelobjOle.SetEmbeddedObject(false, binaryXlsx4, "TS_Reports.zip", false, "abcd");"

Hi @ahsaniqbalsidiqui,

It would be great if you could provide the full solution to display the custom icon for embeddedobject.

Thanks,

@srinivasaraju.b,

There are lots of file format types. We are sorry but (as we told you), we cannot support to include all icons of different unknown file formats (jpeg, zip, msg, etc.), so you have to devise to directly add your desired (correct) icons for the embedded objects with displayAsIcon set as false.

Yes @Amjad_Sahi, I could able to display my own icons for unknow file formats (jpeg, zip, msg, etc…) by setting displayAsIcon to false.

But the problem is → attachments are not opening proper. It is opening with in the excel itself for that I have already posted the issue earlier and you gave me solution to set displayAsIcon to True. Please refer below link.

Thanks,

@srinivasaraju.b,

We will evaluate it and get back to you soon.

@srinivasaraju.b,

Please try the following sample codes to add display icon(s):
e.g
Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
//converting display image into bytes
byte[] binaryImg4 = ToDisplayIcon(dir + "zip.png", "TS_Reports.zip");

int idxOle = worksheet.OleObjects.Add(0, 0, 60, 60, binaryImg4);
            OleObject objOle = worksheet.OleObjects[idxOle]; // worksheet.OleObjects[idxOle];
            byte[] binaryXlsx4 = File.ReadAllBytes(dir + "TS_Reports.zip");
            objOle.SetEmbeddedObject(false, binaryXlsx4, "TS_Reports.zip", false,null);
            workbook.Save(dir + "dest.xlsx");
}
        public static byte[] ToDisplayIcon(string iconPath, string label)
{
            using (Image image = Image.FromFile(iconPath))
    {
                // image.HorizontalResolution = image.VerticalResolution = 96;
                int w = 96;
                int h = 72;
                using (Bitmap bitmap = new Bitmap(w, h))
        {
                    Graphics graphics = Graphics.FromImage(bitmap);
                    graphics.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, w, h));
                    graphics.DrawImage(image, w / 2 - 16, 0,32,32);
                    //draw image
StringFormat format = new StringFormat();
                    format.Alignment = StringAlignment.Center;
                    graphics.DrawString(label, new System.Drawing.Font("Calibri", 11), new SolidBrush(Color.Black), new Rectangle(5, 35, w-5, h - 35), format);
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);
                    ms.Flush();
return ms.ToArray();
}
}
}

Hope, this helps a bit.

Hi @Amjad_Sahi,
Thank you for sharing the sample, I have tried this sample code but it didn’t work. Below are the scenario’s I have tried with the code you have shared.

  1. If I set displayAsIcon to True -> 1) I could not able to show my own icons, it is showing the default icons.
    2) Documents are opening properly as expected.

  2. If I set displayAsIcon to false - 1) I could able to show my own icons instead of default icons as expected.
    2) Documents are opening with in the excel itself.

  3. Expected Solution: 1) My own icons has to display instead of custom icons for (jpeg, msg, zip ets).
    2) Documents should open out side the excel not with in the excel…

I am attaching the poc solution and the excel which was generated from the poc solution for your reference.
Please check and suggest on how to proceed with this (displaying our own icons for Unkown format types and opening attachments out side the excel sheet).

Thanks.
2021-05-3–12-15-45TestAspose.zip (26.9 KB)

AsposeAttachmentsPOC1.zip (1.2 MB)

@srinivasaraju.b,
Thanks for the feedback. We will share our feedback soon.

Please let me know if have any solution for this.

@srinivasaraju.b,
This issue is not resolved yet due to its complexity. We will write back here once any update is ready for sharing.

@srinivasaraju.b,
We hope we can support this in the next week.

@srinivasaraju.b,
1: Now please try the following codes:

objOle.SetEmbeddedObject(false, binaryXlsx4, "TS_Reports.zip", false,null);
objOle.DisplayAsIcon = true;

Does it fit your needs?

2: We plan to add an overload method:

public void SetEmbeddedObject(bool linkToFile, byte[] objectData, string sourceFileName, bool displayAsIcon, string label, bool updateIcon).

If updateIcon is false, we will not automatically update icon when displayAsIcon is true.

  1. Yes @ahsaniqbalsidiqui, this code works for me. I could able to show my own icons as well as the documents also opening proper out side the excel…
  2. When can I expect the new version with this overload method?

Thank you for your prompt action. It’s greatly appreciated.

@srinivasaraju.b,

  1. Good to know that it works fine for your needs.
  2. Hopefully, the fix will be available before the end of next week.

@srinivasaraju.b,

Please try our latest version/fix: Aspose.Cells for .NET v21.3.1 (attached).
Aspose.Cells21.3.1 For .Net2_AuthenticodeSigned.Zip (5.5 MB)
Aspose.Cells21.3.1 For .Net4.0.Zip (5.5 MB)
Aspose.Cells21.3.1 For .NetStandard20.Zip (5.5 MB)

The overload method public void SetEmbeddedObject(bool linkToFile, byte[] objectData, string sourceFileName, bool displayAsIcon, string label, bool updateIcon) has been added.

Let us know your feedback.

Hi @Amjad_Sahi,

I have tried by setting up displayAsIcon is true and updateIcon is false and tried other ways as well…but attachments are opening with in the worksheet it self.

Please let me know how to set if I want to display my own icons as well to open attachments out side the excel sheet.

Please suggest me on how to do this to get the correct out put like how I was getting with below lines of code.

objOle.SetEmbeddedObject(false, binaryXlsx4, “TS_Reports.zip”, false,null);
objOle.DisplayAsIcon = true;

Thanks,

@srinivasaraju.b,
We have noted your feedback along with the ticket for our reference. We will notify you here once any update is available for sharing.

Sure, thanks @ahsaniqbalsidiqui, but mean while I have one question.

One of the excel sheet is attaching as a package, that’s the reason when I try to open that attachment it is displaying as “Office has blocked access to the following embedded object to keep you safe”.

Please find the attached screenshot.
ExcelAsPackage.PNG (23.4 KB)

Thanks,

@srinivasaraju.b,
Thank you for further information. We are analyzing it and will share our feedback soon.