Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Excelize.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,14 @@ public void TestMergeCells()
);
RuntimeError err = Assert.Throws<RuntimeError>(() => f.MergeCell("SheetN", "A1", "B2"));
Assert.Equal("sheet SheetN does not exist", err.Message);
Assert.Null(
Record.Exception(() =>
{
f.UnmergeCell("Sheet1", "D3", "E9");
})
);
err = Assert.Throws<RuntimeError>(() => f.UnmergeCell("SheetN", "A1", "B2"));
Assert.Equal("sheet SheetN does not exist", err.Message);
Assert.Null(Record.Exception(() => f.SaveAs("TestMergeCells.xlsx")));
Assert.Empty(f.Close());
}
Expand Down
39 changes: 39 additions & 0 deletions Excelize/Excelize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ internal static extern IntPtr MergeCell(
[MarshalAs(UnmanagedType.LPUTF8Str)] string bottomRightCell
);

[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr UnmergeCell(
long fileIdx,
[MarshalAs(UnmanagedType.LPUTF8Str)] string sheet,
[MarshalAs(UnmanagedType.LPUTF8Str)] string topLeftCell,
[MarshalAs(UnmanagedType.LPUTF8Str)] string bottomRightCell
);

[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr MoveSheet(
long fileIdx,
Expand Down Expand Up @@ -6338,6 +6346,37 @@ public void UngroupSheets()
throw new RuntimeError(err);
}

/// <summary>
/// UnmergeCell provides a function to unmerge a given range reference.
/// <example>
/// For example unmerge range reference D3:E9 on Sheet1:
/// <code>
/// try
/// {
/// f.UnmergeCell("Sheet1", "D3", "E9");
/// }
/// catch (RuntimeError err)
/// {
/// Console.WriteLine(err.Message);
/// }
/// </code>
/// </example>
/// </summary>
/// <param name="sheet">The worksheet name</param>
/// <param name="topLeftCell">The top-left cell reference</param>
/// <param name="bottomRightCell">The bottom-right cell reference</param>
/// <remarks>Attention: overlapped range will also be unmerged</remarks>
/// <exception cref="RuntimeError">Return None if no error occurred,
/// otherwise raise a RuntimeError with the message.</exception>
public void UnmergeCell(string sheet, string topLeftCell, string bottomRightCell)
{
string err = Marshal.PtrToStringUTF8(
Lib.UnmergeCell(FileIdx, sheet, topLeftCell, bottomRightCell)
);
if (!string.IsNullOrEmpty(err))
throw new RuntimeError(err);
}

/// <summary>
/// UnsetConditionalFormat provides a function to unset the conditional
/// format by given worksheet name and range reference.
Expand Down