使用 EPPlus 将文本添加到 Excel 电子表格中的合并单元格
Add Text to Merged Cells In Excel Spreadsheet Using EPPlus
有谁知道如何检查目录中是否有任何文件,如果没有,我如何将文本 "content not found" 添加到合并单元格中的 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 电子表格的合并单元格中添加文本?
请帮我解决这个问题,谢谢!
您可以使用
ws.Cells["A1:A3"].Value = "content not found";
或
ws.Cells["A1"].Value = "content not found";
有谁知道如何检查目录中是否有任何文件,如果没有,我如何将文本 "content not found" 添加到合并单元格中的 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 电子表格的合并单元格中添加文本? 请帮我解决这个问题,谢谢!
您可以使用
ws.Cells["A1:A3"].Value = "content not found";
或
ws.Cells["A1"].Value = "content not found";