当我保存要保存的新excel文件时,已经保存在excel中的文件被删除。在保存现有的Excel之前要删除 [英] Already save filed in excel to be delete when i save the new excel file to be saved.before saving the existing excel to be deleted
问题描述
在保存要保存的excel文件之前,已经保存在excel中的文件被删除。在保存要删除的现有excel文件之前。
保存excel代码如下;
xlWorkBook.SaveAs(@C:\CourseWiseReport.xls,Excel.XlFileFormat.xlWorkbookNormal,misValue,misValue,misValue,misValue,Excel .XlSaveAsAccessMode.xlExclusive,misValue,misValue,misValue,misValue,misValue);
保存excel文件之前我想查看excel文件已保存在c文件夹中。如果有擅长删除,我的代码如下;
string root = @C:\Course Wise Report.xls;
if(File.Exists(root))
{
File.Delete(root);
}
文件那个旧的例外l在要删除的c文件夹中。
我的上述代码无效。
已保存的excel文件未删除c文件夹。
当我保存它时显示如下消息;
A文件名C:\Coursewisereport.xls已经存在在这个位置。你想要更换吗?
是否取消。
我的上面怎么办。请更正我的代码并帮助我。
Already save filed in excel to be delete when i save the excel file to be saved.before saving the existing excel file to be deleted.
Save an excel code as follows;
xlWorkBook.SaveAs(@"C:\CourseWiseReport.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
Before Saving the excel file i want to check the excel file is already saved in c folder.if there that excel to be deleted, for that my code as follows;
string root = @"C:\Course Wise Report.xls";
if (File.Exists(root))
{
File.Delete(root);
}
before saving an excel file that old excel in c folder to be deleted.
for my above code it is not working.
the already saved excel file is not deleting in c folder.
when i save it shows the message as follows;
A File name "C:\Coursewisereport.xls already exists in this location. do u want to replace it?
Yes No Cancel.
from my above how can i do.Please correct my code and help me.
推荐答案
试试这个:
注意:确保您的目标文件未被应用程序使用,或者使用MS Excel打开
Hi,
Try this:
NOTE: make sure that your target file is not being used by an application, or open with MS Excel
public static void MoveOrReplaceFile( string source, string destination ) {
if( source == null ) throw new ArgumentNullException( "source" );
if( destination == null ) throw new ArgumentNullException( "destination" );
if( File.Exists( destination ) ) {
// File.Replace does not work across volumes
if( Path.GetPathRoot( Path.GetFullPath( source ) ) == Path.GetPathRoot( Path.GetFullPath( destination ) ) ) {
File.Replace( source, destination, null, true );
} else {
File.Copy( source, destination, true );
}
} else {
File.Move( source, destination );
}
}
干杯,
Edo
Cheers,
Edo
这篇关于当我保存要保存的新excel文件时,已经保存在excel中的文件被删除。在保存现有的Excel之前要删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!