@@ -363,6 +363,17 @@ internal static extern IntPtr SetSheetProps(
363363 ref TypesC . SheetPropsOptions options
364364 ) ;
365365
366+ [ DllImport (
367+ LibraryName ,
368+ CallingConvention = CallingConvention . Cdecl ,
369+ CharSet = CharSet . Ansi
370+ ) ]
371+ internal static extern IntPtr SetHeaderFooter (
372+ long fileIdx ,
373+ string sheet ,
374+ ref TypesC . HeaderFooterOptions opts
375+ ) ;
376+
366377 [ DllImport (
367378 LibraryName ,
368379 CallingConvention = CallingConvention . Cdecl ,
@@ -2145,6 +2156,48 @@ public void SetSheetProps(string sheet, SheetPropsOptions options)
21452156 throw new RuntimeError ( err ) ;
21462157 }
21472158
2159+ /// <summary>
2160+ /// Set headers and footers by given worksheet name and the control
2161+ /// characters.
2162+ /// <example>
2163+ /// For example:
2164+ /// <code><![CDATA[
2165+ /// try
2166+ /// {
2167+ /// f.SetHeaderFooter(
2168+ /// "Sheet1",
2169+ /// new HeaderFooterOptions
2170+ /// {
2171+ /// DifferentFirst = true,
2172+ /// DifferentOddEven = true,
2173+ /// OddHeader = "&R&P",
2174+ /// OddFooter = "&C&F",
2175+ /// EvenHeader = "&L&P",
2176+ /// EvenFooter = "&L&D&R&T",
2177+ /// FirstHeader = "&CCenter &\"-,Bold\"Bold&\"-,Regular\"HeaderU+000A&D",
2178+ /// }
2179+ /// );
2180+ /// }
2181+ /// catch (RuntimeError err)
2182+ /// {
2183+ /// Console.WriteLine(err.Message);
2184+ /// }]]>
2185+ /// </code>
2186+ /// </example>
2187+ /// </summary>
2188+ /// <param name="sheet">The worksheet name</param>
2189+ /// <param name="options">The header footer options</param>
2190+ /// <exception cref="RuntimeError">Return None if no error occurred,
2191+ /// otherwise raise a RuntimeError with the message.</exception>
2192+ public void SetHeaderFooter ( string sheet , HeaderFooterOptions ? options )
2193+ {
2194+ var opts = ( TypesC . HeaderFooterOptions )
2195+ Lib . CsToC ( options ?? new HeaderFooterOptions ( ) , new TypesC . HeaderFooterOptions ( ) ) ;
2196+ string err = Marshal . PtrToStringAnsi ( Lib . SetHeaderFooter ( FileIdx , sheet , ref opts ) ) ;
2197+ if ( ! string . IsNullOrEmpty ( err ) )
2198+ throw new RuntimeError ( err ) ;
2199+ }
2200+
21482201 /// <summary>
21492202 /// Writes cells to row by given worksheet name, starting cell reference
21502203 /// and cell values list.
0 commit comments