Yes I did try the version you attached. It did not fix my problem with the number format and it did cause the color of the conditional format I set elsewhere in my code to not show.
The previous code when executed by itself does correctly format the numbers but when combined with other style formatting anywhere in the sheet the number formatting does not work. I read in another post something about style flags. Your documentation is not very clear on how to use it but it looks to maintain existing styles when a new style is applied. This may be it but how is it used?
Here is the code I use to apply style and formats to these numbers. I set the range prior to calling this command and pass the range and the workbook to the routine:
private void cmdFormatBody(Workbook wbIMSRpt, Range rngBody)
{
Aspose.Cells.Style bodystyle = wbIMSRpt.Styles[wbIMSRpt.Styles.Add()];
bodystyle.Font.Name = "Verdana";
bodystyle.HorizontalAlignment = TextAlignmentType.Center;
bodystyle.VerticalAlignment = TextAlignmentType.Center;
bodystyle.Font.Size = 10;
bodystyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
bodystyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
bodystyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
bodystyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
rngBody.Style = bodystyle;
// now to handle rank which does not have a decimal place
m_icol = rngBody.FirstColumn;
while (m_icol <= rngBody.ColumnCount)
{
m_iposition = m_oCells[4, m_icol].StringValue.IndexOf("Rank");
if (m_iposition == -1)
{
for (int cr = 5; cr <= rngBody.RowCount; cr++)
{
m_oCell = m_oCells[cr, m_icol];
m_oCell.Style.Custom = "##.0";
}
}
else
{
for (int cr = 5; cr <= rngBody.RowCount; cr++)
{
m_oCell = m_oCells[cr, m_icol];
m_oCell.Style.Custom = "###";
}
}
m_icol++;
}
}
Here is the code I use to conditionally format certain cells in the same range:
if (m_bOppIncluded)
{
//Conditional formatting of Opportunity Column
int index = m_oIMSDataSheet.ConditionalFormattings.Add();
FormatConditions fcs = m_oIMSDataSheet.ConditionalFormattings[index];
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.GreaterOrEqual, "10", "");
FormatCondition fc = fcs[conditionIndex];
m_icol = 0;
while (m_icol < m_inumcols)
{
m_oCell = m_oCells[4, m_icol];
m_iposition = m_oCells[4, m_icol].StringValue.IndexOf("Opportunity");
if (m_iposition != -1)
{
CellArea ca = new CellArea();
ca.StartRow = 5;
ca.EndRow = m_inumrows;
ca.StartColumn = m_icol;
ca.EndColumn = m_icol;
fcs.AddArea(ca);
Color color1 = Color.FromArgb(234, 245, 225);
m_oWBIMSRpt.ChangePalette(color1, 54);
fc.Style.BackgroundColor = color1;
}
m_icol++;
}
}