hi all,
I have a main directory which contains many sub directories. In each sub directory there will be images. I have managed to export images from each subdirectory into each excel spreadsheet in a excel workbook. For example, if I have 10 sub directories, there will be 1 excel workbook with 10 excel spreadsheets, in each spreadsheet there will be each sub directory's images.
What I want to accomplish now is if there is no image in any sub directory, the sub directory exported to an excel spreadsheet will be blank. I want to
add "No image found" to that blank excel spreadsheet as text.
This is what I have tried but no text appear on the blank excel spreadsheet:
string[] filesindirectory = Directory.GetDirectories(Server.MapPath("~/StoreImage"));
int ImageCount = 0;
foreach (string subdir in filesindirectory)
{
string[] splitter = subdir.Split('\\');
string folderName = splitter[splitter.Length - 1];
ExcelWorksheet ws = package.Workbook.Worksheets.Add("Worksheet-" + folderName);
ImageCount = 0;
foreach (string img in Directory.GetFiles(subdir))
{
if (Directory.GetFiles(subdir).Length == 0)
{
ws.InsertRow(5, 2);
ws.Cells["A5"].Value = "12010";
ws.Cells["B5"].Value = "Drill";
ws.Cells["C5"].Value = 20;
ws.Cells["D5"].Value = 8;
ws.Cells["A6"].Value = "12011";
ws.Cells["B6"].Value = "Crowbar";
ws.Cells["C6"].Value = 7;
ws.Cells["D6"].Value = 23.48;
}
else
{
ImageCount++;
System.Drawing.Image Image1 = System.Drawing.Image.FromFile(img);
var ADDImage1 = ws.Drawings.AddPicture("Chart" + ImageCount.ToString(), Image1);
Image1.Dispose();
if (ImageCount > 1)
{
ADDImage1.SetPosition(ImageFinalPosition, 0, 2, 0);
ADDImage1.SetSize(770, 450);
ImageFinalPosition += (ImagePosition + 1);
}
else
{
ADDImage1.SetPosition(ImageCount, 0, 2, 0);
ADDImage1.SetSize(770, 450);
ImageFinalPosition = (ImageCount + ImagePosition) + 1;
}
}
}
}
This is the output I want to achieve:
http://i.stack.imgur.com/yi87U.png[
^]
Please help me on this, thanks!