﻿using System;
using Com.Aspose.Cells.Api;
using Com.Aspose.Cells.Model;
using Com.Aspose.Storage.Api;

namespace Cells
{
    class ApplyRichTextFormatting
    {
        public static void Run()
        {
            // ExStart:1
            CellsApi cellsApi = new CellsApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);
            StorageApi storageApi = new StorageApi(Common.APP_KEY, Common.APP_SID, Common.BASEPATH);

            string fileName = "Book1.xlsx";
            string sheetName = "Sheet1";
            string cellName = "A1";
            string cellValue = "121211212112";
            string type = "string";

            Com.Aspose.Cells.Model.Font font = new Com.Aspose.Cells.Model.Font();
            font.IsBold = true;
            font.Size = 24;

            Com.Aspose.Cells.Model.FontSetting fontSetting = new Com.Aspose.Cells.Model.FontSetting();
            fontSetting.Length = 5;
            fontSetting.StartIndex = 0;
            fontSetting.Font = font;
            string storage = null;
            string folder = null;
            try
            {
                // Upload source file to aspose cloud storage
                storageApi.PutCreate(fileName, "", "", System.IO.File.ReadAllBytes(Common.GetDataDir() + fileName));

                // Invoke Aspose.Cells Cloud SDK API to set cell value of worksheet and apply rich text formatting              
                CellResponse cellResponse = cellsApi.PostWorksheetCellSetValue(fileName, sheetName, cellName, cellValue, type, null, storage, folder);
                SaaSposeResponse apiResponse = cellsApi.PostCellTextFormatting(fileName, sheetName, cellName, fontSetting, storage, folder);

                if (apiResponse != null && apiResponse.Status.Equals("OK"))
                {
                    Console.WriteLine("Apply Rich Text Formatting to a Cell, Done!");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
            }
            // ExEnd:1
        }
    }
}
