当前位置: 首页>>代码示例>>C#>>正文


C# Aspose.GetCharacters方法代码示例

本文整理汇总了C#中Aspose.GetCharacters方法的典型用法代码示例。如果您正苦于以下问题:C# Aspose.GetCharacters方法的具体用法?C# Aspose.GetCharacters怎么用?C# Aspose.GetCharacters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aspose的用法示例。


在下文中一共展示了Aspose.GetCharacters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTextFromCell

        /// <summary>
        /// Get text with formating from Excel cell
        /// </summary>
        /// <param name="cell">Input Excel cell</param>
        /// <param name="doc">Parent document</param>
        /// <returns>Run that contains text with formating</returns>
        private ArrayList GetTextFromCell(Aspose.Cells.Cell cell, Document doc)
        {
            //Create new array list
            //We will store runs in this list
            ArrayList wordRuns = new ArrayList();

            //Get Chracters objects from the cell
            FontSetting[] charactersList = cell.GetCharacters();
            if (charactersList == null)
                charactersList = new FontSetting[0];

            //Get sring value from the cell
            string cellValue = cell.StringValue;

            //If there is some formatig in the cell
            //charactersList will contains one or more Characters objects
            //And we should create collection of Runs that will represent this formating
            if (charactersList.Length > 0)
            {
                int startIndex = ((FontSetting)charactersList[0]).StartIndex;
                if (startIndex > 0)
                {
                    //Create first run
                    Run firstRun = new Run(doc);
                    //Set text of first run. That will be substring that starts from 0
                    //And ens and the start position of first Characters object

                    //Sometimes Aspose.Cell returns incorrect index so we should check it
                    if (startIndex < cellValue.Length)
                        firstRun.Text = cellValue.Substring(0, startIndex);
                    else
                        firstRun.Text = cellValue.Substring(0);
                    //Formation of first run will be the same as formating of whole cell
                    ImportFont(firstRun.Font, cell.GetDisplayStyle().Font);
                    wordRuns.Add(firstRun);
                }

                //Loop through all Character objects
                foreach (FontSetting chars in charactersList)
                {
                    Run run = new Run(doc);
                    //We should check index to avoid errors
                    if (chars.StartIndex < cellValue.Length)
                    {
                        if (cellValue.Length > (chars.StartIndex + chars.Length) && chars.Length > 0)
                            run.Text = cellValue.Substring(chars.StartIndex, chars.Length);
                        else
                            run.Text = cellValue.Substring(chars.StartIndex);
                    }
                    //Convert Excel Font to Words Font
                    ImportFont(run.Font, chars.Font);
                    wordRuns.Add(run);
                }
            }
            //Othervice there will be only one run
            else
            {
                Run run = new Run(doc);
                run.Text = cellValue;
                //Convert Excel Font to Words Font
                ImportFont(run.Font, cell.GetDisplayStyle().Font);
                wordRuns.Add(run);
            }

            return wordRuns;
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:72,代码来源:ConverterXls2Doc.cs


注:本文中的Aspose.GetCharacters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。