原創(chuàng)|其它|編輯:郝浩|2012-07-24 03:45:32.000|閱讀 1773 次
概述:我有一個(gè)第一列為日期列的GridView。它在運(yùn)行時(shí)會(huì)綁定到日期,但他們通過(guò)CustomColumnDisplayText事件定制類(lèi)似下面的季度和全年格式轉(zhuǎn)換的日期
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
問(wèn)題描述:
我有一個(gè)第一列為日期列的GridView。它在運(yùn)行時(shí)會(huì)綁定到日期,但他們通過(guò)CustomColumnDisplayText事件定制類(lèi)似下面的季度和全年格式轉(zhuǎn)換的日期:
[C#]
private void gvwMargin_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
// Change the colDate column for quarter only since there is no built-in format.
if (sDisplayType == Constants.DISPLAYBY_QUARTERLY)
{
if (e.Column.Name == "colDate")
{
DateTime date = Convert.ToDateTime(e.Value);
int quarterNumber = (date.Month - 1) / 3 + 1;
e.DisplayText = string.Format("Q{0} {1}", quarterNumber, date.Year);
}
}
}
然而,當(dāng)我將GridView導(dǎo)出為xls或xlsx格式時(shí),返回綁定到網(wǎng)格的日期列丟失了格式,顯示的是實(shí)際日期。我怎樣才能在將網(wǎng)格導(dǎo)出為xls或xlsx時(shí)自定義日期并保持它?當(dāng)我將網(wǎng)格導(dǎo)出為PDF或HTML格式時(shí)日期似乎并沒(méi)有發(fā)生變化。
問(wèn)題解答:
改變CustomColumnDisplayText只能影響顯示的文字,并不會(huì)改變數(shù)據(jù)源的值。 默認(rèn)情況下,GridControl導(dǎo)出的是數(shù)據(jù)字段值,而不是顯示的文字。為了解決這個(gè)問(wèn)題,您可以將導(dǎo)出數(shù)據(jù)作為一個(gè)字符串,通過(guò)將TextExportMode對(duì)象的XlsExportOptions屬性設(shè)置為文本即可實(shí)現(xiàn)。
[C#]
XlsExportOptions options = new XlsExportOptions();
options.TextExportMode = TextExportMode.Text;
gridControl1.ExportToXls("File.xls", options);
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: