|
I have a web application to display sales data. My input, transaction_header table, is like this:
... | van_id | sale_date | ... | ... | Van A | 2012-03-01 17:28:38.000 | ... | ... | Van A | 2012-03-01 17:33:54.000 | ... | ... | Van B | 2012-03-01 12:33:48.000 | ... | ... | Van B | 2012-03-01 12:38:14.000 | ... |
I need to export the transaction data to excel and the excel would show as:
Gross Sales | DATE | Van A | Van B | Van C | ... | 1-Mar | $3,359 | | | ... | | $49,934 | $20,657 | $41,481 | ... | 2-Mar | $3,633 | | $4,263 | ... | | $73,394 | $38,134 | $41,083 | ... | 3-Mar | | | $2,118 | ... | | $40,831 | $39,838 | $32,344 | ... | 4-Mar | SUNDAY | 5-Mar | $4,387 | | $3,842 | ... | | $84,814 | $39,242 | $41,116 | ... | ... |
My problem is the number of van may change over time. For the transaction_header table, this does not post a problem as there is just one more row. Yet for the output, it is a problem. Thw columns of my table may increase over time. Now how do I approach this problem?
Appreciate any feedback. Thanks.
modified 19-Apr-12 22:57pm.
|
|
|
|
|
hmmm..... you can do it.... good luck!
|
|
|
|
|
There are a ton of examples online of how to export data to Excel. Start here.[^]
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Yes, there are tons of example out there. My question, I think, is more specific. The number of columns may increase (or even decrease, although I doubt it will) over time. Now how can I handle this?
|
|
|
|
|
Quote: The number of columns may increase (or even decrease, although I doubt it will)
That is just fine. Most examples I have seen use a DataGrid and set AutoGenerateColumns = true. This means that it does not matter how many columns you have.
The code is have used before is here.[^] All you have to do is set the datasource of the datagrid.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Try This...it will work as per your requirement:
protected void cmdExport_Click(object sender, EventArgs e)
{
clsDataAcess oDataAccess = new clsDataAccess();
oDT = new DataTable();
oConst = new clsConstMaster();
string filename = string.Empty;
try
{
oDT = oDataAccess.GetCustomerWholeInformation(Parameter To function Here);
if (oDT.Rows.Count > 0)
{
filename = "CustomerInformationFromMaster.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dg = new DataGrid();
dg.DataSource = oDT;
dg.DataBind();
dg.HeaderStyle.BackColor = System.Drawing.Color.LightGray;
dg.HeaderStyle.Font.Bold = true;
foreach (DataGridItem i in dg.Items)
{
foreach (TableCell tc in i.Cells)
{
tc.Attributes.Add("class", "text");
//tc.BackColor = System.Drawing.Color.Blue;
}
}
dg.RenderControl(hw);
string style = @" .text { mso-number-format:\@; } ";
Response.Write(style);
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;
Response.Write(tw.ToString());
Response.End();
}
}
catch (Exception ex)
{
MessageBox(ex.Message.ToString());
}
}
public override void VerifyRenderingInServerForm(Control control)
{
}
- Happy Coding -
Vishal Vashishta
|
|
|
|
|
Hi,
I have a repeater control, for which I have header template and item template. Both are in different divs. Both divs are creating rows and border properly. The problem now is the header is having gap and then its body.
Is there any way that we can have border for the whole repeater control? Any sort of link or code snippet would be greatly helpfull.
thanks in advance,
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
|
Is it a vertical gap or horizontal gap?
|
|
|
|
|
Can we create a message box inside the Label?... and the msgbox contains a link that will use to pop up another form.?.. this program is using a VB.Net...
Hermaine
|
|
|
|
|
What are you trying to do? Click on a Label and pop up a message box? Click on the link inside the message pop up another form? Wow.
|
|
|
|
|
haha.. yeah.. i'm just trying to create an event handler calendar using a VB.net.. i don't have any idea on how to put an event to each date of the month.
Hermaine
|
|
|
|
|
Hermaine wrote: Can we create a message box inside the Label?
That message does not make much sense. A message box / alert is shown on top of the form / web page.
A non-modal message box could go behind the application confusing the user.
|
|
|
|
|
OK.. thanks Sir.. but how about making an event calendar then if the user will point it's cursor on the date within a month there will be a message that shows all of the events of that date. is this possible using a VB.NET application Sir?
|
|
|
|
|
Anything is possible since you control the code. I think you should start by learning the language better and viewing samples that other people have.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
|
Hi
I have few reports developed on SSRS 2005 and binded in VSS.
When i try to open the reports in my login in visual studio, then i get error "UNABLE GET IVSMDDESIGNER SERVICE". When i open the reports locally in visual studio, i can am able to view the reports. Please suggest me how i can solve this.
Thanks in advance
Naina
Naina
|
|
|
|
|
Hi,
I have web page in which I am Literal Control within list item in the unordered list. Is there any way to get or set its value using jquery.
Thanks in advance please.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Not that I am aware of, you need to use a div tag or panel with an id assigned
|
|
|
|
|
Hi,
I got it solved by append and remove css, and remove all the elements with that css class in the jquery.
Thanks,
abdul
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Well if that backfires on you later on down the road, you can use jquery to dump or delete everything inside the div tags, and then write new html back inside the tags, while retaining your div tag css, so the div tags retain the proper spacing and alignment.
it works great for movie or flash objects, and will destroy the movie and audio as well. Or you can destroy an entire list of products, and write new ones, etc
Good to hear you solved it.
|
|
|
|
|
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
Hi All,
I have a web page which is having print and email buttons. When I say print its printing on paper and on pdf also correctly.
Now they want, the same pdf format should be sent as to users when user clicks email. Is there any way to generate the pdf files for this and send emails with those pdfs as attachments when user clicks email button.
Please any body if have any idea please help me, its very urgent. Any link or any code snippet helps me a lot. In this mean time I will request to uncle google .
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
I have used abcpdf for the same purpose. Its very easy to integrate. Meanwhile, which tool have you used to get your pdf output from webpage?
|
|
|
|
|
Hi,
I am actually printing the page itself by using the below method. When it goes to the printer options, if we have acrobat installed on our machine then the print dialogue box has an option to print in pdf file. Thats how its happening right now.
It is the javascript method:
function printpage() {
window.print();
}
I want to make it automatically that web page should create pdf file and send it to the specified email as an attachment.
All this should happen in a button click as one shot.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|