Different Table Header Result After Export to Excel

Does anyone can help explain why the header is different from the original export results?

Original Table on Web :

Excel Result :

The problem is in the right top of table (Kostik field). Please help me to solve this problem.

Could you provide grid initialization code or debug-file?
To generate debug file open generate.php file and set value true in varible $debug:

$debug = true;

After that try to export grid one more time. Debug file will appear in the directory with generate.php file.

Here is the debug result, please help.

Hi.
Are you using setColumnColor method?
Try to initialize grid without this method.

Hi, here’s the debug without setColumnColor method :

Hi.
Please update gridExcelWrapper.php from attachment.
Tell me please if still doesn’t work.
gridExcelWrapper.zip (2.59 KB)

Hi radyno, its works and looks better now.
Thank you for your script update :slight_smile:

Hi All, I’d like to ask your help in this issue please:

I’m writing code to export a dataset to an excel file, it is doing this perfectly, the problem is in the format of the file, it saves it as Tab delimited format. In my case I need it be saved using normal excel format, because I have another functionality in my application to import the data from the excel file again, but the code I’m using for importing data is expecting the file to be in normal excel format. So, is there any way to force the export function to save the file in normal excel format

Here’s the code I use for exporting:

try

{
#region Check If table contain data or notif (p_UnitRatesDataTable.Rows.Count == 0)

{

throw new Exception(“There are no details to export.”);

}

#endregion

// Create Data Set and Add Table to It .
DataSet dsData = new DataSet(“Export”);

DataTable dtData = p_UnitRatesDataTable.Copy();
dtData.TableName = “Values”;

dsData.Tables.Add(dtData);
int ColumnCount = dtData.Columns.Count;

string[] sArHeader = new string[ColumnCount];
string[] sArItems = new string[ColumnCount];for (int i = 0; i < ColumnCount; i++)

{

sArHeader[i] = dtData.Columns[i].ColumnName;
sArItems[i] = this.ReplaceSpclChars(dtData.Columns[i].ColumnName);

}

try

{
#region Create Excel Style

MemoryStream oStream = new MemoryStream();
XmlTextWriter oWriter1 = new XmlTextWriter(oStream, System.Text.Encoding.UTF8);

CreateStylesheet(oWriter1, sArHeader, sArItems);

oWriter1.Flush();

oStream.Seek((long)0, SeekOrigin.Begin);

#endregion
#region Create Xml Document for Export

XmlDataDocument oXMLDataDoc = new XmlDataDocument(dsData);
XslTransform oTransform = new XslTransform();

oTransform.Load(new XmlTextReader(oStream), null, null);
StringWriter oWriter2 = new StringWriter();

oTransform.Transform(oXMLDataDoc, null, oWriter2, null);

#endregion
#region Create Response Object

HttpResponse oResponse = HttpContext.Current.Response;
oResponse.BufferOutput = false;oResponse.Charset = string.Empty;

oResponse.Clear();

oResponse.ClearContent();

oResponse.ClearHeaders();

oResponse.ContentType = “application/vnd.ms-excel”; // “application/vnd.ms-excel”;
oResponse.AppendHeader(“content-disposition”, “attachment;filename=” + FileName + “.xls”);

oResponse.Write(oWriter2);

oWriter2.Close();

oWriter1.Close();

oStream.Close();

oResponse.Flush();

oResponse.Close();

//oResponse.End();

#endregion

}
catch (ThreadAbortException ExAbort)

{
throw new Exception(ExAbort.Message);

}

}
catch (Exception exception1)

{
throw exception1;

}

Hi
I’m not sure but tab delimited is csv-file.
If you wish to save data exactly into xlsx you have to use some libraries: jexcel for example.