简体   繁体   中英

How do I click button and get excel file by C#?

I want to download file by button from http://www.krx.co.kr/m2/m2_1/m2_1_8/JHPKOR02001_08.jsp

the button is with text "다운로드" in the upper right side

"다운로드" means download

if the button is clicked, i can download excel file at webbrower

here is web page source

<a href="?" onclick="doExcel(); return false;" title="조회결과 다운로드">
    <img     src="http://inc.krx.co.kr/image/cm/btn/bt1download.gif" alt="다운로드" id="excelBtn" style="display:none" />
</a>
<input type="submit" name="excelBtn2" id="excelBtn2" value="다운로드" />

I want to get the excel file by c# program

so I run below code with System.Windows.Forms.WebBrowser

webBrowser.Document.InvokeScript("doExcel()");

but I cant get excel file

how do i get excel file like clicking button?

and what I have to learn to solve problem like this?

when you are calling javascript function from loaded webpage, you can do so by

webBrowser.Document.InvokeScript("doExcel");

*without the '( )'

should you need to pass parameters then

webBrowser1.Document.InvokeScript("doExcel",p1,p2);

Alternatively

you can raise the click event via C# like this.

webBrowser.Document.GetElementById("excelBtn").RaiseEvent("Onclick");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM