We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Excel exporting line break

Thread ID:

Created:

Updated:

Platform:

Replies:

100473 Aug 9,2011 11:29 AM Aug 11,2011 03:21 AM ASP.NET Web Forms (Classic) 2
loading
Tags: XlsIO
victor elizondo
Asked On August 9, 2011 11:29 AM

Hello everybody.

I have a problem.

I have a code snippet:
---------------------------------------------------------------
this.GridGroupingControl1.DataSource = DATATABLE;

GridExcelExport excel = new GridExcelExport(this.GridGroupingControl1, "Namefile.xls");

excel.ExportNestedTable = true;
excel.Export();


---------------------------------------------------------------
I have syncfusion version 6.4.0.15.
I'M USING VISUAL STUDIO 2008 C#.

GridGroupingControl1 is a Syncfusion Control
(Syncfusion.Web.UI.WebControls.Grid.Grouping.GridGroupingControl)

In that syncfusion grid I have a row with information with a line break ( the image about it is attached file) but when EXPORTING to Excel ( in the image says IMPORTING, sorry) doesn't respect the line break in the XLS file.

I don't know if in syncfusion exists a WRAPTEXT property for XLS sheet, or in SQL I must save in a register an ALT-ENTER key combination to make the line break( Actually I don't know how to do this), so this is my request for you.

Best Regards, hope you can help me.






line break_a174f768_c0596675.zip

victor elizondo
Replied On August 10, 2011 09:09 PM

I've founded a solution to my problem I want to share it.

----------------------------------------------------------------

ExcelEngine engine = new ExcelEngine();
IApplication application = engine.Excel;
IWorkbook workbook = application.Workbooks.Create();
IWorksheet sheet = workbook.Worksheets[0];

//This is for showing the datatable dtExcel HEADER in the excel
//sheet
char Numero = '1';
char Letra = 'A';

for (int g = 0; g < dtExcel.Columns.Count; g++)
{
string cell = Letra.ToString() + Numero.ToString();
sheet.Range[cell].Text = dtExcel.Columns[g].ColumnName.Replace("
", "");
sheet.Range[cell].CellStyle.WrapText = true;
sheet.Range[cell].CellStyle.Color = System.Drawing.Color.MediumSeaGreen;
sheet.Range[cell].CellStyle.Font.Bold = true;
sheet.Range[cell].CellStyle.Font.FontName = "Verdana";
sheet.Range[cell].CellStyle.Font.Size = 8;
Letra++;
}

//This is for showing the datatable dtExcel in the excel
//sheet
Numero = '2';
for (int i = 0; i < dtExcel.Rows.Count; i++)
{

Letra = 'A';
for (int j = 0; j < dtExcel.Columns.Count; j++)
{
string cell = Letra.ToString() + Numero.ToString();
sheet.Range[cell].Text = dtExcel.Rows[i][j].ToString().Replace("
", "");
sheet.Range[cell].CellStyle.WrapText = true;
sheet.Range[cell].CellStyle.Font.FontName = "Verdana";
sheet.Range[cell].CellStyle.Font.Size = 8;

if (dtExcel.Rows[i][j].ToString().Length >= 20 && dtExcel.Rows[i][j].ToString().Length <= 50)
sheet.Range[cell].ColumnWidth = 15;

if (dtExcel.Rows[i][j].ToString().Length >= 50 && dtExcel.Rows[i][j].ToString().Length <= 100)
sheet.Range[cell].ColumnWidth = 20;

if (dtExcel.Rows[i][j].ToString().Length >= 100)
sheet.Range[cell].ColumnWidth = 50;

//Increasing the ABC letters
Letra++;
}
//Increasing the numbers (1,2,3,4...)
Numero++;
}

workbook.SaveAs(Request.PhysicalApplicationPath + @"FileName.xls");

workbook.Close();
engine.ThrowNotSavedOnDestroy = true;
engine.Dispose();
System.Diagnostics.Process.Start(Request.PhysicalApplicationPath + @"FileName.xls");

----------------------------------------------------------------

BEST REGARDS.



Sridhar [Syncfusion]
Replied On August 11, 2011 03:21 AM

Hi victor,

Thank you very much for using Syncfusion products.

We are very happy to see that your problem is solved at your side specified in your previous update. Please let us know if you require any further clarifications , get back to us with the required sample file and we are happy to help you out.

Thanks,
Sridhar.S


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;