我利用程序想把Excel文件的后缀名.xls改成.txt,但是里面的内容都变成乱码了,不知道该怎么解决啊?
我的代码如下:
//获得该路径全部文件名
string [] fileNames = Directory.GetFiles(FilePath); string newNm = "";
string FileNmTmp = "";
string strPath = "";
foreach(string fileNm in fileNames)
{
strPath = fileNm.Substring(0,fileNm.LastIndexOf(@"\")+1);
FileNmTmp = fileNm.Substring(fileNm.LastIndexOf('\\')+1);
FileNmTmp = FileNmTmp.Substring(0,4);
switch(FileNmTmp)
{
case "If25":
newNm = m_rep_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
case "If28":
newNm = m_Pro_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
case "If42":
newNm = m_grp_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
default:
newNm = fileNm.Substring(fileNm.LastIndexOf('\\')+1);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
}
//File.Move(fileNm,strPath + newNm);
File.Copy(fileNm,strPath + newNm,true);
File.Delete(fileNm);
this.txtNewFile.Text += newNm + "\r\n";
}
我的代码如下:
//获得该路径全部文件名
string [] fileNames = Directory.GetFiles(FilePath); string newNm = "";
string FileNmTmp = "";
string strPath = "";
foreach(string fileNm in fileNames)
{
strPath = fileNm.Substring(0,fileNm.LastIndexOf(@"\")+1);
FileNmTmp = fileNm.Substring(fileNm.LastIndexOf('\\')+1);
FileNmTmp = FileNmTmp.Substring(0,4);
switch(FileNmTmp)
{
case "If25":
newNm = m_rep_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
case "If28":
newNm = m_Pro_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
case "If42":
newNm = m_grp_Prefix + fileNm.Substring(fileNm.LastIndexOf('\\')+5);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
default:
newNm = fileNm.Substring(fileNm.LastIndexOf('\\')+1);
newNm = newNm.Substring(0,newNm.LastIndexOf('.')) + ".txt";
break;
}
//File.Move(fileNm,strPath + newNm);
File.Copy(fileNm,strPath + newNm,true);
File.Delete(fileNm);
this.txtNewFile.Text += newNm + "\r\n";
}
我知道有专门基于word可以转成很多文件格式的类.
但是不知道有没有专门基于Excel可以转成很多文件格式的类呢?