XLSX Reports with FileRef fail, DOCX works

Hi JMix Team,

I’m having an issue generating XLSX reports using the JMix Reports Addon.

  • The template has a single band with all parameters referenced as ${parameter}.
  • We are trying to pass barcode images using FileRef and map them to a field in the Addon as ImageFileId (WXH).
  • With DOCX templates, this works fine and the barcode images are displayed.
  • With XLSX templates, the report fails to render the image.

The error is:

ReportingException: An error occurred while inserting bitmap to xlsx file  
Report name [StampaCartellino]  
Refusing to add another rel with id rId3. Target is /xl/media/sheet1_image_rId2.png

I would like to understand:

  1. Why FileRef works with DOCX but not XLSX templates.
  2. The recommended way to handle images in XLSX reports when using ImageFileId (WXH).

Any guidance would be greatly appreciated!

Here is my code snippet:
// Preparing report parameters
Map<String, Object> reportParams = new HashMap<>();
reportParams.put(“cod1”, COD != null ? COD : “”);
reportParams.put(“desa1”, DES != null ? DES : “”);
reportParams.put(“prz1”, PRZ != null ? PRZ : 0.0);
reportParams.put(“cbt1”, CBT != null ? CBT : “”);

// Load the report and template
Report report = dataManager.load(Report.class)
.query(“select r from report_Report r where r.name like :name”)
.parameter(“name”, “%StampaCartellino%”)
.one();
ReportTemplate template = report.getTemplateByCode(templateCode);

// Run report (example with DOCX output)
ReportOutputDocument doc = reportRunner.byReportEntity(report)
.withTemplate(template)
.withOutputType(ReportOutputType.DOCX)
.addParam(“cod1”, COD)
.addParam(“desa1”, DES)
.addParam(“prz1”, PRZ)
.addParam(“cbt1”, CBT)
.run();

// Download the generated report
downloader.download(doc.getContent(), “Cartellino.docx”);
And here is the report class that generates the barcode:
@Component
public class FrontalinoGrafico {

private final Metadata metadata;

public FrontalinoGrafico(Metadata metadata) {
    this.metadata = metadata;
}

public List<Map<String, Object>> FrontalinoDetailsgets(String cod1, String desa1, Double prz1, String cbt1) throws Exception {
    List<Map<String, Object>> list = new ArrayList<>();
    Map<String, Object> map = new HashMap<>();

    map.put("COD1", cod1);
    map.put("DESA1", desa1);
    map.put("PRZ1", prz1);

    // Generate barcode and save it to FileStorage
    FileRef barcode1 = generaBarcode(cbt1);
    map.put("CBT1", barcode1);

    list.add(map);
    return list;
}

@Autowired
private FileStorage fileStorage;

public FileRef generaBarcode(String contenuto) throws Exception {
    BitMatrix matrix = new MultiFormatWriter()
            .encode(contenuto, BarcodeFormat.CODE_128, 250, 80);

    BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "png", baos);

    try (InputStream is = new ByteArrayInputStream(baos.toByteArray())) {
        return fileStorage.saveStream(
                contenuto + ".png",
                is
        );
    }
}

}
Thanks,
Catalano Paolo