TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Santhosh
NA
154
2.5k
How to set column width when export datagrid to excel in wpf
May 15 2017 10:05 AM
private void Export_Click(object sender, RoutedEventArgs e)
{
ExportToExcel();
}
private void ExportToExcel()
{
datagrid10.SelectAllCells();
datagrid10.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, datagrid10);
String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
String result = (string)Clipboard.GetData(DataFormats.Text);
datagrid10.UnselectAllCells();
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Santhosh\Desktop\Exportdata.xls");
file.WriteLine(result.Replace(',', ' '));
file.Close();
MessageBox.Show(" Exporting DataBase to Excel file created", "Infromation", MessageBoxButton.OK, MessageBoxImage.Information);
}
This is my code
when i excute excel is created but in excel file columns are smaller and date format is in #### when i expand it then it will show correct date fromat.
How to set column width to excel sheet when i'm export.
Reply
Answers (
2
)
json not saving large amount of data to server
How to display the number row records in sql to textbox?