2016-10-07 20 views
1

是否有可能導出ASPxGridView與包含多行文本使用ASPxGridViewExporter優秀的列?導出ASPxGridView與多行文本的列excel

我有一個ASPxGridView列包含多行文本。 當我使用ASPxGridViewExporter將多行文本呈現爲一行(不換行)時導出網格數據。

我試過< br/>和「\ n」(換行符)作爲行分隔符。

btw屬性PropertiesTextEdit-EncodeHtml的值在該列上爲false。

感謝

回答

1

有2種方式來實現你在找什麼:

  1. 在XlsxExportOptionsEx指定所見即所得的出口類型:

    XlsxExportOptionsEx options = new XlsxExportOptionsEx() 
    { 
        ExportType = DevExpress.Export.ExportType.WYSIWYG 
    }; 
    ASPxGridView1.ExportToXlsx("Test.xlsx", options); 
    
  2. 告訴你想要的出口國有數據意識導出並處理CustomizeCell事件以將單元格換行設置爲true:

    XlsxExportOptionsEx options = new XlsxExportOptionsEx() 
    { 
        ExportType = DevExpress.Export.ExportType.DataAware 
    }; 
    
    options.CustomizeCell += options_CustomizeCell; 
    
    void options_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs e) 
    { 
        e.Formatting.Alignment = new XlCellAlignment() { WrapText = true }; 
        e.Handled = true;  
    } 
    

    然後使用自定義的選項對象進行導出。

參見:https://www.devexpress.com/Support/Center/Question/Details/T381176

還有有時可能是有益的RenderBrick事件。你可以處理它喜歡:

gveExporter.RenderBrick += gveExporter_RenderBrick; 

void gveExporter_RenderBrick(object sender, DevExpress.Web.ASPxGridViewExportRenderingEventArgs e) 
{ 
    ... 
    StringFormat sFormat = new StringFormat(StringFormatFlags.NoWrap); 
    BrickStringFormat brickSFormat = new BrickStringFormat(sFormat); 
    e.BrickStyle.StringFormat = brickSFormat; 
    ... 
} 

但我還沒有找到如何真正迫使細胞包裹在那裏,因爲StringFormatFlags只有適合項目中NoWrap的。根據我的經驗,我確實在導出的Excel文檔中使用了單元格換行,因此我使用RenderBrick來切換換行。

希望有所幫助。

+0

適合我。謝謝。 – Yuriy