【问题标题】:Add Text to Merged Cells In Excel Spreadsheet Using EPPlus使用 EPPlus 将文本添加到 Excel 电子表格中的合并单元格
【发布时间】:2015-10-29 10:09:01
【问题描述】:

有谁知道我如何检查目录中是否有任何文件,如果没有,如何在合并单元格的 Excel 电子表格中添加文本“未找到内容”?

这是我尝试过的:

   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"));
                    }

问题:如何使用 EPplus 在 Excel 电子表格的合并单元格中添加文本?​​ 请帮我解决这个问题,谢谢!

【问题讨论】:

    标签: c# asp.net excel text epplus


    【解决方案1】:

    你可以使用

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

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

    【讨论】:

    • 嗨@Chawin,尝试了以下方法,但我的excel电子表格上没有出现任何内容。请看我更新的帖子谢谢!
    • @FeliciaSoh 我在ws.Cells["A1:A3"].Style.Fill.BackgroundColor.SetColor(System.Drawing.ColorTranslator.FromHtml("#f0f3f5")); 之后直接添加了我的代码,它运行良好,你的 if 函数中的代码是否运行过?
    猜你喜欢
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多