⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 生成并下载excel文件(com方法2).txt

📁 C# 是创新性的新式编程语言
💻 TXT
字号:
public void ToExcel3(string FileName)
		{		

			Application xlApp=new ApplicationClass();		
			Workbook xlBook=xlApp.Workbooks.Add(Missing.Value);
			Worksheet xlSheet=(Worksheet)xlBook.Sheets[1];
			xlApp.Cells[1,1]="名称";
			xlApp.Cells[1,2]="种类";			

			Range rng = xlApp.get_Range("B1", "B1");//B1为Excel的坐标
			
			if (rng.Comment != null ) 
			{
				rng.Comment.Delete();
			}
			rng.AddComment("Comment added " + DateTime.Now);
			
			//建立一个专门存放Excel文件的目录
			string cd="";
			cd=Page.Server.MapPath("..\\..\\")+"ExcelFolder\\";
			if(!Directory.Exists(cd))
				Directory.CreateDirectory(cd);
			//删除服务端临时文件: download.xls
			if(File.Exists(cd+"download.xls"))
				File.Delete(cd+"download.xls");
			//在服务端保存download.xls,Missing.Value 来自System.Reflection; 命名空间
			xlSheet.SaveAs(cd+"download.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,
				Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value); 

			//杀死Excel进程
			Process []procs=Process.GetProcessesByName("excel");
			foreach(Process proc in procs)
			{
				if(!proc.CloseMainWindow())
					proc.Kill();
			}

		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -