如何使用c#从项目文件夹中删除xls表? [英] How to delete a xls sheet from the project folder using c# ?
本文介绍了如何使用c#从项目文件夹中删除xls表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用.Net Framework 3.5,并且正在使用
Hi,
I am currently using .Net framework 3.5 and in that I am making use of
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Runtime.InteropServices;
using Microsoft.Office.Core;
在代码的帮助下,我正在获取xls工作表"A"并进行一些修改,然后将其另存为"B"在同一文件夹中.现在,xls工作表"A"对我来说是浪费.如何删除?
我尝试使用worksheet.delete(),但是它生成了一个异常,指出文件应首先被隐藏,等等.你们中的任何一个都可以帮助我实现同样的目的. ?
我将非常感谢您.
By the help of code I am fetching xls sheet ''A'' and making some modifications and saving it as ''B'' in the same folder. Now, xls sheet ''A'' is waste for me. How can I delete it ?
I tried using worksheet.delete() but it generated a exception saying file should be unhidden first etc etc. Can any of you please help me to achieve the same thing. ?
I will be highly thankful to you.
推荐答案
尝试一下.我假设xls在根文件夹中.根据您的位置更改路径.
如果文件已打开,则将其关闭.
Try this. I assumed that xls is in root folder. Change path according to your location.
Close the file if it is open.
string path = Server.MapPath("MyTest.xls");
FileInfo fi1 = new FileInfo(path);
if(fi1.Exists)
fi1.Delete();
这篇关于如何使用c#从项目文件夹中删除xls表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文