This question is locked. New answers and comments are not allowed.
Hello.
I am developing some application that export contents of RadGridView using "GridViewExportOptions".
Below are my custom method.
public class ExcelHelper
{
public static void ExcelExport(RadGridView gridView)
{
if (gridView != null)
{
gridView.ElementExporting -= ElementExporting;
gridView.ElementExporting += ElementExporting;
ExportFormat format = ExportFormat.Html;
string extension = "xls";
format = ExportFormat.ExcelML;
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = extension;
dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "ExcelML");
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == true)
{
using (Stream stream = dialog.OpenFile())
{
GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters = true;
exportOptions.ShowColumnHeaders = true;
exportOptions.ShowGroupFooters = true;
gridView.Export(stream, exportOptions);
}
}
}
}
}
This method works well usually but sometimes doesn't. The problem is <, > chars in the cell.
// Initialize Class
this._users = new List<Users>();
// Create User 1
_user = new Users();
// Assign Values
_user.FirstName = "Bill";
_user.Surname = "Clinton";
_user.Username = "BillC";
// Add User
this._users.Add(this._user);
// Create User 2
_user = new Users();
// Assign Values
_user.FirstName = "George";
_user.Surname = "Bush";
_user.Username = "GeorgeB";
// Add User
this._users.Add(this._user);
// Create User 3
_user = new Users();
// Assign Values
_user.FirstName = "Baracka";
_user.Surname = "Obama";
_user.Username = "<BarackO>"; //This is the reason of Excel open error.
// Add User
this._users.Add(this._user);
// Assign Items
this.grdList.ItemsSource = this._users;
User 1, 2 is ok, but 3rd user has name that contains <xxx>.
In this case, Excel file is made but couldn't be open.
What can be the best solution for this case?
I am developing some application that export contents of RadGridView using "GridViewExportOptions".
Below are my custom method.
public class ExcelHelper
{
public static void ExcelExport(RadGridView gridView)
{
if (gridView != null)
{
gridView.ElementExporting -= ElementExporting;
gridView.ElementExporting += ElementExporting;
ExportFormat format = ExportFormat.Html;
string extension = "xls";
format = ExportFormat.ExcelML;
SaveFileDialog dialog = new SaveFileDialog();
dialog.DefaultExt = extension;
dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "ExcelML");
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == true)
{
using (Stream stream = dialog.OpenFile())
{
GridViewExportOptions exportOptions = new GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters = true;
exportOptions.ShowColumnHeaders = true;
exportOptions.ShowGroupFooters = true;
gridView.Export(stream, exportOptions);
}
}
}
}
}
This method works well usually but sometimes doesn't. The problem is <, > chars in the cell.
// Initialize Class
this._users = new List<Users>();
// Create User 1
_user = new Users();
// Assign Values
_user.FirstName = "Bill";
_user.Surname = "Clinton";
_user.Username = "BillC";
// Add User
this._users.Add(this._user);
// Create User 2
_user = new Users();
// Assign Values
_user.FirstName = "George";
_user.Surname = "Bush";
_user.Username = "GeorgeB";
// Add User
this._users.Add(this._user);
// Create User 3
_user = new Users();
// Assign Values
_user.FirstName = "Baracka";
_user.Surname = "Obama";
_user.Username = "<BarackO>"; //This is the reason of Excel open error.
// Add User
this._users.Add(this._user);
// Assign Items
this.grdList.ItemsSource = this._users;
User 1, 2 is ok, but 3rd user has name that contains <xxx>.
In this case, Excel file is made but couldn't be open.
What can be the best solution for this case?