DevExpress Grid Export to Excel ,Pdf,Html
Aşağıdaki kod bloğuyla Gridde bulunan değerlerimizi Excel,Pdf ve Html formatına Export edebiliriz.
void mnuExportTable()
{
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
if (saveDialog.ShowDialog() != DialogResult.Cancel)
{
string exportFilePath = saveDialog.FileName;
string fileExtenstion = new FileInfo(exportFilePath).Extension;
switch (fileExtenstion)
{
case ".xls":
gridControl1.ExportToXls(exportFilePath);
break;
case ".xlsx":
gridControl1.ExportToXlsx(exportFilePath);
break;
case ".rtf":
gridControl1.ExportToRtf(exportFilePath);
break;
case ".pdf":
gridControl1.ExportToPdf(exportFilePath);
break;
case ".html":
gridControl1.ExportToHtml(exportFilePath);
break;
case ".mht":
gridControl1.ExportToMht(exportFilePath);
break;
default:
break;
}
if (File.Exists(exportFilePath))
{
try
{
//Try to open the file and let windows decide how to open it.
System.Diagnostics.Process.Start(exportFilePath);
}
catch
{
String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
void mnuExportTable()
{
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
if (saveDialog.ShowDialog() != DialogResult.Cancel)
{
string exportFilePath = saveDialog.FileName;
string fileExtenstion = new FileInfo(exportFilePath).Extension;
switch (fileExtenstion)
{
case ".xls":
gridControl1.ExportToXls(exportFilePath);
break;
case ".xlsx":
gridControl1.ExportToXlsx(exportFilePath);
break;
case ".rtf":
gridControl1.ExportToRtf(exportFilePath);
break;
case ".pdf":
gridControl1.ExportToPdf(exportFilePath);
break;
case ".html":
gridControl1.ExportToHtml(exportFilePath);
break;
case ".mht":
gridControl1.ExportToMht(exportFilePath);
break;
default:
break;
}
if (File.Exists(exportFilePath))
{
try
{
//Try to open the file and let windows decide how to open it.
System.Diagnostics.Process.Start(exportFilePath);
}
catch
{
String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Merhaba bu methotda veriler dosyalara akıyor ancak excelde benmi bir sıokıntım var. Kolonun biri kısa tarih diğeri saat excel'de tüm text ve tarih gelir iken saat verisi gelmiyor ancak bunu pdf aktar yaptığım tüm veriler yerli yerine oturuyor. Sorun neden olabilir?
YanıtlaSilMerhaba bu methotda veriler dosyalara akıyor ancak excelde benmi bir sıokıntım var. Kolonun biri kısa tarih diğeri saat excel'de tüm text ve tarih gelir iken saat verisi gelmiyor ancak bunu pdf aktar yaptığım tüm veriler yerli yerine oturuyor. Sorun neden olabilir?
YanıtlaSil