Asked by:
C#.net Export to excel

Question
-
User-1578974752 posted
Hi
I am using C#.NET
Below is my export to excel code. the values are coming in a straight line.
How can I make it in table format.Thanks
if (Session["dsek"] != null)
{
ASPEXCELL.ExcelExport.ExportDataSetToExcel((DataSet)Session["dsek"], "Data_" + DateTime.Now.ToString() + ".xls");
}
Monday, May 31, 2021 8:20 AM
All replies
-
User409696431 posted
You have to show us the code behind everything in "ASPEXCELL.ExcelExport.ExportDataSetToExcel". You are using a library, or you wrote them. We can't see them.
Your first step should be to put breakpoints in and debug it, to see what it is doing that is different from what you expect.
Monday, May 31, 2021 11:56 AM -
User-1578974752 posted
if (!Page.IsPostBack)
{
DataSet dsk = ORSQLSelectRecord("SELECT DESCRIPTION,MIN_MINMAX_QUANTITY,MAX_MINMAX_QUANTITY,TOTAL_1, TOTAL_2, TOTAL_3, TOTAL_4, TOTAL_5, TOTAL_6, TOTAL_7, TOTAL_8, TOTAL_9, TOTAL_10 WHERE nventoryid = inventory_item_id and VCODE = 'ABC'");
Session["dsek"] = dsk;
}Tuesday, June 1, 2021 2:03 AM -
User409696431 posted
That does not answer my question. All you are showing is your Select from the database, and that you put the results in session.
Again, as to your first question, put breakpoints in and debug it to see what it is doing vs what you are expecting it to do.
Tuesday, June 1, 2021 3:08 AM -
User-1578974752 posted
Above is my code. I want to update so that ,it will show in a Table format in the excel sheet. Code is not there.
How can I make it in table format.Thanks
Tuesday, June 1, 2021 7:36 AM -
User409696431 posted
You have not shared your code. You assume we know what ASPEXCELL.ExcelExport.ExportDataSetToExcel does. Those are not standard asp.net functions. You are using a library, or you wrote them yourself. You have not shown what that code does.
At any rate, again, you should try debugging your code. Only you know what that code is.
Tuesday, June 1, 2021 5:56 PM -
User753101303 posted
Hi,
Do you mean that you have multiple lines but all comma separated values in the first column? What is this library? Could ie be that it just writes data to a csv file?
Wednesday, June 2, 2021 9:15 AM -
User-1578974752 posted
Hi
I will attach as below
protected void ExportToExcel(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=RepeaterExport.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
rptCustomers.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
public static DataSet ORSQLSelectRecord(string strselect)
{
OracleConnection Ocon = new OracleConnection();
Ocon.ConnectionString = "......"
try
{
Ocon.Open();
OracleCommand ocmd = new OracleCommand();
ocmd.Connection = Ocon;
ocmd.CommandType = CommandType.Text;
ocmd.CommandText = strselect;//
OracleDataAdapter oda = new OracleDataAdapter(ocmd);
DataSet ds = new DataSet();
oda.Fill(ds);
return ds;
}
catch
{
return null;
}
finally
{
Ocon.Close();
Ocon.Dispose();
}
}
protected void Page_Load(object sender, EventArgs e)
{
//
if (Session["vcode"] != null)
{
//
if (!Page.IsPostBack)
{
vcode.Text = Request.QueryString["vcode"];
{
//
DataSet ds = ORSQLSelectRecord("SELECT DESCRIPTION,PART_NUMBER,MIN_MINMAX_QUANTITY,MAX_MINMAX_QUANTITY,TOTAL_1, TOTAL_2, TOTAL_3, TOTAL_4, TOTAL_5, TOTAL_6, TOTAL_7, TOTAL_8, TOTAL_9, TOTAL_10 WHERE nventoryid = inventory_item_id and VCODE = 'ABC'");
//
Partdrp.DataTextField = ds.Tables[0].Columns["PART_NUMBER"].ToString(); // text field name of table dispalyed in dropdown
// Partdrp.DataValueField = ds.Tables[0].Columns["Model_Name"].ToString(); // to retrive specific textfield name
Partdrp.DataSource = ds.Tables[0]; //assigning datasource to the dropdownlist
Partdrp.DataBind(); //binding dropdownlist
Partdrp.Items.Insert(0, new ListItem("", ""));
Partdrp.SelectedIndex = 0;
//
if (DropDownList1.SelectedItem.Text == "Part Number")
{
DataSet dsk = ORSQLSelectRecord(" "'");
rptCustomers.DataSource = dsk;
rptCustomers.DataBind();
Session["dsek"] = dsk;
//new
}
//
}
}
}
}
Friday, June 25, 2021 5:41 AM