【发布时间】:2018-05-08 05:50:12
【问题描述】:
首先,如果问这个问题的地方不对,请告诉我。
现在我会尽可能清楚地进入它。
我使用 EPPlus 从 C# 应用程序生成 Excel 文件。
文件生成正常,但在对其使用过滤器时(不是来自 EPPlus 的过滤器,而是来自 Excel 本身的过滤器),它不会过滤所有内容。它过滤了几行。
我可以提供代码sn-ps,或者excel生成的文件。来之前在网上搜索了很多,但是没有发现别人遇到这个问题。
提前感谢您的意见。
enter code here
ExcelPackage ExcelPkg = new ExcelPackage();
ExcelWorksheet wsSheet1 = ExcelPkg.Workbook.Worksheets.Add("Sheet1");
#region Create table and headers
using (ExcelRange Rng = wsSheet1.Cells[TableRange])
{
//Create Table
ExcelTable table = wsSheet1.Tables.Add(Rng, "OSTable");
for (int i = 0; i < headers.Count; i++)
{
table.Columns[i].Name = headers[i];
}
table.ShowHeader = true;
table.ShowFilter = false;
}
#endregion
#region 向 Excel 表格单元格中插入数据
foreach (ArticleRow ar in mainArticleList)
{
for (int i = 0; i < ar.Qty.Count; i++)
{
currentRow++;
string thisRowRange = "A" + currentRow.ToString() + ":" + "Q" + currentRow.ToString();
#region BOM_Position Col: A
using (ExcelRange Rng = wsSheet1.Cells["A" + currentRow.ToString()])
{
Rng.Value = Convert.ToInt32(ar.BOM_Position);
Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
Rng.Style.Font.Size = FontSize;
}
#endregion
#region Input Col: B
using (ExcelRange Rng = wsSheet1.Cells["B" + currentRow.ToString()])
{
Rng.Value = ar.Input;
Rng.Style.Font.Size = FontSize;
}
#endregion
#region QTY Col: J
using (ExcelRange Rng = wsSheet1.Cells["J" + currentRow.ToString()])
{
Rng.Value = ar.Qty[i];
Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
Rng.Style.Font.Size = FontSize;
}
#endregion
#endregion
#region Price Col: L
using (ExcelRange Rng = wsSheet1.Cells["L" + currentRow.ToString()])
{
Rng.Value = ar.Price[i];
Rng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
Rng.Style.Font.Size = FontSize;
}
#endregion
#endregion
#region ArticleUrl Col: Q
using (ExcelRange Rng = wsSheet1.Cells["Q" + currentRow.ToString()])
{
Rng.Formula = "=HYPERLINK(\"" + ar.Link + "\", \"" + ar.Store + "\")";
Rng.StyleName = StyleName;
Rng.Style.Font.Size = FontSize;
}
#endregion
#region Formatting Row Color by Store
using (ExcelRange Rng = wsSheet1.Cells[thisRowRange])
{
Rng.Style.Border.Top.Style = ExcelBorderStyle.None;
Rng.Style.Border.Bottom.Style = ExcelBorderStyle.None;
Rng.Style.Border.Left.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Left.Color.SetColor(Color.LightCyan);
Rng.Style.Border.Right.Style = ExcelBorderStyle.Thin;
Rng.Style.Border.Right.Color.SetColor(Color.LightCyan);
Rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
if (ar.Store == "Farnell" | ar.Store == "FarnellBETA")
{ Rng.Style.Fill.BackgroundColor.SetColor(ColorFarnellRow); }
else if (ar.Store == "Mouser")
{ Rng.Style.Fill.BackgroundColor.SetColor(ColorMouserRow); }
}
#endregion
#region Formatting Stock Cell Color by Content
using (ExcelRange Rng = wsSheet1.Cells["I" + currentRow.ToString()])
{
if (ar.Stock == "0" | ar.Stock == "-" | ar.Stock == "n/a" | ar.Stock == "--")
{
Rng.Style.Fill.PatternType = ExcelFillStyle.Solid;
Rng.Style.Fill.BackgroundColor.SetColor(Color.Red);
}
}
#endregion
}
}
#endregion
我已经删除了一些重复的代码部分,以免给你造成混乱。
【问题讨论】: