我正在尝试取消合并并重新合并更短或更长的范围,具体取决于表列的数量我在下面使用了这段代码,但它似乎不起作用
tableSheet.Cells["C1:J1"].Merge = false;
任何帮助将不胜感激。
您运行的是 EPP 4.0.1 吗? 如果是这样,则是一个已知问题:
https://epplus.codeplex.com/workitem/15134
有人为Merge
属性发布了一个替换二传手(尽管吸气器似乎仍然不正确)。 当我在 ExcelRangeBase 中粘贴他们的替换资源库时.cs并重新编译了这个测试方法开始为我工作:
[TestMethod]
public void Merge_Unmerge_Cells_Test()
{
var existingFile = new FileInfo(@"c:temptemp.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var package = new ExcelPackage(existingFile))
{
var workbook = package.Workbook;
var worksheet = workbook.Worksheets.Add("newsheet");
worksheet.Select("A1:C3");
worksheet.SelectedRange.Merge = true;
worksheet.SelectedRange.Value = "Merged Value";
worksheet.SelectedRange.Merge = false;
package.Save();
}
}
如果您运行的是版本 3,它应该可以正常工作,因此可以粘贴其余代码。
更新:来自代码复合体链接的代码。 寻找public bool Merge
并更换套装。
set
{
IsRangeValid("merging");
//SetMerge(value, FirstAddress);
if (!value)
{
if (_worksheet.MergedCells.Contains(FirstAddress))
{
_worksheet.MergedCells.Remove(FirstAddress);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
if (Addresses != null)
{
foreach (var address in Addresses)
{
if (_worksheet.MergedCells.Contains(address.Address))
{
_worksheet.MergedCells.Remove(address.Address);
}
else
{
throw (new ArgumentException("Range is not merged"));
}
}
}
}
else
{
_worksheet.MergedCells.Add(new ExcelAddressBase(FirstAddress), true);
if (Addresses != null)
{
foreach (var address in Addresses)
{
_worksheet.MergedCells.Add(address, true);
//SetMerge(value, address._address);
}
}
}
}