Interface IExportObjectListener

Interface IExportObjectListener

Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)

Allows users to manipulate objects while exporting.

public interface IExportObjectListener

Examples

The following example creates a Workbook, opens a file named designer.xls in it and makes the horizontal and vertical scroll bars invisible for the Workbook. It then replaces two string values with an Integer value and string value respectively within the spreadsheet and finally sends the updated file to the client browser.

csharp
[C#]
    //custom implementation of IExportObjectListener
    class CustomExportObjectListener : IExportObjectListener
    {
        private int imgIdx = 0;
        public object ExportObject(ExportObjectEvent e)
        {
            Object source = e.GetSource();
            if (source is Shape)
            {
                Shape shape = (Shape)source;
                string url = null;
                switch (shape.MsoDrawingType)
                {
                    case MsoDrawingType.Picture:
                    {
                        url = SaveImage(((Picture)shape).Data, imgIdx, ((Picture)shape).ImageType);
                        break;
                     }
                }
                if (url != null)
                {
                    imgIdx++;
                }
                return url;
            }
            return null;
        }
        private string SaveImage(byte[] data, int imgIdx, ImageType format)
        {
            //here save the image to any location, then return the url(relative or absolute) that the generated html can get the image
            return "temp1/temp2.png";
        }
     }

        //Save html file with custom listener
        Workbook book = null; //build your workbook here
        HtmlSaveOptions saveOptions = new HtmlSaveOptions();
        saveOptions.ExportObjectListener = new CustomExportObjectListener();
        Stream stream = null; //build your stream here
        book.Save("res.html", saveOptions); //or here you can build your out put stream and save the workbook to stream

Methods

ExportObject(ExportObjectEvent)

Export one object.

object ExportObject(ExportObjectEvent e)

Parameters

e ExportObjectEvent

The event triggered when one object needs to be exported.

Returns

object

The information about the result of exporting object.

  • For exporting objects when export workbook to HTML format, the result is URL string to access the saved Image from the html file which contains this exported object.