菜鸟提问!关于文件转换问题?

Nicholasqpl 2005-05-30 10:07:56
我利用程序想把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";
}
...全文
130 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gccr 2005-05-31
  • 打赏
  • 举报
回复
可以那么做吗?
不知道。
凨叔 2005-05-31
  • 打赏
  • 举报
回复
我们以前是这样做的,找到Excel.exe或者Excel.dll(好像Office2000是Excel.olb),用.NET命令tlbimp导出成一个Excel.dll,再在项目中引用,就可以操作Excel了。
Nicholasqpl 2005-05-31
  • 打赏
  • 举报
回复
to: sunjian_qi(sonne)
我知道有专门基于word可以转成很多文件格式的类.
但是不知道有没有专门基于Excel可以转成很多文件格式的类呢?
凨叔 2005-05-31
  • 打赏
  • 举报
回复
你可以用代码打开Excel文件,然后操作Excel对象让它另存为txt文件就行了。
Nara 2005-05-31
  • 打赏
  • 举报
回复
虽然我不太清楚Excel的编码格式,但我想肯定不是简单的文本格式吧。你只是将文件的内容照搬,再将后缀名改了,得到的当然是乱码了
Nicholasqpl 2005-05-31
  • 打赏
  • 举报
回复
哎~~没任知道吗?
高手都到哪里去啦
Nicholasqpl 2005-05-31
  • 打赏
  • 举报
回复
up
ofei 2005-05-30
  • 打赏
  • 举报
回复
把文件读出去再写到文本文件里

没试过`~~

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧