Search Results for

    Show / Hide Table of Contents

    Getting started with FlexCel and macOS (C# / mac-unified)

    Note

    This demo is available in your FlexCel installation at <FlexCel Install Folder>\samples\csharp\VS2022\mac-unified\GettingStarted and also at https:​//​github.​com/​tmssoftware/​TMS-​FlexCel.​NET-​demos/​tree/​master/​csharp/​VS2022/​mac-​unified/​Getting​Started

    Overview

    The examples in this section apply to FlexCel for macOS.

    We only include a getting started example for macOS. For all the functionality, take a look at the netframework demos.

    Files

    AppDelegate.cs

    using System;
    using System.Drawing;
    using Foundation;
    using AppKit;
    using ObjCRuntime;
    
    namespace GettingStarted
    {
        public partial class AppDelegate : NSApplicationDelegate
        {
            MainWindowController mainWindowController;
    
            public AppDelegate()
            {
            }
    
            public override void DidFinishLaunching (NSNotification notification)
            {
                mainWindowController = new MainWindowController();
                mainWindowController.Window.MakeKeyAndOrderFront(this);
            }
    
            public override bool ApplicationShouldTerminateAfterLastWindowClosed(NSApplication sender)
            {
                return true;
    
            }
        }
    }
    

    AppDelegate.designer.cs

    namespace GettingStarted
    {
        // Should subclass MonoMac.AppKit.NSResponder
        [Foundation.Register("AppDelegate")]
        public partial class AppDelegate
        {
        }
    }
    

    Main.cs

    using System;
    using System.Drawing;
    using Foundation;
    using AppKit;
    using ObjCRuntime;
    
    namespace GettingStarted
    {
        class MainClass
        {
            static void Main(string[] args)
            {
                NSApplication.Init();
                NSApplication.Main(args);
            }
        }
    }    
    

    MainWindow.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Foundation;
    using AppKit;
    
    namespace GettingStarted
    {
        public partial class MainWindow : NSWindow
        {
            #region Constructors
            // Called when created from unmanaged code
            public MainWindow(IntPtr handle) : base (handle)
            {
                Initialize();
            }
            // Called when created directly from a XIB file
            [Export ("initWithCoder:")]
            public MainWindow(NSCoder coder) : base (coder)
            {
                Initialize();
            }
            // Shared initialization code
            void Initialize()
            {
            }
            #endregion
        }
    }
    

    MainWindow.designer.cs

    // WARNING
    //
    // This file has been generated automatically by Xamarin Studio to store outlets and
    // actions made in the UI designer. If it is removed, they will be lost.
    // Manual changes to this file may not be handled correctly.
    //
    using Foundation;
    using System.CodeDom.Compiler;
    
    namespace GettingStarted
    {
       [Register ("MainWindow")]
        partial class MainWindow
        {
    
            void ReleaseDesignerOutlets ()
            {
            }
        }
    
       [Register ("MainWindowController")]
        partial class MainWindowController
        {
           [Action ("CreateFile:")]
            partial void CreateFile (Foundation.NSObject sender);
    
            void ReleaseDesignerOutlets ()
            {
            }
        }
    }
    

    MainWindowController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Foundation;
    using AppKit;
    using FlexCel.XlsAdapter;
    using FlexCel.Core;
    
    namespace GettingStarted
    {
        public partial class MainWindowController : AppKit.NSWindowController
        {
            #region Constructors
            // Called when created from unmanaged code
            public MainWindowController(IntPtr handle) : base (handle)
            {
                Initialize();
            }
            // Called when created directly from a XIB file
            [Export ("initWithCoder:")]
            public MainWindowController(NSCoder coder) : base (coder)
            {
                Initialize();
            }
            // Call to load from the XIB/NIB file
            public MainWindowController() : base ("MainWindow")
            {
                Initialize();
            }
            // Shared initialization code
            void Initialize()
            {
            }
            #endregion
            //strongly typed window accessor
            public new MainWindow Window
            {
                get
                {
                    return (MainWindow)base.Window;
                }
            }
    
            partial void CreateFile(NSObject sender)
            {
                var xls = new XlsFile(1, true);
                xls.SetCellValue(1, 1, "Hello OSX Unified!");
                xls.SetCellValue(2, 1, new TFormula("=\"Make sure to \" & \"look at the Windows examples\""));
                xls.SetCellValue(3, 1, "for information on how to use FlexCel");
                xls.SetCellValue(5, 1, "Concepts are similar, so it doesn't make sense to repeat them all here.");
    
                xls.AutofitCol(1, false, 1.2);
    
                NSSavePanel SaveDialog = new NSSavePanel();
                {
                    SaveDialog.Title = "Save file as...";
                    SaveDialog.AllowedFileTypes = new string[] {"xlsx", "xls"};
                    SaveDialog.BeginSheet(Window, 
                    (x) =>
                    {
                        if (SaveDialog.Url != null)
                        {
                            xls.Save(SaveDialog.Url.Path);
                        }
                    });
                }
    
    
            }
    
        }
    }
    
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com