Export to excel on button click of C# code
Hello,
I want to develop an application in C# with authentication , after viewing all the pages, if the user clicks the more button or select a radio button, his information such as user name , and other information
must be appended to an excel sheet (office 2003 or 2007 excel sheet). The person associated with the admin can then view the excel sheet in offline mode to view the details of all the people who opted for a particular option. There may be overlapping of the
time when person clicks the button and admin is viewing the excel sheet. Is there a namespace or library in C# to perform this.
Thanks
Regards
Anoop
The simplest way is this no need of Interoperablety packages
private void toExcel()
Response.Clear();
Response.Buffer = true;
//Response.Charset = "UTF-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=schoolsinfo.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("EN-US", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
GridView1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Please mark as answer or helpful if it is useful
Similar Messages
-
WAD: Add export to excel/pdf button?
Hi all,
there's a standard component to add a button to export to pdf or excel format?
Also i have another problem, in some web reports i have graphs in different containers, if i export them to pdf all the graphs in every container is exported, there's a way to customize this and export only the data from the current container?
Thanks
StefanoHi Stefano,
The item you are looking for is a button group. When you define the buttons you can choose eather XLS or PDF and you can also specify which objects you wish to export e.g. your container object.
BR
Stefan -
Flash export leaves "gaps" between button clicks
Hi!
I'm having a nasty issue with the flash export capability of Encore CS4. I was trying to build a website that has 3 pages and a navigations system to go to them. The problem is that although everything seems to work just fine in the Encore preview, as soon as I export the project to a flash file and try to navigate, I get a flash between the clicks. It kind of looks like flash player is updating the content, just a quick flash on the page.
I have seen examples of flash webpages made with encore and they didn't seem to have that problem. What could be causing the "gaps" or "flashes" when navigating?Encore CS6 6.0.2.004, IE9, Win7
Simple project, DVD NTSC, One menu with one button. One timeline. Menu first play, button linked to timeline.
Output flash with flv (and again with f4v - same results), No template, keep with flash swf rather than streaming.
Open index.html locally, must manually enable active content. Menu opens, movie plays. No grey screen.
Copy entire folder to USB, same result; USB plays on a different PC also.
Upload to web site; same result.
Am I doing soething differently from either of you? Are you using templates?
Factors related to flash security (for local and probably USB playback) can be problems. Various server settings can be problems for on line. -
How do a simulate a button click from the code in BSP
Guys,
I have a push button .I need to simulate the click of that button some way through the code (in the view or controller ).Maybe by raising an button event .Has anybody done it ? Any ideas ?
Thanks,
ManojHi,
so after reading your "This is the real solution" I got it
In my opinion there are two possible solution:
1)When you hit the ok button on the valuehelp on view B two things happen:
a)You copy the selected values to the inputfield on view A
b)You raise an event on view A by clicking an invisible button on view A or using the <bsp:htmlbEvent> like Thomas suggested. However the code which clicks something on view A has to be in view B (the inputhelp). So you will have to change the inputhelp extension by adding a new attribute. I would only choose this solution when you are sure that you need this functionality also for other applications. The extension could look like this:
<zkeg:inputHelp id = "In5"
value = "<%= data5 %>"
rfcDest = "D10088t"
objtype = "DRAW"
objname = "Document"
param = "DocumentNumber"
keyField = "DOKNR"
parentFunctionToCallOnOkClick = "refreshSite()" />
The inputfield will then generate a javascript statement like this: parent.refreshSite();
and puts it in the function that is called when a user clicks on the OK button.
2)You attach an onChange event listener to your inputfield on view A. When a value is entered into the field the event handling javascript function raises a server event. Brians weblog shows you how the call the event and this OnChange Event for inputField shows you how to add the onChange event to the inputfield.
Btw really interesting problem I would love to read a weblog about it when you solved it
regards,
Thomas -
Export to Excel from PL/SQL Procedure
Hello,
I am creating a report using PL/SQL and html code. Once the report is display, I click on "Export to Excel" button. it should open the new window with Excel. The window opens in Excel, but no data. I have following code
as the first statement in the procedure.
OWA_UTIL.MIME_HEADER ('application/vnd.ms-excel', FALSE);
and this is the script
<script language="JavaScript">
var param_list
l_param_list := l_param_list || '&p_app_main_id=' || p_app_main_id;
l_param_list := l_param_list || '&p_from_date=' || p_from_date ;
l_param_list := l_param_list || '&p_to_date=' || p_to_date ;
htp.prn('
param_list = ''');
htp.prn( l_param_list);
htp.prn('''
function NewWindow(mypage,myname,w,h,scroll){
var win = null;
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = ''height=''+h+'',width=''+w+'',top=''+TopPosition+'',left=''+LeftPosition+'',scrollbars=''+scroll+'',resizable''
win = window.open(mypage,myname,settings)
win.focus();
function ExportToExcel() {
var wndname = ''ExpCodeMoveRep'';
var wndw = screen.width-10;
var wndh = screen.height-10;
var wattr = ''scrollbars=yes,toolbar=yes,resizable=yes,menubar=yes'';
var wndurl = ''pm_codemove_report?p_output=E'';
wndurl = wndurl + param_list;
NewWindow(wndurl,wndname,wndw,wndh,wattr);
</script>
My submit is
htp.prn('
<p align="center">
<input type="button" class="printbutton" value="Close" class="button" OnClick="window.close();">
<input type="button" class="printbutton" value="Export To Excel" class="button" OnClick="ExportToExcel();">');
Can anyone tell me what is wrong.
I have the same code in another schema and it is working fine. Both schema are on the same server. Do they have any set up on appserver in DAD file to be able to see the data in Excel?
Thanks
YagnaThank you for your answer dccase!
I decided to go with on demand process. I have trouble with calling procedure from (button URL - javascript:popupURL('#OWNER#.exportXML')) pop window which cause "Forbidden, The requested operation is not allowed" error. I read that this is because I'm using XE edition and there is no HTMLDB_PUBLIC_USER role in XE.
Now, I use on demand process and button URL link:
javascript:popupURL('f?p=&APP_ID.:0:&APP_SESSION.:APPLICATION_PROCESS=PLSQL_Export_XML:NO::')
It is working. Now I have to find solution to automatically close popup window :-)
Thanks!
Marko -
Export to Excel functionality for Multiple tabs in WAD
Hi,
I have a requirement where in i need to export a report from WAD to excel. The WAD template has multiple tabs which i want individually in seperate excel sheet tabs. How can i achieve this ?
Regards
Snehith.Hi,
have a global button (some where on the top) with command 'export to excel' and configure all your analysis item for that button. So when u execute the template and when u click on individual tab, the report out from individual tab will be exported to excel when u click on Export to excel button.In this way u can individually export the output to excel.
Regards -
Text Elements in Export to Excel functionality
Hello Gurus,
I have added Export to Excel functionality button on my web template and also added a Text Element Web Item to my web template. I am unable to get the Text Elements into the Excel Sheet when I click on Export to Excel button. Is there a way to show them in the Excel sheet when I click on Export to Excel or it is not possible to show them.
Please let me know.
Thanks a lot
RajRaj,
Export to Excel will work only for the table item. Not 100% sure, but don't think that it can be setup for teh text items.
Put the text elements into parts of teh query, for e.g. in the query title or column headings.
The idea of export to excel is that the data gets exported. There is no transfer of context of the information.
Aneesh -
Service Process Monitor export to excel is not working
Hi,
The Tx. CRM_SRV_REPORT ( Service -> Service Process Monitor) is not working.
When you try to export to Excel (press button Excel (CtrlshiftF7) is not working. However, this button in other transaction is working, for example Activity Monitor.
Any idea?
LydaReport to SAP. They sent a solution... it's an error
-
Error in FBL3N when exporting to excell.
Good morning gurus.
I have a problem .
After generating a report in FBL3N I try export to excell ,then I click in LIST ---> EXPORT ------> SPREADSHEET.
Then my user configured the scrren :
Then when execute occurs a dump (see attached)
The error says:
| Internally required memory is not available
| An internal function tries to request memory. |
| This memory could not be allocated by the operating system.
can someone help me?
ThanksHi,
please try below mentioned method
FBL3N - execute - go to list in main menu - export - Local file F9 - select spread sheet - press enter - select directory - desktop --- select MS excel file format
give file name and GENERATE
then check file on desktop
Thanking you
Regards
Mahesh -
Error when Calling a BAPI in ALV custom button "could not ascertain code"
Hi,
I am getting the error "Could not ascertain code page" when i try to call my BAPI (to export to excel sheet) on click of a custom button in ALV.
I have done the creation and event handling etc for the custom button.
Kindly help if anybody knows this error.
Thanks
RoshanI am creating a custom export button(after disabling the standard export button) to download the data into an excel sheet in my own format. I have created the new button. The code is given here.
data lr_buttonui2 type ref to cl_salv_wd_fe_button.
data input2 type ref to cl_salv_wd_function.
data: lr_column_settings type ref to if_salv_wd_column_settings,
lr_input_field type ref to cl_salv_wd_uie_input_field.
create object lr_buttonui2.
call method lr_buttonui2->set_text
exporting
value = 'Export'
input2 = lo_value->if_salv_wd_function_settings~create_function( id = 'EXPORT' ).
input2->set_editor( lr_buttonui2 ).
data lr_ref3 type ref to cl_salv_wd_fe.
call method input2->get_editor
receiving
value = lr_ref3
I have also created the event handler for my button and written the below code thr. I am caling a BAPI to download the data into my excel format. The problem is coming here only.
data: lt_return type table of bapiret2.
data lo_nd_methcode type ref to if_wd_context_node.
data lo_el_methcode type ref to if_wd_context_element.
data ls_methcode type wd_this->element_methcode.
data lv_methcode like ls_methcode-methcode.
navigate from <CONTEXT> to <METHCODE> via lead selection
lo_nd_methcode = wd_context->get_child_node( name = wd_this->wdctx_methcode ).
get element via lead selection
lo_el_methcode = lo_nd_methcode->get_element( ).
get single attribute
lo_el_methcode->get_attribute(
exporting
name = `METHCODE`
importing
value = lv_methcode ).
call function 'ZBAPI_EXCEL_DLOAD_METHODOLOGY'
exporting
i_methcode = lv_methcode
tables
et_return = lt_return
Plz give me a solution -
Pop Up to be displayed on Export to excel button click
Dear All,
I am using BW 3.5 web template for reporting. I have a requirement to display a pop-up window when user clicks on Export to excel button in web report. The pop up will be a confirmation message/disclaimer saying the data being sensitive.
I need 2 buttons to be displayed on the pop-up, Ok and Cancel. If user clicks on Ok then data will be exported to excel as usual and if he clicks on Cancel then no action should be performed and pop up should be closed.
Does anyone have implemented the scenario or can anyone guide me how to achieve this requirement.
Regards,
NirajNot done this but you can use JavaScript confirm alert box
Event 1.Upon pressing Export button to Open Alert Message
2. Listen from Alert Message buttons OK or Cancel
3.Trigger events based on user input.
Google "JavaScript confirm alert box" you will get bunch of sample codes. -
ALV GRID Export to Excel button Missing
HI All,
I am facing some problem with ALV GRID. When excuting the report with my user id I am able to see the 'Export to Local file' button in the ALV GRID where as if i am excuting with another user id which is having less authorisations than the button is greyed out. I checked by giving all authorisation than we are able to see the button.
Could anyone please tell me which authorisation object we have to assign to see the buttons.
Thanks & Regards,
Murali.Hi,
Before clicking on the Export to Excel button, start the debugging session by placing the command /H in the command prompt.
Now, put the break point at statement AUTHORITY-CHECK. Now it will trigger all the authorization objects relevant to this.
check the sy-subrc value gets failed.
Regards,
Santhosh. -
Export to Excel button only launches in Internet Explorer window
Hi Experts - A subset users that are experiencing issues with the option to Export to Excel via Web Analyzer on 7.0. For others, including myself it works just fine.
When they click the Export to Excel option after running a query, it only opens in an Internet Explorer window (no Excel options to manipulate data) and does not give them the typical MS Excel pop-up window (like I get) to OPEN or SAVE in Excel format.
Thinking this would be an MS Excel or Internet Explorer setting somewhere, but don't know where to find it....
Any help is appreciated!Hello,
I think that you're right, the problem doesn't seem to come from anything in SAP servers (otherwise no user would be able to make it work right).
If I understand well, you want to open an Excel window when selecting "export to Excel" option, not having the table opened in IE with an Excel tab. Am I right ?
If it's the case, I think that this should work :
In windows explorer, open tools -> folder options
Tab "file type"
find xls extension, and click "advanced" button
uncheck "browse in the same window" button
I'm using windows XP, therefore I can't guarantee that you'll find the same menus with another OS. Furthermore, I'm using a french OS, so my translations might differ slightly from what you'll actually have on screen. The result is reflected in the following registry key : HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.8
(this could be a different key, depending on the MS Office version installed on your computer)
You should now have a DWORD value BrowserFlags = 8
If you have a helpdesk department in your company, that handles software installations, I guess that they should handle this problem (by broadcasting the change in registry ?). But if you're a small company, where everyone has the rights to change such settings, this method will be OK.
Best regards,
Giang DANG -
Cant use Export to Excel functionality for ALV if I add a custom button
Hi,
I have added a custom button the the ALV toolbar by creating a GUI status and using the USER_COMMAND event. However. Now I dont the get the standard ALV toolbar with all the options for sorting, exporting to excel etc.
Can someone show me how I can do both, add my own button to the toolbar as well as use ALV Grid toolbar. Currently the ALV grid standard toolbar has disappeared
Thanks for readingHello,
I am not sure how you are creating your ALV report. If you are using FM REUSE_ALV_GRID_DISPLAY there is a parameter callled I_CALLBACK_PF_STATUS . Read the documentation for this field from the doc for the FM. It tells you to copy a standard PF status from fucn group SLVC_FULLSCREEN and then add your new button to that staus.
If you are using class CL_SALV_MODEL_BASE there is a method called set_screen_status that lets you do a similar thing - copy an existing PF status and add your button.
Hope that helps
Regards
Greg Kern -
How to download background color of ALV with button "Export to Excel"
Dear Experts:
I can download the data of ALV in webdynpro for ABAP, but the color is missing.
Does anybody know how to download background color of the ALV cells also by "Export to Excel" button?
Could anybody help on this?
Thanks in advance!
Best Regards
Lingxing Mengnever experienced that...
[chk this link|Download colored ALV output in to EXCEL sheet;
a couple of intersting posts, they talk abt general ALV...
try one of the last post ...when downloading
use local file->HTML only.. but while choosing the file location to save give extension as XLS.
Maybe you are looking for
-
In Yosemite, Magic Mouse double-click function doesn't work
On my iMac running Yosemite 10.10.2, the double-click function on the Magic Mouse no longer works. So to open a folder, or anything for that matter, I must always do click-control ---and that doesn't work for everything. For example, I can't double c
-
Synching iPhone Contacts through ITunes with Google Contacts.. DUPLICATES
I have an iPhone 3GS and a Windows 7 Computer. I can NOT figure out how to stop the duplication (or triplication +)of contacts from happening every single time i sync my phone to my google contacts. I don't have outlook - so a few months ago when I g
-
Create document in Background with BAPI_DOCUMENT_CREATE2
Hi, how can i create a document with the BAPI_DOCUMENT_CREATE2 in background (not in dialog)? I want to upload the original from my front-end (Path: C:\test.pdf). If i use the paramter "pf_http_dest = SAPHTTP", it didn't work. I don't want to upload
-
Will purchase items continue 2 download if I'm watching other stuff on TV?
I know that my iTunes Library will not sync to my TV until I stop watching something on it. Basically, no TV activity if I wanna sync. And since TV can function as an independent device sans Mac, I'm not sure whether if I can watch a TV show or
-
Access to Export formatting options that may not be readily available?
How can I access Export formatting options that existed in CR XI using CR VS2010? I am converting an app from CR XI to CR VS2010 and am attempting to generate DiskFile exports. The general process is succesful, but there certain formatting options I