惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
IT之家
IT之家
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
V
V2EX
Last Week in AI
Last Week in AI
H
Help Net Security
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
F
Fortinet All Blogs
I
InfoQ
宝玉的分享
宝玉的分享
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog

博客园 - 半克拉鹅卵石

strong name in gac sql积累 一些有用的bat命令 js获取某年某月天数 计算经纬度距离 正则表达式分割数组 修改系统时间 转贴:Lucene的评分(score)机制 搜索引擎CACHE策略研究 DllImport lucene.net 2.0在多线程同步下似乎有问题 Lucene Hack之通过缩小搜索结果集来提升性能 lucene2.0与2.3区别 asp.net常用函数 不走寻常路,设计asp.net应用程序的七大绝招 数据库备份 获取sql server服务器名称 如何用SQLDMO在ASP.NET页面下实现数据库的备份与恢复 Asp.net中操作Excel的权限解决方法
C#中下载Excel文件(其实就是将Excel文件从一个路径Copy到另一...
半克拉鹅卵石 · 2006-04-21 · via 博客园 - 半克拉鹅卵石

C#中下载Excel文件(其实就是将Excel文件从一个路径Copy到另一个路径)

public void download(string TempName)
        
{
            
try
            
{
                
string StrPath ;
                StrPath
=Application.StartupPath+@"\template\"+TempName+@".xls";
                Excel.Application xlApp
=new Excel.Application();
                Excel.Worksheet xlSheet;
                
object missing=System.Reflection.Missing.Value;
                Excel.Workbook xlBook 
= xlApp.Workbooks.Open(StrPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                xlSheet 
=(Excel.Worksheet)xlBook.Worksheets[1];
                FolderBrowserDialog Foler
=new FolderBrowserDialog();
                
string FileName="";
                Foler.Description
="选择保存模板的目录";
                
if(Foler.ShowDialog()==DialogResult.OK)
                
{
                    
if(Foler.SelectedPath!="")
                        
if(System.IO.File.Exists(StrPath))
                        
{
                            FileName
=Foler.SelectedPath;
                            
if(FileName.LastIndexOf(@"\")==(FileName.Length-1))
                                FileName
=Foler.SelectedPath+TempName+@".xls";
                            
else
                                FileName
=Foler.SelectedPath+@"\"+TempName+@".xls";
                            
if(System.IO.File.Exists(FileName))
                            
{
                                MessageBox.Show(Foler.SelectedPath
+@"  已经存在文件"+TempName+@".xls","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                                
return;
                            }

                            xlSheet.SaveAs(FileName,missing, missing, missing, missing, missing, missing, missing, missing);

                        }

                    xlApp.Quit();
                    
if(FileName=="")
                        
return;
                    Excel.Application NewApp
=new Excel.Application();
                    Excel.Workbook NewBook;
                    Excel.Worksheet NewSheet;
                    NewBook 
= NewApp.Workbooks.Open(FileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
                    NewSheet 
= (Excel.Worksheet)NewBook.Worksheets[1];
                    NewApp.Visible 
= true;
                    MessageBox.Show(
"下载成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }

                
else
                
{
                    xlApp.Quit();
                    MessageBox.Show(
"没有成功下载模板","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }

                
            }

            
catch(Exception err)
            
{
                MessageBox.Show(err.Message,
"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

            }

        }