3

does anyone know how do I check if there is any file in a directory, then if there isn't, how can I add text "content not found" onto the excel spreadsheet in merged cells?

This is what I have tried:

   foreach (string subdir in filesindirectory)
            {
                string[] splitter = subdir.Split('\\');
                string folderName = splitter[splitter.Length - 1];
                ExcelWorksheet ws = package.Workbook.Worksheets.Add(folderName); //create new worksheet
                ImageCount = 0;
                foreach (string img in Directory.GetFiles(subdir))
                {
                    if (subdir.Length == 0)
                    {

                        ws.Cells["A1:A3"].Merge = true;
                        ws.Cells["A1:A3"].Style.VerticalAlignment = ExcelVerticalAlignment.Top;
                        ws.Cells["A1:A3"].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                        ws.Cells["A1:A3"].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                        ws.Cells["A1:A3"].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                        ws.Cells["A1:A3"].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                        ws.Cells["A1:A3"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                        ws.Cells["A1:A3"].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#f0f3f5"));
                    }

Question: How to add text to merged cell in excel spreadsheet using EPplus? Please help me on this, thanks!

1 Answer 1

7

You can either use

ws.Cells["A1:A3"].Value = "content not found";

or

ws.Cells["A1"].Value = "content not found";
Sign up to request clarification or add additional context in comments.

2 Comments

hi @Chawin, have tried the following method but nothing appeared on my excel spreadsheet. Please look at my updated post thanks!
@FeliciaSoh I've added my code directly after ws.Cells["A1:A3"].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#f0f3f5")); and it works perfectly, is the code within your if function ever running?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.