Вопрос

I have a WPF datagrid that is linked to a database. Some of the text fields are mapped to Nvarchar(255) fields in the database. I need to be able to copy the entire datagrid and paste it in Excel. I am currently using the following code to achieve this:

    Dim VacancyGrid = Me.OMRStocklistsDataGrid
    VacancyGrid.SelectAllCells()
    ApplicationCommands.Copy.Execute(Nothing, VacancyGrid)

This works fine except that when the string / text fields are pasted in Excel (using paste special - csv) they are all 255 characters long. Most of the actual fields only contain 20 or so characters of text and then whitespace is added to make exactly 255 characters.

How can I trim this extra whitespace either in the datagrid or when copying to the clipboard?

Alternatively if there is a better way of achieving a smooth transition from a datagrid to an excel file, that would be great to know.

Thanks very much!

Это было полезно?

Решение

Okay,

The answer is to trim upstream - at the database end. I ended up using a view:

RTRIM (Your field)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top