Skip to content

Commit dfa9940

Browse files
committed
Add new function: CopySheet
- Fix build break by remapping Interface data structure - Update unit test - Remove CodeQL configuration
1 parent 53e907a commit dfa9940

File tree

5 files changed

+31
-43
lines changed

5 files changed

+31
-43
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

Excelize.Tests/UnitTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public void TestStyle()
166166
},
167167
f.GetRows("Sheet1")
168168
);
169+
Assert.Null(Record.Exception(() => f.CopySheet(0, f.NewSheet("Sheet3"))));
169170
Assert.Null(Record.Exception(() => f.SaveAs("Book1.xlsx")));
170171
Assert.Empty(f.Close());
171172

@@ -186,6 +187,8 @@ public void TestStyle()
186187
Assert.Equal(expected, err.Message);
187188
err = Assert.Throws<RuntimeError>(() => f.AddVBAProject(Array.Empty<byte>()));
188189
Assert.Equal(expected, err.Message);
190+
err = Assert.Throws<RuntimeError>(() => f.CopySheet(1, 2));
191+
Assert.Equal(expected, err.Message);
189192
err = Assert.Throws<RuntimeError>(() => f.GetCellValue("Sheet1", "A1"));
190193
Assert.Equal(expected, err.Message);
191194
err = Assert.Throws<RuntimeError>(() => f.GetRows("Sheet1"));

Excelize/Excelize.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ internal static extern TypesC.CellNameToCoordinatesResult CellNameToCoordinates(
191191
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
192192
internal static extern IntPtr Close(long fileIdx);
193193

194+
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
195+
internal static extern IntPtr CopySheet(long fileIdx, int from, int to);
196+
194197
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
195198
internal static extern TypesC.IntErrorResult ColumnNameToNumber(
196199
[MarshalAs(UnmanagedType.LPUTF8Str)] string name
@@ -366,12 +369,12 @@ public static object CsValToCInterface(object value)
366369
value switch
367370
{
368371
int _ => new Interface { Type = 1, Integer = (int)value },
369-
string _ => new Interface { Type = 2, String = (string)value },
370-
double _ => new Interface { Type = 3, Float = (double)value },
371-
float _ => new Interface { Type = 3, Float = (float)value },
372-
long _ => new Interface { Type = 3, Float = (long)value },
373-
short _ => new Interface { Type = 3, Float = (short)value },
374-
bool _ => new Interface { Type = 4, Boolean = (bool)value },
372+
string _ => new Interface { Type = 3, String = (string)value },
373+
double _ => new Interface { Type = 4, Float = (double)value },
374+
float _ => new Interface { Type = 4, Float = (float)value },
375+
long _ => new Interface { Type = 4, Float = (long)value },
376+
short _ => new Interface { Type = 4, Float = (short)value },
377+
bool _ => new Interface { Type = 5, Boolean = (bool)value },
375378
_ => new Interface { Type = 0 },
376379
},
377380
new TypesC.Interface()
@@ -2356,11 +2359,26 @@ public string Close()
23562359
return Marshal.PtrToStringUTF8(Lib.Close(FileIdx));
23572360
}
23582361

2362+
/// <summary>
2363+
/// Duplicate a worksheet by gave source and target worksheet index.
2364+
/// Note that currently doesn't support duplicate workbooks that contain
2365+
/// tables, charts or pictures.
2366+
/// </summary>
2367+
/// <param name="buffer">The contents buffer of the file</param>
2368+
/// <exception cref="RuntimeError">Return None if no error occurred,
2369+
/// otherwise raise a RuntimeError with the message.</exception>
2370+
public void CopySheet(int from, int to)
2371+
{
2372+
string err = Marshal.PtrToStringUTF8(Lib.CopySheet(FileIdx, from, to));
2373+
if (!string.IsNullOrEmpty(err))
2374+
throw new RuntimeError(err);
2375+
}
2376+
23592377
/// <summary>
23602378
/// Get formatted value from cell by given worksheet name and cell
23612379
/// reference in spreadsheet. The return value is converted to the
2362-
/// 'string' data type. If the cell format can be applied to the value
2363-
/// of a cell, the applied value will be returned, otherwise the
2380+
/// <c>string</c> data type. If the cell format can be applied to the
2381+
/// value of a cell, the applied value will be returned, otherwise the
23642382
/// original value will be returned. All cells' values will be the same
23652383
/// in a merged range.
23662384
/// </summary>

Excelize/TypesC.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public unsafe struct Interface
1919
{
2020
public int Type;
2121
public int Integer;
22+
public int Integer32;
2223
public sbyte* String;
2324
public double Float;
2425

Excelize/TypesCs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public struct Interface
203203
{
204204
public int Type;
205205
public int Integer;
206+
public int Integer32;
206207
public string String;
207208
public double Float;
208209
public bool Boolean;

0 commit comments

Comments
 (0)