XtraReports以编程方式导入Excel格式单元格

当使用Designer时,我可以编辑单元格的XlsxFormatString属性为“#,## 0.00”,结果如预期。 当我尝试以编程的方式做到这一点,没有什么改变:

private XRTableCell CreateCell(int width, string text, bool haveColor, string color, bool isBold, DevExpress.XtraPrinting.BorderSide border, bool IsNumeric) { //MyWorkaround if (IsNumeric) { if (text.Contains(",")) { if (text.Length > text.IndexOf(',') + 3) text = text.Remove(text.IndexOf(',') + 3); } } //MyWorkaround end XRTableCell cell = CreateCell(width, text, haveColor, color, isBold); cell.Borders = border; if (IsNumeric) cell.XlsxFormatString = "#,##0.00"; return cell; } 

任何build议,使其正确?

经过对Devexpress Documents的一些研究,经过几十次尝试之后,我通过了这个解决scheme。

  1. 如果输出不会用于某些计算:

     XtraReport myReport = new XtraReport(); myReport.ExportOptions.Xls.TextExportMode = TextExportMode.Text; myReport.ExportOptions.Xlsx.TextExportMode = TextExportMode.Text; 
  2. 如果输出单元types由于某种原因而重要:

     float myTextValue; if (float.TryParse(textToPrint,out myValue)) { string decSeperator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; if (text.Contains(decSeperator)) { if (textToPrint.Length > textToPrint.IndexOf(decSeperator[0]) + 3) textToPrint= textToPrint.Remove(textToPrint.IndexOf(decSeperator[0]) + 3); } } 

如果可以在文本中find分隔符,这将在2位数后修剪。 如果最后一位数字高于5位,则可以更改为圆形

XtraReports导出工具将已经找出文本是否编号,它会设置单元格types本身

如果有人find更好的解决scheme,请随时沟通。