What happened to ExportObjectListener between 2.5.4 and 7.2.1

I must have missed a version update of Aspose.Cells for Java. I updated from 2.5.4 to 7.2.1 and appear to be completely outdated. Can anyone advise me where to find intermediate javadocs between 2.5.4 and 7.2.1 so I can see the deprecation path for my code? Main point of interest is what replaced ExportObjectListener related.


public class CellsUtil
{

/**
* Converts office document contents into XHTML Document
*
* @param filename File name of document
* @param content Content of document
* @return AposeDocument instance
* @throws com.nxlight.framework.WebappException
* on convert error
*/
public static AsposeDocument createXhtmlAsposeDocument(String filename, byte[] content) throws WebappException
{
try
{
Workbook workbook = loadWorkbook(new ByteArrayInputStream(content), filename);
final List helpers = new ArrayList();

SaveOptions options = workbook.getSaveOptions();
options.setExportObjectListener(new ExportObjectListener()
{
@Override
public Object exportObject(ExportObjectEvent e) throws Exception
{
Object source = e.getSource();
if (source instanceof Picture)
{
Picture picture = (Picture) e.getSource();
byte[] data = picture.getData();
if (data != null)
{
String oldFileName = picture.getName();
String ext = “.png”;
int i = oldFileName.lastIndexOf(’.’);
if (i > 0 && i < oldFileName.length() - 1)
{
ext = oldFileName.substring(i);
if (".jpeg".equalsIgnoreCase(ext))
{
ext = “.jpg”;
}
}
String newFileName = “image_” + helpers.size() + ext;

ImageExtractHelper helper = new ImageExtractHelper();
helper.data = data;
helper.fileName = newFileName;
helpers.add(helper);

return newFileName;
}
}
return null;
}
});
options.setHtmlExportImagesFolderAlias("…/Images");

ByteArrayOutputStream os = new ByteArrayOutputStream();
workbook.save(os, FileFormatType.HTML);

final List images = new ArrayList();
for (ImageExtractHelper helper : helpers)
{
Image image = new Image();
image.setFilename(helper.fileName);
image.setContent(helper.data);
image.setContentType(StringUtil.getContentType(helper.fileName));
images.add(image);
}

content = WordsUtil.fixAspose(os.toByteArray(), false, null, null);

AsposeDocument asposeDocument = new AsposeDocument(content, filename);
if (images.size() > 0)
{
asposeDocument.setImages(images);
}
return asposeDocument;
}
catch (IOException e)
{
throw new WebappException(e);
}
}

public static List convertAspose(String filename, byte[] content, boolean pdf) throws WebappException
{
try
{
final String documentName = StringUtil.getFileNameWithoutExtension(filename);
Workbook workbook = loadWorkbook(new ByteArrayInputStream(content), filename);
SaveOptions options = workbook.getSaveOptions();
if (pdf)
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
options.setFontPath(new String[]{FontManager.getInstance().getFontsLocation()});
workbook.save(os, FileFormatType.PDF);
List files = new ArrayList(1);
Document doc = new Document();
doc.setContent(os.toByteArray());
doc.setFilename(filename + “.pdf”);
doc.setContentType(MimeUtil.PDF);
files.add(doc);
return files;
}
else
{
final List helpers = new ArrayList();
options.setExportObjectListener(new ExportObjectListener()
{
@Override
public Object exportObject(ExportObjectEvent e) throws Exception
{
Object source = e.getSource();
if (source instanceof Picture)
{
Picture picture = (Picture) e.getSource();
byte[] data = picture.getData();
if (data != null)
{
String oldFileName = picture.getName();
String ext = “.png”;
int i = oldFileName.lastIndexOf(’.’);
if (i > 0 && i < oldFileName.length() - 1)
{
ext = oldFileName.substring(i);
if (".jpeg".equalsIgnoreCase(ext))
{
ext = “.jpg”;
}
}
String newFileName = null == documentName || documentName.trim().length() == 0 ? “image_” + helpers.size() + ext : documentName + “_” + helpers.size() + ext;

ImageExtractHelper helper = new ImageExtractHelper();
helper.data = data;
helper.fileName = newFileName;
helpers.add(helper);

return newFileName;
}
}
return null;
}
});
options.setHtmlExportImagesFolderAlias("…/Images");

ByteArrayOutputStream os = new ByteArrayOutputStream();
workbook.save(os, FileFormatType.HTML);

final List images = new ArrayList();
for (ImageExtractHelper helper : helpers)
{
Image image = new Image();
image.setFilename(helper.fileName);
image.setContent(helper.data);
image.setContentType(StringUtil.getContentType(helper.fileName));
images.add(image);
}

content = WordsUtil.fixAspose(os.toByteArray(), false, null, null);

List files = new ArrayList(1);
Document doc = new Document();
doc.setContent(content);
doc.setFilename(filename + “.html”);
doc.setContentType(MimeUtil.PDF);
files.add(doc);
files.addAll(images);
return files;
}
}
catch (IOException e)
{
throw new WebappException(e);
}
}

public static boolean hasMacro(InputStream is, String filename)
{
try
{
Workbook wb = loadWorkbook(is, filename);
return wb.hasMacro();
}
catch (IOException e)
{
// silence
}
return false;
}

public static byte[] exportWorkbook(String[] columns, String[][] data, String name, int format, char… separator) throws IOException
{
Workbook wb = new Workbook();
// it adds several default sheets, remove them
while (wb.getWorksheets().size() > 0)
{
wb.getWorksheets().removeSheet(0);
}
Worksheet sheet = wb.getWorksheets().addSheet(name);
Cells cells = sheet.getCells();
for (int i = 0, len = columns.length; i < len; i++)
{
Cell cell = cells.getCell(0, i);
cell.setValue(columns[i]);
cells.setColumnWidthPixel(i, 180);
}
if (data != null)
{
for (int i = 0, len = data.length; i < len; i++)
{
String[] row = data[i];
if (row != null)
{
for (int j = 0, len2 = row.length; j < len2; j++)
{
Cell cell = cells.getCell(i + 1, j);
cell.setValue(row[j]);
}
}
}
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
if (separator != null && separator.length > 0)
{
wb.save(os, separator[0], “UTF-8”);
}
else
{
wb.save(os, format);
}
os.flush();
return os.toByteArray();
}

public static byte[] exportDataList(AbstractDataList list, char… separator) throws IOException
{
return exportWorkbook(list.getColumnNames(), list.getRows(), list.getName(), FileFormatType.EXCEL97TO2003, separator);
}

public static byte[] exportDataList(RestrictedListIterator iter, String name, int format, char… separator) throws IOException
{
String[] columns = iter.getColumnNames();
List<String[]> rows = new ArrayList<String[]>();
Iterator records = iter.getIterator();
if (records!=null)
{
while (records.hasNext())
{
DataRecord rec = records.next();
String[] line = new String[columns.length];
int index=0;
for (String col:columns)
{
line[index]=rec.get(col);
index++;
}
rows.add(line);
}
}
return exportWorkbook(columns, rows.toArray(new String[rows.size()][]), name, format, separator);

}

public static List parseWorkbook(InputStream is, String filename, boolean evalFormulas) throws IOException
{
Workbook wb = loadWorkbook(is, filename);
Worksheets sheets = wb.getWorksheets();
List lists = new ArrayList();
for (int i = 0, len = sheets.size(); i < len; i++)
{
Worksheet sheet = sheets.getSheet(i);
DataList list = new DataList();
list.setName(sheet.getName());

Cells cells = sheet.getCells();
List<String[]> dlRows = new ArrayList<String[]>();

for (Iterator rowIterator = cells.getRowIterator(); rowIterator.hasNext():wink:
{
Row row = rowIterator.next();
if (list.getColumns() == null)
{
List columnNames = new ArrayList();
int c = 0;
for (Iterator cellIterator = row.getCellIterator(); cellIterator.hasNext():wink:
{
Cell cell = cellIterator.next();
int current = cell.getColumnIndex();
if (c < current)
{
for (; c < current; c++)
{
columnNames.add("unnamed " + c);
}
}
columnNames.add(cell.isFormula() && !evalFormulas ? cell.getFormula() : cell.getStringValue());
c++;
}
list.setColumns(columnNames.toArray(new String[columnNames.size()]));
}
else if (list.getColumns().length > 0)
{
int c;
String[] dlRow = new String[list.getColumns().length];
for (Iterator cellIterator = row.getCellIterator(); cellIterator.hasNext():wink:
{
Cell cell = cellIterator.next();
c = cell.getColumnIndex();
if (c >= dlRow.length)
{
break;
}
dlRow[c] = cell.isFormula() && !evalFormulas ? cell.getFormula() : cell.getStringValue();
}
dlRows.add(dlRow);
}
else
{
break;
}
}
if (list.getColumns() != null && list.getColumns().length > 0)
{
list.setRecords(dlRows.toArray(new String[dlRows.size()][]));
lists.add(list);
}
}
return lists;
}

public static Workbook loadWorkbook(InputStream is, String fileName) throws IOException
{
Workbook workbook = new Workbook();
int type = FileFormatType.EXCEL97TO2003;
boolean convertNumbers = true;
if (fileName != null)
{
String ext = StringUtil.getFilenameExtensionNS(fileName.toLowerCase());
if (“xlsx”.equals(ext))
{
type = FileFormatType.XLSX;
}
else if (“ods”.equals(ext))
{
type = FileFormatType.ODS;
}
else if (“csv”.equals(ext))
{
type = FileFormatType.CSV;
convertNumbers = false;
}
else if (“txt”.equals(ext))
{
type = FileFormatType.TAB_DELIMITED;
convertNumbers = false;
}
}
workbook.getOpenOptions().setConvertNumericData(convertNumbers);
workbook.open(is, type);
return workbook;
}

private static class ImageExtractHelper
{
private byte[] data;
private String fileName;
}

}

Hi,

I have looked into your API and I think, it is not supported at the moment.

I have logged your question in our database. We will look into it and if possible support it asap.

Also, if there is any other alternative to it, we will let you know.

This issue has been logged as CELLSJAVA-40199.

Hi,


Please see the attached Excel file to know which APIs are changed or renamed in the new versions of the product while migrating from v2.5.x to 7.x.x.

Hope, this helps you for your requirements.

Thank you.

Hi,

Please download and try the latest fix: Aspose.Cells for Java v7.2.1.7

The old interface ExportObjectListener now changes to IExportObjectListener. The
usage of it for saving html file is same with old versions.

Where can I find the javadocs for 7.2.1.7?


D

Hi,

Javadoc for Aspose.Cells for Java v7.2.1.7 will be released with the Major Version i.e Aspose.Cells for Java v7.3.0.

It will be released in anytime in next coming weeks.

We will soon provide you a working example so that you can utilize it in your code.

Ok- I followed the changes in your Excel spreadsheet using the 7.2.1.7 jar. Looks like the only thing that will block me is SaveOptions.setFontPath which your spreadsheet does not appear to address. Is that completely gone?

Woops- sorry, I misread the spreadsheet. The answer is there for setFontDir.

Hi,

That’s great to know, you have fixed your code without Javadocs using the Excel spreadsheet.

If you like you can share your code relating to ExportObjectListener here. It will be helpful for other forum members too. Thank you.

The issues you have found earlier (filed as CELLSJAVA-40199) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.