使用c#处理Excel工作表 [英] handling excel sheet using c#

查看:113
本文介绍了使用c#处理Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用selenium应用程序从网上下载excel文件。该文件以只读格式下载,即下载后不会保存。但是一旦它在打开excel之前下载就会抛出一个安全警告,其中有2个按钮启用和禁用。由于我在c#中编码,我希望c#处理该窗口。



这就是我想要c#点击启用按钮那个excel表的按钮。可能吗??任何评论都会非常感激..



谢谢。

I am using selenium application to download an excel file from web. The file is downloaded in read only format, that is it doesn't gets saved after downloading. But once it downloads before opening the excel throws a security warning in which it has 2 buttons-enable and disable. Since I am coding in c#, I want c# to handle that window.

That is I want c# to click on "Enable" button of that excel sheet. Is it possible?? Any comments would be really appreciated..

thanks.

推荐答案



您从哪里下载Excel文件。

如果我的猜测是例如来自gridview您将出口数据输出到excel然后尝试这样。



Hi,
From where you are downloading the Excel file.
if my guess is for example from gridview your exporting data to excel then try like this.

this.GridView1.Page.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        hw.WriteLine("<font size="3"> Test</font>");
        this.GridView1.RenderControl(hw);
        string HtmlInfo = tw.ToString();
        string DocFileName = "Report" + ".xls";
        string FilePathName = Request.PhysicalPath;
        FilePathName = FilePathName.Substring(0, FilePathName.LastIndexOf("\\"));
        FilePathName = @"C:\Excel" + "\\" + DocFileName;
          var fileInfo = new FileInfo(FilePathName );
           fileInfo.IsReadOnly = false;
        FileStream Fs = new FileStream(FilePathName, FileMode.Create);
        BinaryWriter BWriter = new BinaryWriter(Fs,System.Text.Encoding.GetEncoding("UTF-8"));
        BWriter.Write(HtmlInfo);
        BWriter.Close();
        Fs.Close();


这篇关于使用c#处理Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆