/// <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; }