Click here to Skip to main content
15,178,008 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I have many sub directories, in each sub directory, there are many images. Some sub directories have long names like "Thisismyfirstsubdirectoryinfolder", hence when I loop through each sub directory and add in images from each sub directory to each excel spreadsheet, the excel spreadsheet name will still be the sub directory folder name. But some of the characters are being cut off because the sub directory name is too long for the excel spreadsheet, so excel spreadsheet will just show "Thisismyfirstsubdire".

Does anyone know how can I check to see if the first 15 characters of the sub directory name matches with the first 15 characters of excel spreadsheet name?

This is my codes currently:
foreach (string subdir in filesindirectory)
                foreach (var sheet in package.Workbook.Worksheets)
                    string[] splitter = heatmapsubdir.Split('\\');
                    string folderName = heatmapsplitter[heatmapsplitter.Length - 1];
                    ImageCount = 0;

                    string worksheetname = sheet.Name.ToString();
                    foreach (char worksheetchar in sheet.Name)
                        if (folderName.Contains(worksheetchar.ToString()))
                            foreach (string img in Directory.GetFiles(subdir))
                                System.Drawing.Image IMAGE1 = System.Drawing.Image.FromFile(img);
                                var ADDIMAGE1 = sheet.Drawings.AddPicture("Image" + ImageCount.ToString(), IMAGE1);

                                if (ImageCount > 1)
                                    ADDIMAGE1.SetPosition(ImageFinalPosition + 1, 0, 14, 0);
                                    ADDIMAGE1.SetSize(22, 436);
                                    ImageFinalPosition += (ImagePosition + 1); // Add 1 to have 1 row of empty row
                                    ADDIMAGE1.SetPosition(ImageCount + 1, 0, 14, 0);
                                    ADDIMAGE1.SetSize(22, 436);
                                    ImageFinalPosition = (ImageCount + ImagePosition) + 1; // Add 1 to have 1 row of empty row

Please help me on this, thanks a lot!!

1 solution what happens when two sub directories share the same 15 starting characters?

Also, Excel, by default, uses a proportional font, so a filenames with differeing characters even if the same character length are not the same length when rendered in the cell.

Wouldn't it be easier to just widen the column the name is in?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900