When we add an image to the Excel worksheet, we always need to reset the size and position for the image to list the image where we want and make the size coordinate with the other elements on the Excel worksheet. This article will focus on demonstrates how to apply picture settings by using Spire.XLS.
Step 1: Initialize an instance of Workbook and get the first worksheet.
Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0];
Step 2: Add a picture to the first worksheet.
ExcelPicture picture = sheet.Pictures.Add(1, 1, "Logo.png");
Step 3: Set the size for the picture.
picture.Width = 75; picture.Height = 75;
Step 4: Set the position for the picture.
picture.Left = 200; picture.Top = 100;
Step 5: Save the document to file.
workbook.SaveToFile("Output.xlsx",FileFormat.Version2013);
Effective screenshot after reset the size and position for the image:
Full codes:
using Spire.Xls; namespace ReseSizeandPosition { class Program { static void Main(string[] args) { Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; ExcelPicture picture = sheet.Pictures.Add(1, 1, "Logo.png"); picture.Width = 75; picture.Height = 75; picture.Left = 200; picture.Top = 100; workbook.SaveToFile("Output.xlsx", FileFormat.Version2013); } } }