Save images with the name of a cell in Calc


I’ve been searching everywhere but I can’t find much information on how to save the images with the name I want. Does anyone know if it is possible to do this? When I save the file as .ods and then rename it to .zip and unzip it the Pictures are exported but with a name that Calc generates I think. Is it possible to modify the XML that generates these names to change it to one of a Calc cell?

Best regards

I plan to do it exported to html and then with awk via cli rename the images with the field I want. From Calc I don’t know how to do that.

This naming and internal LibreOffice standard is the way to standardize names, so that there is no incompatibility between different operating systems.
It is possible to change the names in the xml, but the next save it will be renamed again.


These names are generated by a C++ code, not by an “XML”. These names are just a hash of the respective image content, allowing to have unique names depending on the image data, and same names when the same bytes are in two images. Indeed, it is possible to change the code in LibreOffice, but then:

  1. You would need to fight with possible duplication of identical images copied to several places in the document (these identical images would be stored several times with different names in the ODF, increasing the file size);
  2. You would need to deal somehow with several images anchored to the same cell…
1 Like

This can be done with macros. Please create an example file and explain where and with what names and extensions you would like to save the images.

1 Like

example.ods (203.7 KB)
Thanks for the replies.

Attached are the example.ods file

I want to name the image with the A column value. The Reference.

To name, right click on the image…






Noo, that not. I wanto to name with this code the exported images. And automatic process, that is hard to 6.000 pictures.

Thanks for the reply but I don’t want to store data in calc. I want to use the calc data to store the image in the disk with a name from a calc cell value. Sorry me english if do you not understand.

For example:
Column A Column B
123456 Picture1
654321 Picture2

I wanto to export the images to disk so:
… and so for the rest

Thanks for the example. We’ll create a macro in a couple of hours.

Please use the ExportImages button on the sheet.

Option Explicit

' Exports embedded images.
Sub ExportImages()
  Dim oSheet As Object, oGraphicProvider As Object, oShape As Object, oDrawPage As Object, oCell As Object
  Dim aProp(1) as new
  Dim i As Long, n as Long, arr
  arr=Split(ThisComponent.URL, "/") 
  oSheet=ThisComponent.Sheets(0)  ' first sheet of the current document
  For i=0 To oDrawPage.Count-1
    If HasUnoInterfaces(oCell, "") And oShape.supportsService("") Then
      If Not (oShape.graphic Is Null) Then
        aProp(0).Name  = "URL"
        arr(Ubound(arr))=oSheet.getCellbyPosition(0, oCell.cellAddress.row).String & ".png"
        aProp(0).Value=Join(arr, "/")
        aprop(1).Value="image/png"  ' 
        oGraphicProvider.storeGraphic oShape.graphic, aProp
      End If  
    End If
  Next i

  Msgbox "Exported images: " & n
End Sub

ExportImages.ods (205.9 KB)


You should post your solution as an answer.
BTW: I would prefer to use the anchor cell directly for the name. Images anchored
To Page should be excluded, and can’t anyway be treated based on an anchor’s CellAddress.

I prefer singly linked lists. :slightly_smiling_face:

1 Like

Works pretty well. Thanks a lot!


1 Like