We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word Cell BackgroundPatternColor issue


I am facing once issue while converting an excel cell to word cell using Aspose.

Issue is like, i have an Excel Content that contains “one cell with Background Color = Black”. . I want to get actual BackgroundColor of cell which is there in Excel Content.

Sample Code:

//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 word cell backgroundPatternColor
wordsCell.CellFormat.Shading.BackgroundPatternColor = excelCell.GetStyle().BackgroundColor;

The above line is not giving the actual Cell’s BackgroungColor that is Black, Giving White by default always, which is wrong.


Hi Lakshmi,

Thanks for your query. Please use the following code snippet to change the background color of table’s cell in doc file after getting the color of Excel cell.

<!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Cordia New"; mso-bidi-theme-font:minor-bidi;}


//Instantiating a Workbook object
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(MyDir + "ExceltoWord.xls");

//Obtaining the reference of the newly added worksheet by passing its sheet index
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];

Document doc = new Document(MyDir + "Table.EmptyTable.doc");

Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);

Aspose.Words.Tables.Cell wordsCell = table.Rows[0].Cells[0];

//Get Excel cell from collection=
Aspose.Cells.Cell excelCell = worksheet.Cells["A1"];

// set word cell backgroundPatternColor
wordsCell.CellFormat.Shading.BackgroundPatternColor = excelCell.GetStyle().ForegroundColor;// Color.FromArgb(r, g, b);

doc.Save(MyDir + "TableOut.doc", Aspose.Words.SaveFormat.Doc);

Hi Tahir Manzoor,

Thanks for your reply.

But, Still…
always excelCell.GetStyle().ForegroundColor is returning value as “{Name=0, ARGB=(0, 0, 0, 0)}” . Which is not expected (Expected is BLACK).

Note: With this change for all other colors as backgoundcolor is working fine, except BLACK as backgoundcolor.


Hi Lakshmi,

Thanks for your inquiry. You need to change color of
worksheet.Cells["A1"]as black or use this code snippet to change the background color:
wordsCell.CellFormat.Shading.BackgroundPatternColor = Color.Black;

Hello Imran Rafique,

In my requirement, BackgroundColor of worksheet.Cells[“A1”] cell is BLACK only, no need to set explicitly. Now i need to get this cell background Color and then set. How???

But this Cell
BackgroundColor value is coming as “{Name=0, ARGB=(0, 0, 0, 0)}” with excelCell.GetStyle().ForegroundColor ALWAYS…


Hi Lakshmi,

Thanks for your inquiry. I am transferring your thread to Aspose.Cells forum. Please make sure that you are using latest Aspose.Cells & Aspose.Words.

Sorry for inconvenience.

Follow up the links to get latest dlls.

Hi Lakshmi,

I have tested your scenario and it works fine. Please always use Style.ForegroundColor property instead of Style.BackgroundColor attribute if your underlined cell shading color is solid fill. For your knowledge, the Foreground color is the cell’s outline color and Background color is the back color of the cell. But, keeping in mind, if you want to set/get cell’s shading color with solid fill/pattern type, you will use ForegroundColor setter/getter. There is no need to use Background color then that would be only useful if there is no solid/null background pattern type set for the cell.
For complete reference, see a topic:

I have tested the scenario with a simple Excel file (attached) that contains black color in A1 cell (sheet1) as a solid fill. I have attached the template Excel file here and here is my sample code.

For your information, rgb (0,0,0) is black color, which is I am getting, so it works fine here, I am using our latest version/fix v7.0.4.x:

Sample code:
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(“e:\test2\backclr.xlsx”);
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
//Get Excel cell from collection=
Aspose.Cells.Cell excelCell = worksheet.Cells[“A1”];
Style cellStyle = excelCell.GetStyle();
MessageBox.Show(cellStyle.ForegroundColor.R.ToString()); //0
MessageBox.Show(cellStyle.ForegroundColor.G.ToString()); //0
MessageBox.Show(cellStyle.ForegroundColor.B.ToString()); //0

// It works fine as RGB (0,0,0) is black color, you may check it opening the Excel file into MS Excel.

Thank you.