i am using 2011.1 version
I am using WebExcelExporter to export the grid into excel.
i have some hidden column in grid. if i export the grid into excel then
hidden column header does not export but hidden column cell values are exporting
and it override the Next cell visible column value.
This is happen only when i have atteached CellExporting event on WebExcelExporter .
and i am trying to cancel the event and i am atteching the e.worksheetcell.value to some
values. and also
i have Link column and i wanted to show it the Linktext not <a title="some thing">
i have more then one LinkColumn in my grid for first column it work as expected
but for 2nd Lincolumn it showing the text as <a title="some thing2"> not Text alone.
why?
For ex if i have a grid with fallowing column
LinkColumn-1 HideColumn-1 Column-2 LinkColumn-3 Column-4
LinValue-1 HideValue VisibleVal2 LinkVal3 VisibleVal4
Then Grid exported Like this
LinkColumn-1 Column-2 LinkColumn-3 Column-4
LinValue-1 HideValue VisibleVal2 <a title=LinkVal3 />
VisibleVal4 goes out and not showing
Why HideValues is showing?
why LinkVal3 is shoing as <a title=LinkVal3 />?
i have written the code inside the CellExporting event lnk this
private static void OnCellExporting(object sender, ExcelCellExportingEventArgs e) { if(!e.IsHeaderCell && !e.IsFooterCell && !e.IsSummaryCell) { GridRecordItem item=_exporter.WebDataGrid.Rows[e.CurrentRowIndex - 1].Items[e.CurrentColumnIndex]; if(item.Column.GetType().Name == "TemplateDataField") { TemplateDataField field = item.Column as TemplateDataField; if(!string.IsNullOrEmpty(((TemplateColumn)field.ItemTemplate)._linkColumnPath)) { System.Web.UI.HtmlControls.HtmlAnchor anchor = item.FindControl("anchor") as System.Web.UI.HtmlControls.HtmlAnchor; if(anchor != null) { e.Cancel = true; e.WorksheetCell.Value = anchor.Title; e.WorksheetCell.CellFormat.Font.Height = 200; } } } else { e.Cancel = true; e.WorksheetCell.CellFormat.Font.Height = 200; e.WorksheetCell.Value = item.Text; } } }
i have resolved the problem.
i am handling the cellexporting event diffrently, when grid some column are not visible.
For example
private
text) {
i = _weDataGrid.Columns.Count - 1; i >= 0; i--) {
(_weDataGrid.Columns[i].Header.Text == text)
i;
}
0;
e) {
(!e.IsHeaderCell && !e.IsFooterCell && !e.IsSummaryCell) {
.ToString(e.Worksheet.Rows[0].Cells[e.CurrentColumnIndex].Value));
item = WebDataGrid.Rows[e.CurrentRowIndex - 1].Items[index];
) {
;
)field.ItemTemplate)._linkColumnPath)) {
System.Web.UI.HtmlControls.
e.WorksheetCell.Value = anchor.Title;
e.WorksheetCell.CellFormat.Font.Height = 200;
e.Cancel =
{
e.WorksheetCell.Value = item.Text;
Hello Mypost,
Thank you for posting your solution for this question in our forum.
Inform me if you need additional assistance.
If I read this correctly, the ONLY way to handle the situation when a Grid has hidden columns and you want to override a subset of columns using the _CellExporting event, is to override EVERY column's export?
Considering the "standard" method for exporting the lookup values for fields with DropDownProviders is to use the _CellExporting event of the WebExcelExporter, it looks like we have to handle EVERY column then.
Is this correct?
As a final word on the matter, if you use the _GridRecordItemExported event, then you do NOT have to issue a e.Cancel = True in order to ensure your value gets exported. If you update e.WorksheetCell.Value in this event, it writes to the exported worksheet without requiring canceling of the events.
Why does this matter? Because, apparently, the e.Cancel = True in the _GridRecordItemExporting event prevents the exporter from formatting your exported cell. It is left as exercise to identify what other operations are curtailed when specifying e.Cancel = True.
As it turns out, there is a replacement to CellExporting introduced ... I don't know when:
GridRecordItemExporting Event
It seems to handle the e.Cancel = True action MUCH better than CellExporting insofar as it doesn't get all mixed up with hidden columns.
Sadly, my discovery was based on reading the source code, not the forums.