Home  Products  Purchase  Downloads  Demos  Forums  Blogs  Ticket  Wiki  API  Corporate


com.aspose.cells
Interface ExportObjectListener


public interface ExportObjectListener

Represents the method that will handle the ExportObjectEvent event. One can implement this interface in a class that needs in notification if ExportObjectEvent event is occur. Implementing class also must be registered as event subscriber by call to SaveOptions.setExportObjectSavingListener(ExportObjectListener) method. Example:

      // register an ExportObjectListener to get the image data when export to HTML format.
      int imgIdx = 0;
  
      private void saveHTMLToStream() throws Exception
      {
          String path = "temp/";
          String infn = path + "expImage.xls";
          String outfn = path + "expImage_out.htm";
      
          Workbook book = new Workbook();
          book.open(infn);
      
          SaveOptions saveOptions = book.getSaveOptions();
          saveOptions.setExportObjectListener(
          new ExportObjectListener()
          {
              public Object exportObject(ExportObjectEvent e) throws Exception
              {
                  Object source = e.getSource();
                  if(source instanceof Picture)
                  {
                      Picture pic = (Picture)source;
                      String fn = "temp/imgFolder/image" + (imgIdx++);
                      // String fn = "temp/imgFolder/image" + (imgIdx++) + getFileSuffix(pic.getImageFormat()); 

                      byte[] data = pic.getData();
                      if(data != null && data.length > 0)
                      {
                          FileOutputStream fs = new FileOutputStream(fn);
                          fs.write(data);
                          fs.flush();
                          fs.close();
                  
                          return fn; // return the file path and filename that will be used in HTML document
                      }
                  }
                  return null;
              }
          });

          FileOutputStream os = new FileOutputStream(outfn);
          book.save(os, FileFormatType.HTML);
          os.flush();
          os.close();        
      }


Method Summary
 java.lang.Object exportObject(ExportObjectEvent e)
          Allows to export extra object data when export to HTML format such as exporting Images.
 

Method Detail

exportObject

java.lang.Object exportObject(ExportObjectEvent e)
                              throws java.lang.Exception
Allows to export extra object data when export to HTML format such as exporting Images. The event occurs when an object such as image need to be saved.

Parameters:
e - the ExportObjectEvent object allows to get the object data.
Returns:
the information about the result of exporting object.
  • For exporting Images when export to HTML format, the result is String that represents the URL(or file path and name) to access the saved Image. If the URL is a relative path, the base should be the path of the HTML file of corresponding Sheet.
Throws:
java.lang.Exception