Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
175
Exporting manually set text to excel
posted

Hi, 

I want to export Y for 1 and N FOR 0.Currently I have set this in InitializeRow in webdatagrid as

protected void WebDataGrid1_InitializeRow(object sender, RowEventArgs e)
{
string maskingValue = e.Row.Items[12].Text;
string masking = "";
double cellValue = 0D;

if (maskingValue != null)
{
if (maskingValue.ToUpper().Trim() == "T/F")
{
//allow nulls for Y/N
if (e.Row.Items[13].Text == "0")
e.Row.Items[6].Text = "N";
else if (e.Row.Items[13].Text == "1")
e.Row.Items[6].Text = "Y";

if (e.Row.Items[14].Text == "0")
e.Row.Items[7].Text = "N";
else if (e.Row.Items[14].Text == "1")
e.Row.Items[7].Text = "Y";

if (e.Row.Items[15].Text == "0")
e.Row.Items[8].Text = "N";
else if (e.Row.Items[15].Text == "1")
e.Row.Items[8].Text = "Y";

if (e.Row.Items[16].Text == "0")
e.Row.Items[9].Text = "N";
else if (e.Row.Items[16].Text == "1")
e.Row.Items[9].Text = "Y";

if (e.Row.Items[17].Text == "0")
e.Row.Items[10].Text = "N";
else if (e.Row.Items[17].Text == "1")
e.Row.Items[10].Text = "Y";

}

}

Where Item[12] is hidden.

protected void cmdExportToExcel_Click(object sender, EventArgs e)
{
bindWebDataGrid1();

logutils.createLogEntry(1, "LOB Distribution Export for MI: " + currentMI.modelInstanceID, loggedInUserID);
Infragistics.Documents.Excel.Workbook workbook = new Infragistics.Documents.Excel.Workbook();
workbook.Worksheets.Add(currentMI.modelInstanceID.ToString().Substring(0, 31).Replace("-", ""));
Infragistics.Documents.Excel.IWorkbookFont normalFont = workbook.Styles.NormalStyle.StyleFormat.Font;
normalFont.Name = "Microsoft Sans Serif";
normalFont.Height = 8 * 20;

WebExcelExporter1.Export(workbook.Worksheets[0], 1, 0, WebDataGrid1);

}

But 1/0 are not getting exported as Y/N. I can still se 1/0 in excel sheet. How to achieve this?

Parents
  • 18204
    Verified Answer
    Offline posted

    Hello prabhakar kumar,

    Thank you for posting in our forums!

    The WebExcelExporter will export the data values of the cells to the Excel file.  In your InitializeRow handler you are only setting the cells' Text property and not their Value.  One option you have is to make columns 6-10 UnboundFields, which will allow you to set the Value of the cells.  Or you can wire up some of the WebExcelExporter's events, namely RowExported or GridRecordItemExported.  Using these events, you can alter the values that are used in the Worksheet.

    I would recommend using UnboundColumns and setting the cell Values before using the events.  This would make the code more maintainable.

    If you have any further questions or concerns with this, please let me know.

Reply Children
No Data