/// <summary> /// Convert Excel Cell to Word Cell /// </summary> /// <param name="doc">Parent document</param> /// <param name="cells">Excel cells collection</param> /// <param name="rowIndex">Row index</param> /// <param name="columnIndex">Column index</param> /// <returns>Word Cell</returns> private Aspose.Words.Tables.Cell ImportExcelCell(Document doc, Aspose.Cells.Cells cells, int rowIndex, int columnIndex) { //Create a new Word Cell Aspose.Words.Tables.Cell wordsCell = new Aspose.Words.Tables.Cell(doc); //Get Excel cell from collection Aspose.Cells.Cell excelCell = cells[rowIndex, columnIndex]; //Set cell width double cellWidth = ConvertUtil.PixelToPoint(cells.GetColumnWidthPixel(columnIndex)); wordsCell.CellFormat.PreferredWidth = PreferredWidth.FromPoints(cellWidth); wordsCell.CellFormat.Width = ConvertUtil.PixelToPoint(cellWidth); //Set background color wordsCell.CellFormat.Shading.ForegroundPatternColor = excelCell.GetDisplayStyle().ForegroundColor; wordsCell.CellFormat.Shading.BackgroundPatternColor = excelCell.GetDisplayStyle().BackgroundColor; //Set background texture wordsCell.CellFormat.Shading.Texture = ConvertBackgroundTexture(excelCell.GetDisplayStyle().Pattern); //Import borders from Excel cell to Word cell ImportBorders(wordsCell, excelCell); //Set vertical alignment wordsCell.CellFormat.VerticalAlignment = ConvertVerticalAlignment(excelCell.GetDisplayStyle().VerticalAlignment); //If Excel cells is merged then merge cells in Word Table wordsCell.CellFormat.VerticalMerge = ConvertVerticalCellMerge(excelCell); wordsCell.CellFormat.HorizontalMerge = ConvertHorizontalCellMerge(excelCell); //Create paragraph that will containc content of cell Paragraph wordsParagraph = new Paragraph(doc); //Set horizontal alignment wordsParagraph.ParagraphFormat.Alignment = ConvertHorizontalAlignment(excelCell.GetDisplayStyle().HorizontalAlignment); //Get text with formating from Excel cell as collection Run ArrayList wordRuns = GetTextFromCell(excelCell, doc); foreach (Run run in wordRuns) { wordsParagraph.AppendChild(run); } //Import formating of the cell ImportFont(wordsParagraph.ParagraphBreakFont, excelCell.GetDisplayStyle().Font); //Insert paragrahp with content into cell wordsCell.AppendChild(wordsParagraph); //If Excel cell contains drawing object then convert this object and insert into Word cell InsertDrawingObject(excelCell, wordsCell); return wordsCell; }