using xslt and dataset im uploading my data to excel file.
now i want to set the column display position dynamically ie.) let we assume if the dataset has 5 columns col1,col2,col3,col4 and col5 then the xslt is in the order of col2,col1,col4,col5,col3 so, now the excel file displaying in the order xslt, that is col2,col1,col4,col5,col3
got it!
now how i expect is, the excel output should be based on dataset position, and the ability to set the column title dynamically(i need to use xslt to design my excel) so, any body please tell me how to achieve this?
Any doubts please feel free to ask me. If this post is answer of your question then don't forgot to Click "Mark As Answer".
J.Jeyaseelan
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
dynamic settings
Mar 06, 2012 04:22 AM|LINK
hi all,
using xslt and dataset im uploading my data to excel file.
now i want to set the column display position dynamically ie.) let we assume if the dataset has 5 columns col1,col2,col3,col4 and col5 then the xslt is in the order of col2,col1,col4,col5,col3 so, now the excel file displaying in the order xslt, that is col2,col1,col4,col5,col3 got it!
now how i expect is, the excel output should be based on dataset position, and the ability to set the column title dynamically(i need to use xslt to design my excel) so, any body please tell me how to achieve this?
J.Jeyaseelan
Taimoor Janj...
Member
164 Points
32 Posts
Re: dynamic settings
Mar 06, 2012 05:14 AM|LINK
Hi there,
You can do this with this snippet,
}
this is the simplest way to do that. you can also format Column as you like.
Or you can follow this
http://www.codeproject.com/Articles/15023/Excel-Export-Component-Using-XSL
Regards,
Muhammad Taimoor
Pelase mark this answered, if this is what you were looking for.
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: dynamic settings
Mar 06, 2012 05:25 AM|LINK
Taimoor thanks for your response.
// Headers.
for (int i = 0; i < dt.Columns.Count; i++)
{
ws.Cells[1, i + 1] = dt.Columns[i].ColumnName;
}
above is fine
// Content.
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
ws.Cells[i + 2, j + 1] = dt.Rows[i][j].ToString();
}
}
above code will take much time, because every time i export thousands or lakhs of data.
do we have any other idea?
J.Jeyaseelan
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: dynamic settings
Mar 08, 2012 12:42 AM|LINK
Hello jeyaseelan:)
Maybe you can use Batch Exporting From DataTable to Excel,which is a different way from what we saw before……:http://www.codeproject.com/Articles/21519/Fast-Exporting-from-DataSet-to-Excel
jeyaseelan@a...
Contributor
5124 Points
2025 Posts
Re: dynamic settings
Mar 08, 2012 04:06 AM|LINK
finaly i resolved like this. this may help full in future to others so,im sharing my code here
string sXslt = @"<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/><xsl:template match='/'>
<head><title>Error Output</title><body><h1><xsl:value-of select='Application' /> - Error</h1><table><tr><td>Method:</td><td><xsl:value-of select='Method' />
</td></tr><tr><td>Message:</td><td><xsl:value-of select='Message' /></td></tr><tr><td>Trace:</td><td><xsl:value-of select='Trace' /></td></tr></table>
</body></head></xsl:template></xsl:stylesheet>";
XslCompiledTransform objXslTrans = new XslCompiledTransform();
objXslTrans.Load(new XmlTextReader(new StringReader(sXslt)));
string XmlPath = @"D:\DeleteMe\Xslt\" + Guid.NewGuid().ToString() + ".xml";
string strXsltFilePath = @"D:\DeleteMe\Xslt\" + Guid.NewGuid().ToString() + ".xslt";
string strXlspath = @"D:\DeleteMe\Xslt\" + Guid.NewGuid().ToString() + ".xls";
//File.Create(strXsltFilePath);
FileStream fs = new FileStream(strXsltFilePath, FileMode.CreateNew);
byte[] buffer = new byte[sXslt.Length];
for (int i = 0; i < sXslt.Length; i++)
{
buffer[i] = (byte)sXslt[i];
}
fs.Write(buffer, 0, buffer.Length);
fs.Close();
ds.WriteXml(XmlPath);
System.Xml.Xsl.XslTransform xsltObj = new System.Xml.Xsl.XslTransform();
xsltObj.Load(strXsltFilePath);
xsltObj.Transform(XmlPath, strXlspath);
File.Delete(XmlPath);
above is sample code onlu based on ur need you have to alter this.
J.Jeyaseelan
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: dynamic settings
Mar 09, 2012 12:19 AM|LINK
Congratulation!Welcome to here again to share us your nice solutions or chat with us about technology……