找回密码
 立即注册

QQ登录

只需一步,快速开始

newdimchina

银牌会员

3

主题

11

帖子

2237

积分

银牌会员

积分
2237

活字格认证

最新发帖
newdimchina
银牌会员   /  发表于:2013-4-12 11:35  /   查看:4746  /  回复:3
客户端winform导入excel时,需要导入部署在服务端网站上的excel文件,请问可以支持导入么?如果可以的话,应该怎么做。谢谢!

3 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-4-12 16:21:00
沙发
回复 1楼newdimchina的帖子

可以,请使用以下代码测试:

  1. private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             Download("输入excel链接", Application.StartupPath + "\");

  4.             this.fpSpread1.Open("report.xls");
  5.             this.fpSpreadDesigner1.ShowDialog(this.fpSpread1);
  6.             Application.Exit();
  7.         }

  8.         /// <summary>
  9.         /// 下载服务器文件至客户端
  10.         /// </summary>
  11.         /// <param name="uri">被下载的文件地址</param>
  12.         /// <param name="savePath">另存放的目录</param>
  13.         public static bool Download(string uri, string savePath)
  14.         {
  15.             string fileName;  //被下载的文件名
  16.             if (uri.IndexOf("\") > -1)
  17.             {
  18.                 fileName = uri.Substring(uri.LastIndexOf("\") + 1);
  19.             }
  20.             else
  21.             {
  22.                 fileName = uri.Substring(uri.LastIndexOf("/") + 1);
  23.             }


  24.             if (!savePath.EndsWith("/") &amp;&amp; !savePath.EndsWith("\"))
  25.             {
  26.                 savePath = savePath + "/";
  27.             }

  28.             savePath += fileName;   //另存为的绝对路径+文件名

  29.             WebClient client = new WebClient();
  30.             if (client.Proxy != null)
  31.             {
  32.                 client.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
  33.             }

  34.             try
  35.             {
  36.                 client.DownloadFile(uri, savePath);
  37.             }
  38.             catch
  39.             {
  40.                 return false;
  41.             }
  42.             return true;
  43.         }
复制代码
回复 使用道具 举报
newdimchina
银牌会员   /  发表于:2013-4-15 15:06:00
板凳
哦~还是要下到本地的啊!
thanks~
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-4-15 16:08:00
地板
回复 3楼newdimchina的帖子

是的
不客气
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部