hi Members,
I have 1 directory with many subdirectories. Inside each subdirectory there are many images. I have successfully exported all images from each subdirectory into one excel worksheet each on 1 excel workbook.
For e.g. if I have 10 subdirectories, I will have 1 excel workbook with 10 excel worksheets, then in each excel worksheet there will be images from each subdirectory.
What I would like to do now is there's an image 'ColorBar' in my image folder, I want to add this image many times in each excel worksheet based on the number of images there are in each worksheet.
For e.g. if there are 3 images in worksheet1 and 2 images in worksheet2, I want to add 'ColorBar' image 3 times in worksheet1 and 2 times in worksheet2
(Please refer to links below).
This is my code:
public void ExportToExcel()
{
ExcelPackage objExcelPackage = new ExcelPackage();
string[] filesindirectory = Directory.GetDirectories(Server.MapPath("~/Folder"));
int count = 0;
int count1 = 0;
int x = 25;
int finalValue = 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.Web.UI.WebControls.Image TEST_IMAGE = new System.Web.UI.WebControls.Image();
System.Drawing.Image myImage = System.Drawing.Image.FromFile(img);
if (count1 > 1)
{
pic.SetPosition(finalValue, 0, 2, 0);
finalValue += (x + 1);
}
else
{
pic.SetPosition(count1, 0, 2, 0);
finalValue = (count1 + x) + 1;
}
myImage.Dispose();
}
}
var filepath = new FileInfo(@"C:\Users\user\Desktop\Test\" + datetime.ToString("dd-MM-yyyy_hh-mm-ss") + ".xlsx");
objExcelPackage.SaveAs(filepath);
}
This is my image folder path:
C:\Users\user\Desktop\Project\Project1\Project1\NewProject\NewProject\Image
This is the output I have currently:
http://i.stack.imgur.com/lIalH.png[
^]
This is the output I want to achieve:
http://i.stack.imgur.com/aq7Lq.png[
^]
Question: How to add same image from Image folder multiple times to each excel worksheet using EPplus?
Please help me on this, thanks!