hi all,
I have exported images from a folder to excel as shown below. There will be two images side by side each other everytime. I would like to know how can I set specific position for the same image that is being displayed out multiple times.
For example, now the repeated image is being displayed at the same start and end position of the image next to it. I want it to start to be displayed 3 rows after the image next to it has started, and end of display 3 rows before the image next to it has ended
(Please see the image below).
This is the output I have currently:
http://i.stack.imgur.com/iGyE1.png[
^]
This is the output I want to achieve:
http://i.stack.imgur.com/WA0nU.png[
^]
This is my code: (same image to display multiple times: repeatimage, image next to repeatedimage: myImage)
public void ExportToExcel()
{
ExcelPackage objExcelPackage = new ExcelPackage();
string[] filesindirectory = Directory.GetDirectories(Server.MapPath("~/Folder"));
string repeatimagepath=@"C:\Users\user\Desktop\Project\Project1\Project1\NewProject\NewProject\Image\repeatimage.png";
int count = 0;
int count1 = 0;
int x = 25;
int finalValue = 0;
int finalValue1 = 0;
foreach (string subdir in filesindirectory)
{
count++;
string[] splitter = subdir.Split('\\');
string folderName = splitter[splitter.Length - 1];
ExcelWorksheet ws = objExcelPackage.Workbook.Worksheets.Add(folderName);
count1 = 0;
foreach (string img in Directory.GetFiles(subdir))
{
count1++;
System.Drawing.Image myImage = System.Drawing.Image.FromFile(img);
System.Drawing.Image repeatimage= System.Drawing.Image.FromFile(repeatimagepath);
var pic = ws.Drawings.AddPicture(count1.ToString(), myImage);
var picture = ws.Drawings.AddPicture("i" + count1.ToString(), repeatimage);
if (count1 > 1)
{
pic.SetPosition(finalValue, 0, 2, 0);
picture.SetPosition(finalValue1, 0, 15, 0);
picture.SetSize(30, 400);
finalValue += (x + 1);
finalValue1 += (x + 3);
}
else
{
pic.SetPosition(count1, 0, 2, 0);
picture.SetPosition(count1, 0, 15, 0);
picture.SetSize(30, 400);
finalValue = (count1 + x) + 1;
finalValue1 = (count1 + x) + 3;
}
myImage.Dispose();
repeatimage.Dispose();
}
}
var filepath = new FileInfo(@"C:\Users\user\Desktop\Test\" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx");
objExcelPackage.SaveAs(filepath);
}
Thanks.