@@ -410,6 +410,16 @@ internal static extern IntPtr SetCellFormula(
410410 ref TypesC . FormulaOpts opts
411411 ) ;
412412
413+ [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
414+ internal static extern IntPtr SetCellHyperLink (
415+ long fileIdx ,
416+ string sheet ,
417+ string cell ,
418+ string link ,
419+ string linkType ,
420+ ref TypesC . HyperlinkOpts opts
421+ ) ;
422+
413423 [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
414424 internal static extern IntPtr SetCellInt (
415425 long fileIdx ,
@@ -418,6 +428,14 @@ internal static extern IntPtr SetCellInt(
418428 long value
419429 ) ;
420430
431+ [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
432+ internal static extern IntPtr SetCellStr (
433+ long fileIdx ,
434+ [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string sheet ,
435+ [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string cell ,
436+ [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string value
437+ ) ;
438+
421439 [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
422440 internal static extern IntPtr SetCellStyle (
423441 long fileIdx ,
@@ -3473,6 +3491,81 @@ public void SetCellFormula(
34733491 throw new RuntimeError ( err ) ;
34743492 }
34753493
3494+ /// <summary>
3495+ /// SetCellHyperLink provides a function to set cell hyperlink by given
3496+ /// worksheet name and link URL address. LinkType defines three types
3497+ /// of hyperlink <c>External</c> for website or <c>Location</c> for
3498+ /// moving to one of cell in this workbook or <c>None</c> for remove
3499+ /// hyperlink. Maximum limit hyperlinks in a worksheet is 65530. This
3500+ /// function is only used to set the hyperlink of the cell and doesn't
3501+ /// affect the value of the cell. If you need to set the value of the
3502+ /// cell, please use the other functions such as <c>SetCellStyle</c> or
3503+ /// <c>SetSheetRow</c>.
3504+ /// <example>
3505+ /// The below is example for external link:
3506+ /// <code>
3507+ /// string display = "https://github.com/xuri/excelize";
3508+ /// string tooltip = "Excelize on GitHub";
3509+ /// try
3510+ /// {
3511+ /// f.SetCellHyperLink(
3512+ /// "Sheet1",
3513+ /// "A3",
3514+ /// display,
3515+ /// "External",
3516+ /// new HyperlinkOpts { Display = display, Tooltip = tooltip }
3517+ /// );
3518+ /// // Set underline and font color style for the cell.
3519+ /// int style = f.NewStyle(
3520+ /// new Style
3521+ /// {
3522+ /// Font = new Font { Color = "1265BE", Underline = "single" },
3523+ /// }
3524+ /// );
3525+ /// f.SetCellStyle("Sheet1", "A3", "A3", style);
3526+ /// }
3527+ /// catch (RuntimeError err)
3528+ /// {
3529+ /// Console.WriteLine(err.Message);
3530+ /// }
3531+ /// </code>
3532+ /// This is another example for <c>Location</c>:
3533+ /// <code>
3534+ /// try
3535+ /// {
3536+ /// f.SetCellHyperLink("Sheet1", "A3", "Sheet1!A40", "Location");
3537+ /// }
3538+ /// catch (RuntimeError err)
3539+ /// {
3540+ /// Console.WriteLine(err.Message);
3541+ /// }
3542+ /// </code>
3543+ /// </example>
3544+ /// </summary>
3545+ /// <param name="sheet">The worksheet name</param>
3546+ /// <param name="cell">The cell reference</param>
3547+ /// <param name="link">The hyperlink</param>
3548+ /// <param name="linkType">The hyperlink type</param>
3549+ /// <param name="options">The hyperlink options</param>
3550+ /// <exception cref="RuntimeError">Return None if no error occurred,
3551+ /// otherwise raise a RuntimeError with the message.</exception>
3552+ public void SetCellHyperLink (
3553+ string sheet ,
3554+ string cell ,
3555+ string link ,
3556+ string linkType ,
3557+ HyperlinkOpts ? options = null
3558+ )
3559+ {
3560+ var opts = ( TypesC . HyperlinkOpts )
3561+ Lib . CsToC ( options ?? new HyperlinkOpts ( ) , new TypesC . HyperlinkOpts ( ) ) ;
3562+ string err = Marshal . PtrToStringUTF8 (
3563+ Lib . SetCellHyperLink ( FileIdx , sheet , cell , link , linkType , ref opts )
3564+ ) ;
3565+ if ( ! string . IsNullOrEmpty ( err ) )
3566+ throw new RuntimeError ( err ) ;
3567+ }
3568+
34763569 /// <summary>
34773570 /// Set int type value of a cell by given worksheet name, cell reference
34783571 /// and cell value.
@@ -3489,6 +3582,22 @@ public void SetCellInt(string sheet, string cell, long value)
34893582 throw new RuntimeError ( err ) ;
34903583 }
34913584
3585+ /// <summary>
3586+ /// SetCellStr provides a function to set string type value of a cell.
3587+ /// Total number of characters that a cell can contain 32767 characters.
3588+ /// </summary>
3589+ /// <param name="sheet">The worksheet name</param>
3590+ /// <param name="cell">The cell reference</param>
3591+ /// <param name="value">The cell value</param>
3592+ /// <exception cref="RuntimeError">Return None if no error occurred,
3593+ /// otherwise raise a RuntimeError with the message.</exception>
3594+ public void SetCellStr ( string sheet , string cell , string value )
3595+ {
3596+ string err = Marshal . PtrToStringUTF8 ( Lib . SetCellStr ( FileIdx , sheet , cell , value ) ) ;
3597+ if ( ! string . IsNullOrEmpty ( err ) )
3598+ throw new RuntimeError ( err ) ;
3599+ }
3600+
34923601 /// <summary>
34933602 /// Set int type value of a cell by given worksheet name, cell reference
34943603 /// and cell value.
0 commit comments