コード例 #1
0
        /// <summary>
        /// Import boreders from Excel cell to Word Cell
        /// </summary>
        /// <param name="wordsCell">Destination Word cell</param>
        /// <param name="excelCell">Source Excel cell</param>
        private void ImportBorders(Aspose.Words.Tables.Cell wordsCell, Aspose.Cells.Cell excelCell)
        {
            //Set line style
            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Bottom].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle);
            //Set line color
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Bottom].LineStyle != LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Bottom].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.BottomBorder].Color;

            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalDown].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.DiagonalDown].LineStyle);
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalDown].LineStyle!= LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalDown].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.DiagonalDown].Color;

            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalUp].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.DiagonalUp].LineStyle);
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalUp].LineStyle!= LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.DiagonalUp].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.DiagonalUp].Color;

            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Left].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle);
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Left].LineStyle != LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Left].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.LeftBorder].Color;

            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Right].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.RightBorder].LineStyle);
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Right].LineStyle != LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Right].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.RightBorder].Color;

            wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle = ConvertLineStyle(excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.TopBorder].LineStyle);
            if (wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle != LineStyle.None)
                wordsCell.CellFormat.Borders[Aspose.Words.BorderType.Top].Color = excelCell.GetDisplayStyle().Borders[Aspose.Cells.BorderType.TopBorder].Color;
        }
コード例 #2
0
        /// <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;
        }