I can't figure out how to do the following 2 things.
1. Set the width of the exported columns. They look ok in my grid in the WinForm, but when exported take up too much space.
2. How do I change the style of the column headers? I would like to bold it.
Here's my code.
private
void
btnExportVendorInvoices_Click(
object
sender, EventArgs e)
{
using
(SaveFileDialog dialog =
new
SaveFileDialog())
{
dialog.Filter =
"Microsoft Excel (*.xlsx)|*.xlsx"
;
dialog.FilterIndex = 2;
dialog.RestoreDirectory =
true
;
if
(dialog.ShowDialog() == DialogResult.OK)
{
rgvInvoices.EnableAlternatingRowColor =
true
;
var exporter =
new
ExportToExcelML(rgvInvoices);
exporter.SheetMaxRows = ExcelMaxRows._1048576;
exporter.HiddenColumnOption = HiddenOption.DoNotExport;
exporter.ExportVisualSettings =
true
;
exporter.ExcelCellFormatting += explorter_ExcelCellFormatting;
exporter.RunExport(dialog.FileName);
exporter.ExcelRowFormatting += exporter_ExcelRowFormatting;
var dr = RadMessageBox.Show(
this
,
"File has been saved, would you like to open it?"
,
"File saved"
, MessageBoxButtons.YesNo, RadMessageIcon.Info);
if
(dr.ToString() ==
"Yes"
)
{
System.Diagnostics.Process.Start(dialog.FileName);
}
}
}
}
private
void
explorter_ExcelCellFormatting(
object
sender, ExcelCellFormattingEventArgs e)
{
if
(e.GridCellInfo.RowInfo
is
GridViewDataRowInfo)
{
if
(e.GridCellInfo.ColumnInfo.Name ==
"vendorFedId"
)
{
e.ExcelCellElement.Data.DataItem =
string
.Format(
"{0:00-0000000}"
, Convert.ToInt32(e.GridCellInfo.Value));
}
}
}