Hi Experts,
In a .Net application, Response.ContentType can be set to excel to export data from a table to excel. How to do the same in SAP, as it doesn't accept this command? All I have to do is export data in DataTable to an Excel document. Could anyone suggest me some workaround or snippet in this regard ASAP.
Thank you in advance,
Madhesh.
Request clarification before answering.
any news about this problem ?
thx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Madhesh,
I posting code below.I am using this on button click event.
Check it whether it helps you or not.
/* ************************************************************************************************* */
if (dsDataSet.Tables.Count > ZERO)
{
string sTableStart = @"<HTML><BODY><TABLE Border=1>";
string sTableEnd = @"</TABLE></BODY></HTML>";
string sTHead = "<TR>";
StringBuilder sTableData = new StringBuilder();
foreach (DataColumn col in dsDataSet.Tables[0].Columns)
{
sTHead += @"<TH>" + col.ColumnName + @"</TH>";
}
sTHead += @"</TR>";
foreach (DataRow row in dsDataSet.Tables[0].Rows)
{
sTableData.Append(@"<TR>");
for (int i = 0; i < dsDataSet.Tables[0].Columns.Count; i++)
{
sTableData.Append(@"<TD>" + row<i>.ToString() + @"</TD>");
}
sTableData.Append(@"</TR>");
}
string sTable = sTableStart + sTHead + sTableData.ToString() + sTableEnd;
System.IO.StreamWriter oExcelWriter = System.IO.File.CreateText("c:/excelfile.xls");
oExcelWriter.WriteLine(sTable);
oExcelWriter.Close();
/* ************************************************************************************************* */
If above code snip help then award Points
Regards
Sunil Pawar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.