题
我正在尝试使用千位分隔符格式化SharePoint中的BDC(业务数据目录)定义中的字段。
在BDC XML定义中似乎不可能,并且只能通过SharePoint Designer(!)实现。我目前得到的字段是System.Decimal,所以它显示为12345.98,但我希望它显示为12,345.98。
您是否知道是否可以通过BDC XML定义实现?
<Parameter Direction="Return" Name="@ContactTotals">
<TypeDescriptor TypeName="System.Data.IDataReader, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" IsCollection="true" Name="Reader">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Data.IDataRecord, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Name="Record">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Int32" IdentifierName="dim_claims_key" Name="dim_claims_key" />
<TypeDescriptor TypeName="System.Decimal" Name="total_outstanding" DefaultDisplayName="Total Outstanding (USD)" />
<TypeDescriptor TypeName="System.Decimal" Name="total_paid" DefaultDisplayName="Total Paid (USD)" />
<TypeDescriptor TypeName="System.Decimal" Name="total_incurred" DefaultDisplayName="Total Incurred (USD)" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
干杯
尼克
解决方案
XML是一种不打算格式化或呈现信息的元语言,它描述和存储其他词汇表。考虑到这一点,答案是:不,你不能只使用XML来实现你所要求的。
推荐的方法是使用XSLT <!> lt; xsl:decimal您正在使用的BDC列表视图或BDC项目视图Web部件中的-format / <!> gt; 元素。如果您通过其他方式使用数据,则可以在渲染过程中轻松格式化输出。
假设您有这部分代码显示您的小数类型:
<xsl:value-of select="$ColName_0" />
您需要使用类似的东西(基于链接中的示例)封装它:
<xsl:value-of select="format-number($ColName_0, '#.###,00', 'euro')"/>
您可以在Modify Shared WebPart菜单中找到webpart的XSLT,或者如您所说,使用SharePoint Designer。
其他提示
似乎可以在 Complex Formatting
=“http://msdn.microsoft.com/en-us/library/ms543392.aspx”rel =“nofollow noreferrer”> TypeDescriptor
元素。由于我没有正确测试此解决方案的环境,因此以下定义似乎是有效的并且可以解决您的特定情况:
<Parameter Direction="Return" Name="@ContactTotals">
<TypeDescriptor TypeName="System.Data.IDataReader, ..."
IsCollection="true" Name="Reader">
<!-- note this -->
<Properties>
<Property Name="ComplexFormatting"
Type="System.String" />
</Properties>
<TypeDescriptors>
<TypeDescriptor TypeName="System.Data.IDataRecord, ..." Name="Record">
<TypeDescriptors>
<TypeDescriptor TypeName="System.Int32"
IdentifierName="dim_claims_key"
Name="dim_claims_key" />
<TypeDescriptor TypeName="System.Decimal"
Name="total_outstanding"
DefaultDisplayName="Total Outstanding (USD)" />
<!-- note this -->
<Properties>
<Property Name="FormatString"
Type="System.String">{0:#.###,00}</Property>
</Properties>
</TypeDescriptor>
...
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
请注意MSDN文档中的警告,"ComplexFormatting is slow"
。也许最好坚持使用 F.Aquino回答
不隶属于 StackOverflow