h3110 3v3ry0n3,特别是EPPlus团队!
我有一个这样的Excel模板:
_______________________________
| Title 1 | Title 2 |
|_______________|_______________|
| %Placeholder% | %Placeholder% |
|_______________|_______________|
| Special cell | Special cell |
|_______________|_______________|
特殊单元格 - 包含一些数据验证和数据列表的空单元格。
所以,这个模板有双重目的:
%placeholder%s
)或在第二种情况下,我调用sheet.DeleteRow(1)
并期望特殊行#3成为第2行(向上移动),但这不会发生。所以,问题是:这是一个错误,我应该发布一个问题,或者有一些解决办法迫使行向上移动?
这是一些想法。我想,这可能是因为特殊细胞处理为空。可能是,有一种方法可以将数据验证从第3行复制到第2行吗?对于更一般的情况,还有另一个类似的问题C# ExcelPackage (EPPlus) DeleteRow does not change sheet dimension?,并且似乎删除的行后面没有空行。
答案 0 :(得分:2)
似乎是一个已知问题。如果查看源代码中当前版本的ExcelWorksheet.cs
https://epplus.codeplex.com/SourceControl/latest#EPPlus/ExcelWorkbook.cs:
#region DeleteRow
/// <summary>
/// Delete the specified row from the worksheet.
/// </summary>
/// <param name="row">A row to be deleted</param>
public void DeleteRow(int row)
{
DeleteRow(row, 1);
}
/// <summary>
/// Delete the specified row from the worksheet.
/// </summary>
/// <param name="rowFrom">The start row</param>
/// <param name="rows">Number of rows to delete</param>
public void DeleteRow(int rowFrom, int rows)
{
CheckSheetType();
if (rowFrom < 1 || rowFrom + rows > ExcelPackage.MaxRows)
{
throw(new ArgumentException("Row out of range. Spans from 1 to " + ExcelPackage.MaxRows.ToString(CultureInfo.InvariantCulture)));
}
lock (this)
{
_values.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
_formulas.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
_flags.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
_commentsStore.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
_hyperLinks.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
_names.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
Comments.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns);
Workbook.Names.Delete(rowFrom, 0, rows, ExcelPackage.MaxColumns, n => n.Worksheet == this);
AdjustFormulasRow(rowFrom, rows);
FixMergedCellsRow(rowFrom, rows, true);
foreach (var tbl in Tables)
{
tbl.Address = tbl.Address.DeleteRow(rowFrom, rows);
}
foreach (var ptbl in PivotTables)
{
if (ptbl.Address.Start.Row > rowFrom + rows)
{
ptbl.Address = ptbl.Address.DeleteRow(rowFrom, rows);
}
}
}
}
没有更新public ExcelDataValidationCollection DataValidations
对象的引用。
查看当前的dev分支(现在在github上)似乎将在下一个版本中解决它:
https://github.com/JanKallman/EPPlus/blob/master/EPPlus/ExcelWorksheet.cs#L2551
哪个引用了codeplex上的问题:
https://epplus.codeplex.com/workitem/15573
因此,您可以尝试重现可能很难的功能,因为看起来他们必须在多个地方进行更改。或者你试着从git中提取最新内容并进行编译。