如何在Windows应用程序中保存webBrowser控件中的excel文件。 [英] How to save excel file from webBrowser control in windows application.
本文介绍了如何在Windows应用程序中保存webBrowser控件中的excel文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在使用以下方法在我的Windows应用程序中打开侧面webBrowser控件中的Excel文件。它打开正确。如果某个更改或向单元格添加新值,我想要保存数据。我怎么能在我的申请中这样做。
Hi all,
I'm using following way to open an Excel file in side webBrowser Control in my windows application. it opens correctly. I want save data if some one change or add new values to cells. How can I do this in my application.
webBrowser1.Navigate(@"C:\Documents and Settings\shiv.singh\Desktop\Exceptions.xlsx");
谢谢
thanks
推荐答案
//Don't forget the directive
using System.Net;
...
private void webBrowser1_Navigating_1(object sender, WebBrowserNavigatingEventArgs e)
{
//Provide the path and file name for the download
string targetPath = @"C:\ExcelFileTarget\MyDownLoadedExcelFile.xlsx";
//Create a web client and the event for the download
WebClient client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
//Place the file in the desired folder.
client.DownloadFileAsync(e.Url, targetPath);
}
private void button1_Click(object sender, EventArgs e)
{
//Use what ever method you want to load the file into the browser
downloadMyExcelFile();
}
private void downloadMyExcelFile()
{
//As the file is loaded let's use the navigate event
//to trigger the file download. There should be a test to
//assure there is a file to upload.
string urlPath = @"C:\ExcelFileSource\MyExcelFile.xlsx";
webBrowser1.Navigate(urlPath);
}
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
//This event can be left empty, but the event needs to happen
MessageBox.Show("File downloaded");
}
祝你好运!
Good luck!
这篇关于如何在Windows应用程序中保存webBrowser控件中的excel文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文