From 456900bbef4691d2ff0aaf29d9ad7d84d13b8c06 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Wed, 26 Nov 2025 16:54:35 +0530 Subject: [PATCH 1/5] 991467-Image-Cell --- Document-Processing-toc.html | 3 + .../how-to-align-the-image-inside-the-cell.md | 106 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 40a62f69d..22f1d60ef 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -5848,6 +5848,9 @@
  • Does XlsIO support auto-correcting formulas?
  • +
  • + How to align a picture inside a cell in an Excel worksheet? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md new file mode 100644 index 000000000..dda7b99b4 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md @@ -0,0 +1,106 @@ +--- +title: Align a picture inside a cell in an Excel worksheet | Syncfusion +description: Learn how to align an image precisely within a worksheet cell using the Syncfusion .NET Excel (XlsIO) library, including positioning, fitting to the cell. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to align a picture inside a cell in an Excel worksheet? +Image can be aligned in the cell as required using the **TopRowOffset** and **LeftColumnOffset** properties of **ShapeImpl**. In the Microsoft Excel UI, the image is dragged to the required position manually. In the same way, there are no specific values for this property. The values can only be assigned manually. + +The following example shows how to align a picture inside a worksheet cell using the Syncfusion .NET Excel (XlsIO) library. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + int row = 2; + int column = 3; + + //Adding a picture + FileStream imageStream = new FileStream("../../../Data/Image.png", FileMode.Open, FileAccess.Read); + IPictureShape shape = worksheet.Pictures.AddPicture(row, column, imageStream); + + //Insert the image into the cell + (shape as ShapeImpl).Height = worksheet.GetRowHeightInPixels(row); + (shape as ShapeImpl).Width = worksheet.GetColumnWidthInPixels(column); + + //Algin the image inside the cell + (shape as ShapeImpl).TopRowOffset = 50; + (shape as ShapeImpl).LeftColumnOffset = 50; + + #region Save + //Saving the workbook + workbook.SaveAs("../../../Output/Picture.xlsx"); + #endregion + + //Dispose streams + imageStream.Dispose(); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + IApplication application = excelEngine.Excel; + application.DefaultVersion = ExcelVersion.Xlsx; + IWorkbook workbook = application.Workbooks.Create(1); + IWorksheet worksheet = workbook.Worksheets[0]; + + int row = 2; + int column = 3; + + //Adding a picture + string image = "../../Data/Image.png"; + IPictureShape shape = worksheet.Pictures.AddPicture(row, column, image); + + // Insert the image into the cell + (shape as ShapeImpl).Height = worksheet.GetRowHeightInPixels(row); + (shape as ShapeImpl).Width = worksheet.GetColumnWidthInPixels(column); + + //Algin the image inside the cell + (shape as ShapeImpl).TopRowOffset = 50; + (shape as ShapeImpl).LeftColumnOffset = 50; + + #region Save + //Saving the workbook + workbook.SaveAs("../../Output/Picture.xlsx"); + #endregion +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} + Using excelEngine As New ExcelEngine() + Dim application As IApplication = excelEngine.Excel + application.DefaultVersion = ExcelVersion.Xlsx + + Dim workbook As IWorkbook = application.Workbooks.Create(1) + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + Dim row As Integer = 2 + Dim column As Integer = 3 + + ' Adding a picture + Dim image As String = "../../Data/Image.png" + Dim shape As IPictureShape = worksheet.Pictures.AddPicture(row, column, image) + + ' Insert the image into the cell + Dim impl As ShapeImpl = CType(shape, ShapeImpl) + impl.Height = worksheet.GetRowHeightInPixels(row) + impl.Width = worksheet.GetColumnWidthInPixels(column) + + ' Align the image inside the cell + impl.TopRowOffset = 50 + impl.LeftColumnOffset = 50 + + ' Save + workbook.SaveAs("../../Output/Picture.xlsx") + End Using +{% endhighlight %} +{% endtabs %} From b09a9b269d5b15672c6d4de83c0b5e1c615136d4 Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 27 Nov 2025 18:48:33 +0530 Subject: [PATCH 2/5] 991467-Image-Cell --- Document-Processing-toc.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 22f1d60ef..40a62f69d 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -5848,9 +5848,6 @@
  • Does XlsIO support auto-correcting formulas?
  • -
  • - How to align a picture inside a cell in an Excel worksheet? -
  • From e18b032eebff56e095c69668e34830a1f504626e Mon Sep 17 00:00:00 2001 From: Ramya Sivakumar Date: Thu, 27 Nov 2025 19:02:25 +0530 Subject: [PATCH 3/5] 991467-Image-Cell --- Document-Processing-toc.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index ef4d2fab9..f977a1c0d 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -5879,6 +5879,18 @@
  • What is the unit of row height and column width in Excel?
  • +
  • + How to apply formatting to a specific column while importing data? +
  • +
  • + How to align a picture inside a cell in an Excel worksheet? +
  • +
  • + How to resolve the “Can't open Pivot table source file” error? +
  • +
  • + How to extract embedded OLE files from an Excel workbook as streams? +
  • From 995d6814faaef35da9c54e767533f1650c500dda Mon Sep 17 00:00:00 2001 From: MOHAN CHANDRAN <93247949+Mohan2401@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:39:47 +0530 Subject: [PATCH 4/5] Fix capitalization in FAQ link text --- Document-Processing-toc.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index f977a1c0d..3a8931eda 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -5886,7 +5886,7 @@ How to align a picture inside a cell in an Excel worksheet?
  • - How to resolve the “Can't open Pivot table source file” error? + How to resolve the cannot open pivot table source file error?
  • How to extract embedded OLE files from an Excel workbook as streams? From e221282f56c12e053e8134bbbe321d28854a41fd Mon Sep 17 00:00:00 2001 From: MOHAN CHANDRAN <93247949+Mohan2401@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:42:52 +0530 Subject: [PATCH 5/5] Update image alignment instructions in FAQ Clarified the description of image alignment in Excel cells. --- .../NET/faqs/how-to-align-the-image-inside-the-cell.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md index dda7b99b4..cb22aa130 100644 --- a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-align-the-image-inside-the-cell.md @@ -7,9 +7,8 @@ documentation: UG --- # How to align a picture inside a cell in an Excel worksheet? -Image can be aligned in the cell as required using the **TopRowOffset** and **LeftColumnOffset** properties of **ShapeImpl**. In the Microsoft Excel UI, the image is dragged to the required position manually. In the same way, there are no specific values for this property. The values can only be assigned manually. -The following example shows how to align a picture inside a worksheet cell using the Syncfusion .NET Excel (XlsIO) library. +Image can be aligned in the cell as required using the **TopRowOffset** and **LeftColumnOffset** properties of **ShapeImpl** instance. The following example shows how to align a picture inside a worksheet cell using the Syncfusion .NET Excel (XlsIO) library. {% tabs %} {% highlight c# tabtitle="C# [Cross-platform]" %}