none
table RRS feed

Answers

  • Hi pranay,

    >>How to get alt text of all type of images in a excel using openxml

    What do you mean with alt text? Do you mean Title and Description for images? If so, you could try something like below:

    public  void ChangeDrawingsPart(DrawingsPart drawingsPart1)
            {
                Xdr.WorksheetDrawing worksheetDrawing1 = drawingsPart1.WorksheetDrawing;
    
                Xdr.TwoCellAnchor twoCellAnchor1=worksheetDrawing1.GetFirstChild<Xdr.TwoCellAnchor>();
    
                Xdr.Picture picture1=twoCellAnchor1.GetFirstChild<Xdr.Picture>();
    
                Xdr.NonVisualPictureProperties nonVisualPictureProperties1=picture1.GetFirstChild<Xdr.NonVisualPictureProperties>();
    
                Xdr.NonVisualDrawingProperties nonVisualDrawingProperties1=nonVisualPictureProperties1.GetFirstChild<Xdr.NonVisualDrawingProperties>();
                nonVisualDrawingProperties1.Description = "ALTDescription";
                nonVisualDrawingProperties1.Title = "ALTTitle";
            }
    

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 8, 2016 6:20 AM
  • Hi pranay,

    >> I want a code for multiple images in a single excel.

    For all the images in excel, you will need to loop through WorksheetParts and DrawingsPart.

    Here is a simple code:

            public void ChangeImageATL(string filePath)
            { 
                using(SpreadsheetDocument sheetDocument=SpreadsheetDocument.Open(filePath,true))
                {
                    WorkbookPart workbookPart = sheetDocument.WorkbookPart;
                    foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts)
                    {
                        DrawingsPart drawingsPart = worksheetPart.DrawingsPart;
                        ChangeDrawingsPart(drawingsPart);
                    }
                }
            }
            public void ChangeDrawingsPart(DrawingsPart drawingsPart1)
            {
                Xdr.WorksheetDrawing worksheetDrawing1 = drawingsPart1.WorksheetDrawing;
                foreach(Xdr.TwoCellAnchor twoCellAnchor in worksheetDrawing1.Elements<Xdr.TwoCellAnchor>())
                {
                    Xdr.Picture picture1 = twoCellAnchor.GetFirstChild<Xdr.Picture>();
                    Xdr.NonVisualPictureProperties nonVisualPictureProperties1 = picture1.GetFirstChild<Xdr.NonVisualPictureProperties>();
                    Xdr.NonVisualDrawingProperties nonVisualDrawingProperties1 = nonVisualPictureProperties1.GetFirstChild<Xdr.NonVisualDrawingProperties>();
                    MessageBox.Show(nonVisualDrawingProperties1.Description + "; " + nonVisualDrawingProperties1.Title);
                }            
            }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 8, 2016 8:07 AM

All replies

  • Hi pranay,

    >>How to get alt text of all type of images in a excel using openxml

    What do you mean with alt text? Do you mean Title and Description for images? If so, you could try something like below:

    public  void ChangeDrawingsPart(DrawingsPart drawingsPart1)
            {
                Xdr.WorksheetDrawing worksheetDrawing1 = drawingsPart1.WorksheetDrawing;
    
                Xdr.TwoCellAnchor twoCellAnchor1=worksheetDrawing1.GetFirstChild<Xdr.TwoCellAnchor>();
    
                Xdr.Picture picture1=twoCellAnchor1.GetFirstChild<Xdr.Picture>();
    
                Xdr.NonVisualPictureProperties nonVisualPictureProperties1=picture1.GetFirstChild<Xdr.NonVisualPictureProperties>();
    
                Xdr.NonVisualDrawingProperties nonVisualDrawingProperties1=nonVisualPictureProperties1.GetFirstChild<Xdr.NonVisualDrawingProperties>();
                nonVisualDrawingProperties1.Description = "ALTDescription";
                nonVisualDrawingProperties1.Title = "ALTTitle";
            }
    

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 8, 2016 6:20 AM
  • Hi Edward,

    Is is for only one image , I want a code which gives me description of all the images in the excel not a single image. The code is working fine which you give but works only for single image, I want a code for multiple images in a single excel. 

    Monday, August 8, 2016 6:41 AM
  • Hi pranay,

    >> I want a code for multiple images in a single excel.

    For all the images in excel, you will need to loop through WorksheetParts and DrawingsPart.

    Here is a simple code:

            public void ChangeImageATL(string filePath)
            { 
                using(SpreadsheetDocument sheetDocument=SpreadsheetDocument.Open(filePath,true))
                {
                    WorkbookPart workbookPart = sheetDocument.WorkbookPart;
                    foreach (WorksheetPart worksheetPart in workbookPart.WorksheetParts)
                    {
                        DrawingsPart drawingsPart = worksheetPart.DrawingsPart;
                        ChangeDrawingsPart(drawingsPart);
                    }
                }
            }
            public void ChangeDrawingsPart(DrawingsPart drawingsPart1)
            {
                Xdr.WorksheetDrawing worksheetDrawing1 = drawingsPart1.WorksheetDrawing;
                foreach(Xdr.TwoCellAnchor twoCellAnchor in worksheetDrawing1.Elements<Xdr.TwoCellAnchor>())
                {
                    Xdr.Picture picture1 = twoCellAnchor.GetFirstChild<Xdr.Picture>();
                    Xdr.NonVisualPictureProperties nonVisualPictureProperties1 = picture1.GetFirstChild<Xdr.NonVisualPictureProperties>();
                    Xdr.NonVisualDrawingProperties nonVisualDrawingProperties1 = nonVisualPictureProperties1.GetFirstChild<Xdr.NonVisualDrawingProperties>();
                    MessageBox.Show(nonVisualDrawingProperties1.Description + "; " + nonVisualDrawingProperties1.Title);
                }            
            }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 8, 2016 8:07 AM