Skip to content

Commit c2a779c

Browse files
committed
Add 2 new functions: DeleteFormControl and UnsetConditionalFormat
- Update unit test - Upgrade Go language version to 1.26.0 in build pipeline
1 parent 73e5dc9 commit c2a779c

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
go-version: [1.25.x]
11+
go-version: [1.26.x]
1212
os: [ubuntu-24.04, macos-latest, windows-latest]
1313
targetplatform: [x64]
1414

@@ -119,8 +119,8 @@ jobs:
119119
run: |
120120
docker run --rm -v $PWD:/src -w /src quay.io/pypa/manylinux2014_x86_64 bash -c "
121121
yum install -y wget || true
122-
wget https://go.dev/dl/go1.25.5.linux-amd64.tar.gz && \
123-
tar -C /usr/local -xzf go1.25.5.linux-amd64.tar.gz && \
122+
wget https://go.dev/dl/go1.26.0.linux-amd64.tar.gz && \
123+
tar -C /usr/local -xzf go1.26.0.linux-amd64.tar.gz && \
124124
export PATH=/usr/local/go/bin:\$PATH && \
125125
CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=amd64 \
126126
go build -buildmode=c-shared -ldflags='-s -w' -trimpath \
@@ -130,8 +130,8 @@ jobs:
130130
131131
docker run --rm -v $PWD:/src -w /src quay.io/pypa/manylinux2014_i686 bash -c "
132132
yum install -y wget || true
133-
wget https://go.dev/dl/go1.25.5.linux-386.tar.gz && \
134-
tar -C /usr/local -xzf go1.25.5.linux-386.tar.gz && \
133+
wget https://go.dev/dl/go1.26.0.linux-386.tar.gz && \
134+
tar -C /usr/local -xzf go1.26.0.linux-386.tar.gz && \
135135
export PATH=/usr/local/go/bin:\$PATH && \
136136
CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=386 \
137137
go build -buildmode=c-shared -ldflags='-s -w' -trimpath \
@@ -146,8 +146,8 @@ jobs:
146146
run: |
147147
docker run --rm -v $PWD:/src -w /src quay.io/pypa/manylinux2014_aarch64 bash -c "
148148
yum install -y wget || true
149-
wget https://go.dev/dl/go1.25.5.linux-arm64.tar.gz && \
150-
tar -C /usr/local -xzf go1.25.5.linux-arm64.tar.gz && \
149+
wget https://go.dev/dl/go1.26.0.linux-arm64.tar.gz && \
150+
tar -C /usr/local -xzf go1.26.0.linux-arm64.tar.gz && \
151151
export PATH=/usr/local/go/bin:\$PATH && \
152152
CGO_ENABLED=1 CC=gcc GOOS=linux GOARCH=arm64 \
153153
go build -buildmode=c-shared -ldflags='-s -w' -trimpath \

Excelize.Tests/UnitTest.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,15 @@ public void TestAddFormControl()
210210
Path.GetFullPath(Path.Combine("..", "..", "..", "vbaProject.bin"))
211211
)
212212
);
213+
f.DeleteFormControl("Sheet1", "B3");
213214
})
214215
);
215216
RuntimeError err = Assert.Throws<RuntimeError>(() =>
216217
f.AddFormControl("SheetN", new FormControl { })
217218
);
218219
Assert.Equal("sheet SheetN does not exist", err.Message);
220+
err = Assert.Throws<RuntimeError>(() => f.DeleteFormControl("SheetN", "A1"));
221+
Assert.Equal("sheet SheetN does not exist", err.Message);
219222
err = Assert.Throws<RuntimeError>(() =>
220223
f.SetSheetProps("SheetN", new SheetPropsOptions { })
221224
);
@@ -727,12 +730,15 @@ public void TestConditionalFormat()
727730
},
728731
}
729732
);
733+
f.UnsetConditionalFormat("Sheet1", "A5:A10");
730734
})
731735
);
732736
RuntimeError err = Assert.Throws<RuntimeError>(() =>
733-
f.SetConditionalFormat("SheetN", "A1", new ConditionalFormatOptions[] { })
737+
f.SetConditionalFormat("SheetN", "A1:A10", new ConditionalFormatOptions[] { })
734738
);
735739
Assert.Equal("sheet SheetN does not exist", err.Message);
740+
err = Assert.Throws<RuntimeError>(() => f.UnsetConditionalFormat("SheetN", "A1:A10"));
741+
Assert.Equal("sheet SheetN does not exist", err.Message);
736742
Assert.Null(Record.Exception(() => f.SaveAs("TestConditionalFormat.xlsx")));
737743
Assert.Empty(f.Close());
738744
}
@@ -1339,6 +1345,8 @@ public void TestStyle()
13391345
Assert.Equal(expected, err.Message);
13401346
err = Assert.Throws<RuntimeError>(() => f.DeleteComment("Sheet1", "A1"));
13411347
Assert.Equal(expected, err.Message);
1348+
err = Assert.Throws<RuntimeError>(() => f.DeleteFormControl("Sheet1", "A1"));
1349+
Assert.Equal(expected, err.Message);
13421350
err = Assert.Throws<RuntimeError>(() => f.DeletePicture("Sheet1", "A1"));
13431351
Assert.Equal(expected, err.Message);
13441352
err = Assert.Throws<RuntimeError>(() => f.DeleteSheet("Sheet1"));
@@ -1426,6 +1434,8 @@ public void TestStyle()
14261434
Assert.Equal(expected, err.Message);
14271435
err = Assert.Throws<RuntimeError>(() => f.SetWorkbookProps(new WorkbookPropsOptions()));
14281436
Assert.Equal(expected, err.Message);
1437+
err = Assert.Throws<RuntimeError>(() => f.UnsetConditionalFormat("Sheet1", "A1:A10"));
1438+
Assert.Equal(expected, err.Message);
14291439
err = Assert.Throws<RuntimeError>(() => f.UpdateLinkedValue());
14301440
Assert.Equal(expected, err.Message);
14311441
err = Assert.Throws<RuntimeError>(() => f.SaveAs("Book1.xlsx"));

Excelize/Excelize.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ internal static extern IntPtr DeleteComment(
238238
[MarshalAs(UnmanagedType.LPUTF8Str)] string cell
239239
);
240240

241+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
242+
internal static extern IntPtr DeleteFormControl(
243+
long fileIdx,
244+
[MarshalAs(UnmanagedType.LPUTF8Str)] string sheet,
245+
[MarshalAs(UnmanagedType.LPUTF8Str)] string cell
246+
);
247+
241248
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
242249
internal static extern IntPtr DeletePicture(
243250
long fileIdx,
@@ -583,6 +590,13 @@ internal static extern IntPtr StreamSetRow(
583590
long length
584591
);
585592

593+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
594+
internal static extern IntPtr UnsetConditionalFormat(
595+
long swIdx,
596+
[MarshalAs(UnmanagedType.LPUTF8Str)] string cell,
597+
[MarshalAs(UnmanagedType.LPUTF8Str)] string rangeRef
598+
);
599+
586600
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
587601
internal static extern IntPtr UpdateLinkedValue(long fileIdx);
588602

@@ -2762,6 +2776,34 @@ public void DeleteComment(string sheet, string cell)
27622776
throw new RuntimeError(err);
27632777
}
27642778

2779+
/// <summary>
2780+
/// DeleteFormControl provides the method to delete form control in a
2781+
/// worksheet by given worksheet name and cell reference.
2782+
/// <example>
2783+
/// For example, delete the form control in Sheet1!$A$1:
2784+
/// <code>
2785+
/// try
2786+
/// {
2787+
/// f.DeleteFormControl("Sheet1", "A1");
2788+
/// }
2789+
/// catch (RuntimeError err)
2790+
/// {
2791+
/// Console.WriteLine(err.Message);
2792+
/// }
2793+
/// </code>
2794+
/// </example>
2795+
/// </summary>
2796+
/// <param name="sheet">The worksheet name</param>
2797+
/// <param name="cell">The cell reference</param>
2798+
/// <exception cref="RuntimeError">Return None if no error occurred,
2799+
/// otherwise raise a RuntimeError with the message.</exception>
2800+
public void DeleteFormControl(string sheet, string cell)
2801+
{
2802+
string err = Marshal.PtrToStringUTF8(Lib.DeleteFormControl(FileIdx, sheet, cell));
2803+
if (!string.IsNullOrEmpty(err))
2804+
throw new RuntimeError(err);
2805+
}
2806+
27652807
/// <summary>
27662808
/// Delete all pictures in a cell by given worksheet name and cell
27672809
/// reference.
@@ -4818,6 +4860,24 @@ public void SetWorkbookProps(WorkbookPropsOptions options)
48184860
throw new RuntimeError(err);
48194861
}
48204862

4863+
/// <summary>
4864+
/// UnsetConditionalFormat provides a function to unset the conditional
4865+
/// format by given worksheet name and range reference.
4866+
/// </summary>
4867+
/// <param name="sheet">The worksheet name</param>
4868+
/// <param name="rangeRef">The top-left and right-bottom cell range
4869+
/// reference</param>
4870+
/// <exception cref="RuntimeError">Return None if no error occurred,
4871+
/// otherwise raise a RuntimeError with the message.</exception>
4872+
public void UnsetConditionalFormat(string sheet, string rangeRef)
4873+
{
4874+
string err = Marshal.PtrToStringUTF8(
4875+
Lib.UnsetConditionalFormat(FileIdx, sheet, rangeRef)
4876+
);
4877+
if (!string.IsNullOrEmpty(err))
4878+
throw new RuntimeError(err);
4879+
}
4880+
48214881
/// <summary>
48224882
/// Fix linked values within a spreadsheet are not updating in Office
48234883
/// Excel application. This function will be remove value tag when met a

0 commit comments

Comments
 (0)