Issue saving images

The following code fails:

 boolean npe = false;
    try {
        Workbook workbook = new Workbook(filePath);
        Worksheet worksheet = workbook.getWorksheets().get(1);
        int imageCounter = 0;
        for(int j=0; j<worksheet.getCharts().getCount(); j++) {
            Chart chart = worksheet.getCharts().get(j);

             String filename = MessageFormat.format("{0}{1}{2}_", "C", 1, imageCounter) + "fc336084-170a-4ce9-a7e3-673a9921f11d";
            String tempFileName = FileUtilities.getTempFile(filename, ".chart.png");
            chart.toImage(tempFileName, imgOptions);
            imageCounter++;
        }

     } catch (Exception e) {
        e.printStackTrace(System.err);
        npe = true;
    }

     p = Paths.get(s3Uris[1]);
    fileName = p.getFileName().toString();

     filePath = "/tmp/" + fileName;
    com.csdisco.process.utilities.Utilities.downloadFile(s3Uris[1], filePath);

     int notFound = 0;
    try {
        Set<String> outputFiles = new HashSet<>();
        int imageCounter = 0;
        Workbook workbook = new Workbook(filePath);
        Worksheet worksheet = workbook.getWorksheets().get(3);
        for(int j=0; j<worksheet.getSparklineGroupCollection().getCount(); j++) {
            SparklineGroup sparklineGroup = worksheet.getSparklineGroupCollection().get(j);

             for (int z = 0; z < sparklineGroup.getSparklineCollection().getCount(); z++) {
                Sparkline sparkline = sparklineGroup.getSparklineCollection().get(z);

                 String filename = MessageFormat.format("{0}{1}{2}_", "K", 3, imageCounter) + "fc336084-170a-4ce9-a7e3-673a9921f11d";
                String tempFileName = FileUtilities.getTempFile(filename, ".sparkline.png");

                 sparkline.toImage(tempFileName, imgOptions);
                imageCounter++;
                outputFiles.add(tempFileName);
            }
        }

         for (String outputFilename : outputFiles) {
            File f = new File(outputFilename);
            if(!f.exists()) {
                System.err.println("File Not found: " + f.getName());
                notFound++;
            }
        }

     }
    catch (Exception e){
        e.printStackTrace();
    }

     assertEquals("Chart NPE", false, npe);
    assertEquals("File Not Found", 0, notFound);

Files:

https://www.dropbox.com/s/o7q23slvnld0t0u/runtime-cells.xlsm?dl=0
https://www.dropbox.com/s/rx2hk1j6tdxtwto/image-not-found.xlsx?dl=0

@russ.nichols,
Thank you for writing to Aspose support team. This code seems to be taken from an existing project and contains many references and variables whose values are not known. Please provide us a standalone console application which can be directly executed without any error to reproduce the issue here. It will help us to observe the issue here and provide assistance accordingly.

ISSUE WITH chart.toImage()

try {
    Workbook workbook = new Workbook(<PATH TO FILE - runtime-cells.xlsm>);
    Worksheet worksheet = workbook.getWorksheets().get(1);
    int imageCounter = 0;
    for(int j=0; j<worksheet.getCharts().getCount(); j++) {
        Chart chart = worksheet.getCharts().get(j);

         String filename = MessageFormat.format("{0}{1}{2}_", "C", 1, imageCounter);
        String tempFileName = FileUtilities.getTempFile(filename, ".chart.png");
        chart.toImage(tempFileName, imgOptions);
        imageCounter++;
    }

 } catch (Exception e) {
    e.printStackTrace(System.err);
}

ISSUE WITH sparkline.toImage()

    Set<String> outputFiles = new HashSet<>();
    int imageCounter = 0;
    Workbook workbook = new Workbook(<PATH TO FILE - image-not-found.xlsx>);
    Worksheet worksheet = workbook.getWorksheets().get(3); //Make sure this is set to 3
    for(int j=0; j<worksheet.getSparklineGroupCollection().getCount(); j++) {
        SparklineGroup sparklineGroup = worksheet.getSparklineGroupCollection().get(j);
         for (int z = 0; z < sparklineGroup.getSparklineCollection().getCount(); z++) {
            Sparkline sparkline = sparklineGroup.getSparklineCollection().get(z);

             String filename = MessageFormat.format("{0}{1}{2}_", "K", 3, imageCounter);
            String tempFileName = FileUtilities.getTempFile(filename, ".sparkline.png");

             sparkline.toImage(tempFileName, imgOptions);
            imageCounter++;
            outputFiles.add(tempFileName);
        }
    }

//NOTE The above code claims to produce about 8000 output files, only 88 is actuality.

     for (String outputFilename : outputFiles) {
        File f = new File(outputFilename);
        if(!f.exists()) {
            System.err.println("File Not found: " + f.getName());
            notFound++;
        }
    }

@ravikashyap,
We were able to observe the issues but we need to look into them more. We have logged the issues in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

 CELLSJAVA-42992 – Exception raised while converting XLSM to image
 CELLSJAVA-42993 – Wrong numbers shown while creating images from Sparkline

@ravikashyap,

We evaluated the issue in details. This is not an issue with Aspose.Cells. We found some rows are not visible in spreadsheet (See attached picture), so they are not saved to images.
1.png (38.0 KB)

@ravikashyap,

Please try our latest version/fix: Aspose.Cells for Java v19.8.3 (attached)

Your issue “CELLSJAVA-42992” should be fixed in it.

Let us know your feedback.
Aspose_Cells_Java_v19.8.3.zip (6.6 MB)

When is Aspose.Cells 19.9 getting released?

@ravikashyap,
Aspose.Cells for Java 19.9 will be released at the end of next week. You will be automatically notified once this release is published and available online for download.

The problem is that the call sparkline.ToImage(tempFileName, imgOptions) fails silently and not create the tempfile when it sees some rows are not visible.
This is a bug, IMO. The call should throw an exception when it cannot process an invisible row.
Otherwise how can I know when something went wrong?

@ravikashyap,
We have recorded this information with the logged ticket for our reference. I will write back here as soon as some feedback is ready to share.

@ravikashyap,

Please see the following sample code. We hope the following workaround can cope with it.
e.g
Sample code:

if(worksheet.getCells().getRowHeight(sparkline.getRow())>0 && worksheet.getCells().getColumnWidth(sparkline.getColumn())>0) {
    sparkline.toImage(tempFileName, imgOptions);
    imageCounter++;
    outputFiles.add(tempFileName);
}

Otherwise, you can set the value of RowHeight and ColumnWidth larger than 0 to save to image:

worksheet.getCells().setRowHeight(sparkline.getRow(),1);
worksheet.getCells().setColumnWidth(sparkline.getColumn(),1);
sparkline.toImage(tempFileName, imgOptions);

Hope, this helps a bit.

The issues you have found earlier (filed as CELLSJAVA-42992) have been fixed in Aspose.Cells for Java v19.9. This message was posted using BugNotificationTool from Downloads module by ahsaniqbalsidiqui

I am currently evaluating Aspose.Cells for Android via Java in version 19.9 and the issue CELLSJAVA-42992 still occurs for me.

@Nicole_Weiss,

We will check your issue using newer version and get back to you soon.

@Nicole_Weiss,

I have tested your scenario/ case using latest Aspose.Cells for Android via Java v19.9 with its latest resource Jar file (.apk), it works fine and all the five charts in worksheet 2 are generated fine. I do not find any exception. I am using Android Studio to test your issue (logged earlier as “CELLSJAVA-42992” ). I am using the original file with the following sample code:
e.g
Sample code:

String sdCardPath = Environment.getExternalStorageDirectory().getPath() + File.separator;
   
         Workbook workbook = new Workbook(sdCardPath + "runtime-cells.xlsm");
            Worksheet worksheet = workbook.getWorksheets().get(1);
            int imageCounter = 0;
            for (int j = 0; j < worksheet.getCharts().getCount(); j++) {
                Chart chart = worksheet.getCharts().get(j);

               ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                imgOptions.setChartImageType(ImageFormat.getPng());
                chart.toImage(sdCardPath + "chart" +imageCounter + ".png", imgOptions);
                imageCounter++;

            }

Please find attached the output image files for different charts in the second sheet.
files1.zip (100.3 KB)

Ah yes you’re right, I’m sorry I didn’t properly read.

I am not trying to create images from charts but from sheets.
My sample code:

   val workbook = Workbook(inputStream)
    val sheet = workbook.worksheets.get(0)
    val imgOptions = ImageOrPrintOptions().apply { imageType = ImageType.PNG }
    val render = SheetRender(sheet, imgOptions)
    render.toImage(outputStream, imgOptions)

In your documentation you set imageFormat instead of imageType which is deprecated and didn’t work, too.

@Nicole_Weiss,

I think your code is not right. I have tested the following code using the original file and it works fine. I got images for the first sheet pages:
e.g
Sample code:

String sdCardPath = Environment.getExternalStorageDirectory().getPath() + File.separator;

            Workbook workbook = new Workbook(sdCardPath + "runtime-cells.xlsm");
            Worksheet worksheet = workbook.getWorksheets().get(0);
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            imgOptions.setImageType(ImageType.PNG);

            SheetRender sr = new SheetRender(worksheet,imgOptions);

            for (int j = 0; j < sr.getPageCount(); j++) {

                sr.toImage(j, sdCardPath + "sheetpage" +j + ".png");


            } 

And, please find attached the output images for your reference.
outfiles.zip (76.1 KB)