@@ -401,6 +401,16 @@ internal static extern IntPtr SetCellDefault(
401401 string value
402402 ) ;
403403
404+ [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
405+ internal static extern IntPtr SetCellFloat (
406+ long fileIdx ,
407+ string sheet ,
408+ string cell ,
409+ double value ,
410+ long precision ,
411+ long bitSize
412+ ) ;
413+
404414 [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
405415 internal static extern IntPtr SetCellFormula (
406416 long fileIdx ,
@@ -428,6 +438,15 @@ internal static extern IntPtr SetCellInt(
428438 long value
429439 ) ;
430440
441+ [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
442+ internal static extern IntPtr SetCellRichText (
443+ long fileIdx ,
444+ [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string sheet ,
445+ [ MarshalAs ( UnmanagedType . LPUTF8Str ) ] string cell ,
446+ [ In , MarshalAs ( UnmanagedType . LPArray ) ] TypesC . RichTextRun [ ] options ,
447+ long length
448+ ) ;
449+
431450 [ DllImport ( LibraryName , CallingConvention = CallingConvention . Cdecl ) ]
432451 internal static extern IntPtr SetCellStr (
433452 long fileIdx ,
@@ -3314,6 +3333,35 @@ public void SetCellDefault(string sheet, string cell, string value)
33143333 throw new RuntimeError ( err ) ;
33153334 }
33163335
3336+ /// <summary>
3337+ /// SetCellFloat sets a floating point value into a cell. The precision
3338+ /// parameter specifies how many places after the decimal will be shown
3339+ /// while -1 is a special value that will use as many decimal places as
3340+ /// necessary to represent the number. bitSize is 32 or 64 depending on
3341+ /// if a float32 or float64 was originally used for the value.
3342+ /// </summary>
3343+ /// <param name="sheet">The worksheet name</param>
3344+ /// <param name="cell">The cell reference</param>
3345+ /// <param name="value">The cell value</param>
3346+ /// <param name="precision">The cell value precision</param>
3347+ /// <param name="bitSize">The cell value bit size</param>
3348+ /// <exception cref="RuntimeError">Return None if no error occurred,
3349+ /// otherwise raise a RuntimeError with the message.</exception>
3350+ public void SetCellFloat (
3351+ string sheet ,
3352+ string cell ,
3353+ double value ,
3354+ int precision ,
3355+ int bitSize
3356+ )
3357+ {
3358+ string err = Marshal . PtrToStringUTF8 (
3359+ Lib . SetCellFloat ( FileIdx , sheet , cell , value , precision , bitSize )
3360+ ) ;
3361+ if ( ! string . IsNullOrEmpty ( err ) )
3362+ throw new RuntimeError ( err ) ;
3363+ }
3364+
33173365 /// <summary>
33183366 /// SetCellFormula provides a function to set formula on the cell is
33193367 /// taken according to the given worksheet name and cell formula
@@ -3582,6 +3630,166 @@ public void SetCellInt(string sheet, string cell, long value)
35823630 throw new RuntimeError ( err ) ;
35833631 }
35843632
3633+ /// <summary>
3634+ /// SetCellRichText provides a function to set cell with rich text by
3635+ /// given worksheet name, cell reference and rich text runs.
3636+ /// <example>
3637+ /// For example, set rich text on the A1 cell of the worksheet named
3638+ /// Sheet1:
3639+ /// <code>
3640+ /// using ExcelizeCs;
3641+ ///
3642+ /// class Program
3643+ /// {
3644+ /// static void Main()
3645+ /// {
3646+ /// ExcelizeCs.File f = Excelize.NewFile();
3647+ /// try
3648+ /// {
3649+ /// f.SetCellRichText(
3650+ /// "Sheet1",
3651+ /// "A1",
3652+ /// new RichTextRun[]
3653+ /// {
3654+ /// new RichTextRun
3655+ /// {
3656+ /// Text = "bold",
3657+ /// Font = new Font
3658+ /// {
3659+ /// Bold = true,
3660+ /// Color = "2354E8",
3661+ /// Family = "Times New Roman",
3662+ /// },
3663+ /// },
3664+ /// new RichTextRun
3665+ /// {
3666+ /// Text = " and ",
3667+ /// Font = new Font
3668+ /// {
3669+ /// Family = "Times New Roman",
3670+ /// },
3671+ /// },
3672+ /// new RichTextRun
3673+ /// {
3674+ /// Text = "italic ",
3675+ /// Font = new Font
3676+ /// {
3677+ /// Bold = true,
3678+ /// Color = "E83723",
3679+ /// Italic = true,
3680+ /// Family = "Times New Roman",
3681+ /// },
3682+ /// },
3683+ /// new RichTextRun
3684+ /// {
3685+ /// Text = "text with color and font-family,",
3686+ /// Font = new Font
3687+ /// {
3688+ /// Bold = true,
3689+ /// Color = "2354E8",
3690+ /// Family = "Times New Roman",
3691+ /// },
3692+ /// },
3693+ /// new RichTextRun
3694+ /// {
3695+ /// Text = "\r\nlarge text with ",
3696+ /// Font = new Font
3697+ /// {
3698+ /// Size = 14,
3699+ /// Color = "AD23E8",
3700+ /// },
3701+ /// },
3702+ /// new RichTextRun
3703+ /// {
3704+ /// Text = "strike",
3705+ /// Font = new Font
3706+ /// {
3707+ /// Color = "E89923",
3708+ /// Strike = true,
3709+ /// },
3710+ /// },
3711+ /// new RichTextRun
3712+ /// {
3713+ /// Text = " superscript",
3714+ /// Font = new Font
3715+ /// {
3716+ /// Color = "DBC21F",
3717+ /// VertAlign = "superscript",
3718+ /// },
3719+ /// },
3720+ /// new RichTextRun
3721+ /// {
3722+ /// Text = " and ",
3723+ /// Font = new Font
3724+ /// {
3725+ /// Size = 14,
3726+ /// Color = "AD23E8",
3727+ /// VertAlign = "baseline",
3728+ /// },
3729+ /// },
3730+ /// new RichTextRun
3731+ /// {
3732+ /// Text = "underline",
3733+ /// Font = new Font
3734+ /// {
3735+ /// Color = "23E833",
3736+ /// Underline = "single",
3737+ /// },
3738+ /// },
3739+ /// new RichTextRun
3740+ /// {
3741+ /// Text = " subscript.",
3742+ /// Font = new Font
3743+ /// {
3744+ /// Color = "017505",
3745+ /// VertAlign = "subscript",
3746+ /// },
3747+ /// },
3748+ /// }
3749+ /// );
3750+ /// int style = f.NewStyle(
3751+ /// new Style
3752+ /// {
3753+ /// Alignment = new Alignment { WrapText = true },
3754+ /// }
3755+ /// );
3756+ /// f.SetCellStyle("Sheet1", "A1", "A1", style);
3757+ /// f.SaveAs("Book1.xlsx");
3758+ /// }
3759+ /// catch (RuntimeError err)
3760+ /// {
3761+ /// Console.WriteLine(err.Message);
3762+ /// }
3763+ /// finally
3764+ /// {
3765+ /// string err = f.Close();
3766+ /// if (!string.IsNullOrEmpty(err))
3767+ /// Console.WriteLine(err);
3768+ /// }
3769+ /// }
3770+ /// }
3771+ /// </code>
3772+ /// </example>
3773+ /// </summary>
3774+ /// <param name="sheet">The worksheet name</param>
3775+ /// <param name="cell">The cell reference</param>
3776+ /// <param name="runs">The rich text runs</param>
3777+ /// <exception cref="RuntimeError">Return None if no error occurred,
3778+ /// otherwise raise a RuntimeError with the message.</exception>
3779+ public void SetCellRichText ( string sheet , string cell , RichTextRun [ ] runs )
3780+ {
3781+ TypesC . RichTextRun [ ] arr = new TypesC . RichTextRun [ runs . Length ] ;
3782+ for ( int i = 0 ; i < runs . Length ; i ++ )
3783+ {
3784+ arr [ i ] = ( TypesC . RichTextRun ) Lib . CsToC ( runs [ i ] , new TypesC . RichTextRun ( ) ) ;
3785+ }
3786+ string err = Marshal . PtrToStringUTF8 (
3787+ Lib . SetCellRichText ( FileIdx , sheet , cell , arr , arr . Length )
3788+ ) ;
3789+ if ( ! string . IsNullOrEmpty ( err ) )
3790+ throw new RuntimeError ( err ) ;
3791+ }
3792+
35853793 /// <summary>
35863794 /// SetCellStr provides a function to set string type value of a cell.
35873795 /// Total number of characters that a cell can contain 32767 characters.
0 commit comments