This is my code to export to excel .But in this code while i press export button then it will export the excel,and shows a message as it is saved ,but it is not opening automatically by the code given ,instead os that it shows file cannot be find.How can i fix it?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using Telerik.WinControls;
using System.IO;
using System.Collections.Specialized;
using System.Web;
using Telerik.WinControls.UI;
using System.Reflection;
using Telerik.WinControls.Export;
using Telerik.WinControls.UI.Export;
using Telerik.WinControls.Data;
namespace Export2html_pdf_excel
{
public partial class ExportForm : Telerik.WinControls.UI.RadForm
{
SaveFileDialog save = new SaveFileDialog();
public ExportForm()
{
InitializeComponent();
}
private void RadForm1_Load(object sender, EventArgs e)
{
try
{
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("server=QB_DT_2\\sqlexpress;database=nikeho;user id=sa;password=admin123");
SqlDataAdapter sda = new SqlDataAdapter("select top 1000 * from idtable", con);
sda.Fill(dt);
GridView.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private void radRadioButtonExport_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (this.RBtnExcel.IsChecked)
{
save.Filter = "Excel (*.xls)|*.xls";
}
}
private void Export_Click(object sender, EventArgs e)
{
if (save.ShowDialog() != DialogResult.OK)
{
return;
}
if (save.FileName.Equals(String.Empty))
{
RadMessageBox.SetThemeName(this.GridView.ThemeName);
RadMessageBox.Show("Please enter a file name.");
return;
}
string fileName = this.save.FileName;
bool openExportFile = false;
if (this.RBtnExcel.IsChecked)
{
RunExportToExcel(fileName, ref openExportFile);
}
if (openExportFile==true)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch (Exception ex)
{
string message = String.Format("The file cannot be opened on your system.\nError message: {0}", ex.Message);
RadMessageBox.Show(message, "Open File", MessageBoxButtons.OK, RadMessageIcon.Error);
}
}
}
private void RunExportToExcel(string fileName, ref bool openExportFile)
{
ExportToExcelML excelExporter = new ExportToExcelML(this.GridView);
try
{
this.Cursor = Cursors.WaitCursor;
excelExporter.RunExport(fileName);
RadMessageBox.SetThemeName(this.GridView.ThemeName);
DialogResult dr = RadMessageBox.Show("The data in the grid was exported successfully. Do you want to open the file?", "Export to Excel", MessageBoxButtons.YesNo, RadMessageIcon.Question);
if (dr == DialogResult.Yes)
{
openExportFile = true;
//System.Diagnostics.Process.Start(fileName);
}
}
catch (IOException ex)
{
RadMessageBox.SetThemeName(this.GridView.ThemeName);
RadMessageBox.Show(this, ex.Message, "I/O Error", MessageBoxButtons.OK, RadMessageIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
hi,
I have a grid view which has a grouping, I want to have a button within the group, is it possible, the image has been attached & I want a button next to
"Rule Name :Galaxy"
Thanks
Regards
Ramraj
Don't know if this has been mentioned before but I'll share my solution anyway.
The issue is when you use the ExportToML on a RadGridView and the resulting excel-file gives you the little green triangle on every cell. Where it says "the number in the cell is formatted as text or preceded by an apostrophe". The yellow mark gives you the option to "convert to number" before you can use the values as expected. Highly annoying if you ask me.
Solution
If you google this you get the standard solution of using ExcelCellFormatting event and change
the property of:
This however doesn't solve the problem. The solution is not the visual style export, but in the data.
var exporter =
new
ExportToExcelML(grid) {SheetName = sheetname, ExportVisualSettings =
true
};
exporter.ExcelCellFormatting += exporter_ExcelCellFormatting;
exporter.RunExport(tempPath);
private
static
void
exporter_ExcelCellFormatting(
object
sender, ExcelCellFormattingEventArgs e)
{
if
(!e.GridCellInfo.ColumnInfo.Name.StartsWith(
"v."
))
return
;
if
(e.GridCellInfo.Value ==
null
)
return
;
e.ExcelStyleElement.NumberFormat.FormatType = DisplayFormatType.Custom;
e.ExcelStyleElement.NumberFormat.FormatString =
"#"
;
int
old;
if
(
int
.TryParse(e.GridCellInfo.Value.ToString().Replace(
","
,
""
),
out
old))
{
e.ExcelCellElement.Data.DataType = DataType.Number;
e.ExcelCellElement.Data.DataItem = old;
}
}
Hi
I have a grid view in which it has a combo box in some cell
& i can select multiple rows,now my query is that is there any way that when i select multiple row & then change the combo box value of one row it should automatically set the value of combo box to all the row which are selected through multiple option.
Thanks
Regards
Ramraj Gupta
So far the only way I've been able to hide them is by setting the radPivotGrid.ColumnHeaderHeight = 0
Is there a cleaner way to hide/remove them?​
is there en example existing for drag and drop operation between 2 RadTreeviews, but not with a move , but Copy operation.
How do I change the border color on a radSplitButton? I'm using
btnUser.DropDownButtonElement.ButtonSeparator.BorderColor = Color.FromArgb(255, 190, 106)
btnUser.DropDownButtonElement.ActionButton.BorderElement.ForeColor = Color.FromArgb(255, 190, 106)
but it only changes part of the border color. The left and right borders are unchanged.
Why do these two properties seems to conflict. I want to store an object in .Value and display a simple String in .Text, but it seems I can't do this...
The last one set always overrides the other.