c#保存word的问题 我想用c#实现对word的操作。我对流的概念比较模糊,那位大侠能帖出一段对word保存以及读取的代码,让我研究以下,不胜感激 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自己看看,并实验一下吧。追加文件(文件不存在创建)public void WriteFile(string users,string content) { try { string path=@"bin\leaveword.log"; string mDate=DateTime.Now.ToShortDateString(); if(!File.Exists(Server.MapPath(path))) { StreamWriter SW=File.CreateText(Server.MapPath(path)); SW.WriteLine(users+"\t"+mDate+"\t"+content); SW.Close(); } else { StreamWriter SW=File.AppendText(Server.MapPath(path)); SW.WriteLine(users+"\t"+mDate+"\t"+content); SW.Close(); } } catch(Exception ee) { throw new Exception(ee.Message); } }创建文件public void CreateFile() { string path=""; try { if(!File.Exists(path)) { FileStream FS=File.Create(path); Byte[] info={0,0,0,0,0,0,}; FS.Write(info,0,info.Length); FS.Close(); } } catch(Exception ee) { } }拷贝文件public void CopyFile() { string path=""; try { if(!File.Exists(orgin_path)) { return; } if(File.Exists(object_path)) { return; } File.Copy(orgin_path,object_path); } catch(Exception ee) { } }移动文件public void MoveFile() { string path=""; try { if(!File.Exists(orgin_path)) { return; } if(File.Exists(object_path)) { return; } File.Move(orgin_path,object_path); } catch(Exception ee) { } }删除文件public void DeleteFile() { string path=""; try { if(!File.Exists(path)) { return; } File.Delete(orgin_path,object_path); } catch(Exception ee) { } }读取文件信息public void FileInfo() { string path=""; FileInfo FI=new FileInfo(path); try { if(!FI.Exists) { return; } FI.DirectoryName;//文件路径 FI.Length;//文件大小 FI.CreationTime;//创建时间 FI.LastWriteTime;//最后修改时间 FI.Attributes;//文件属性 } catch(Exception ee) { } }创建文件夹public void CreateDirectory() { string path=""; try { if(Directory.Exists(path)) { return; } DirectoryInfo DirInfo=Directory.CreateDirectory(path); Directory.GetCreationTime(path);//创建时间 } catch(Exception ee) {} }移动文件夹public void MoveDirectory() { string path=""; try { if(!Directory.Exists(source_path)) { return; } if(Directory.Exists(object_path)) { return; } Directory.Move(source_path,object_path); } catch(Exception ee) {} }删除文件夹public void MoveDirectory() { string path=""; try { if(!Directory.Exists(path)) { return; } Directory.Delete(path); } catch(Exception ee) {} } ProcessFileInfoDirectoryInfo FileInfo fifOut; // FileStream fsOut = new FileStream(); ApplicationClass acsOut = new ApplicationClass(); object strPash = @"d:\my.doc"; object Nothing=System.Reflection.Missing.Value; Word.Document dctOut; dctOut =acsOut.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); dctOut.Paragraphs .Last .Range .Text ="aaaaaa"; dctOut.Paragraphs.First.Range.Text = "bbbb"; //bool blFlag = File.Exists(strPash .ToString ()); //if (blFlag) //{ // File.Delete(strPash.ToString()); //} dctOut.SaveAs(ref strPash ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ); dctOut .Close (ref Nothing ,ref Nothing ,ref Nothing ); acsOut .Quit (ref Nothing ,ref Nothing ,ref Nothing ); 建SQL表时身份证号码的数据类型最好选什么? 以下代码如何修改 C# 图层问题 程序执行中关机时,是不是所有运行中的winform都会收到关机的消息? C# 编译时加密 请教一条 sql 查询语句 如何给Columns赋值 库文件 在.net中如何操作配置文件 各位新年好,有个问题,关于XML的,帮我看下,谢了 C#中怎么把oralce数据库中的数据导入*.dbf文件中 这是什么问题
{
try
{
string path=@"bin\leaveword.log";
string mDate=DateTime.Now.ToShortDateString();
if(!File.Exists(Server.MapPath(path)))
{
StreamWriter SW=File.CreateText(Server.MapPath(path));
SW.WriteLine(users+"\t"+mDate+"\t"+content);
SW.Close(); }
else
{
StreamWriter SW=File.AppendText(Server.MapPath(path));
SW.WriteLine(users+"\t"+mDate+"\t"+content);
SW.Close();
}
}
catch(Exception ee)
{
throw new Exception(ee.Message);
}
}创建文件
public void CreateFile()
{
string path="";
try
{
if(!File.Exists(path))
{
FileStream FS=File.Create(path);
Byte[] info={0,0,0,0,0,0,};
FS.Write(info,0,info.Length);
FS.Close();
}
}
catch(Exception ee)
{ }
}
拷贝文件
public void CopyFile()
{
string path="";
try
{
if(!File.Exists(orgin_path))
{
return;
}
if(File.Exists(object_path))
{
return;
}
File.Copy(orgin_path,object_path);
}
catch(Exception ee)
{
}
}移动文件
public void MoveFile()
{
string path="";
try
{
if(!File.Exists(orgin_path))
{
return;
}
if(File.Exists(object_path))
{
return;
}
File.Move(orgin_path,object_path);
}
catch(Exception ee)
{
}
}删除文件public void DeleteFile()
{
string path="";
try
{
if(!File.Exists(path))
{
return;
}
File.Delete(orgin_path,object_path);
}
catch(Exception ee)
{
}
}读取文件信息public void FileInfo()
{
string path="";
FileInfo FI=new FileInfo(path);
try
{
if(!FI.Exists)
{
return;
}
FI.DirectoryName;//文件路径
FI.Length;//文件大小
FI.CreationTime;//创建时间
FI.LastWriteTime;//最后修改时间
FI.Attributes;//文件属性
}
catch(Exception ee)
{
}
}
创建文件夹
public void CreateDirectory()
{
string path="";
try
{
if(Directory.Exists(path))
{
return;
}
DirectoryInfo DirInfo=Directory.CreateDirectory(path);
Directory.GetCreationTime(path);//创建时间
}
catch(Exception ee)
{}
}移动文件夹
public void MoveDirectory()
{
string path="";
try
{
if(!Directory.Exists(source_path))
{
return;
}
if(Directory.Exists(object_path))
{
return;
}
Directory.Move(source_path,object_path); }
catch(Exception ee)
{}
}删除文件夹
public void MoveDirectory()
{
string path="";
try
{
if(!Directory.Exists(path))
{
return;
}
Directory.Delete(path); }
catch(Exception ee)
{}
}
FileInfo
DirectoryInfo
FileInfo fifOut;
// FileStream fsOut = new FileStream();
ApplicationClass acsOut = new ApplicationClass();
object strPash = @"d:\my.doc"; object Nothing=System.Reflection.Missing.Value;
Word.Document dctOut; dctOut =acsOut.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); dctOut.Paragraphs .Last .Range .Text ="aaaaaa";
dctOut.Paragraphs.First.Range.Text = "bbbb";
//bool blFlag = File.Exists(strPash .ToString ());
//if (blFlag)
//{
// File.Delete(strPash.ToString());
//}
dctOut.SaveAs(ref strPash ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing
,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing ,ref Nothing );
dctOut .Close (ref Nothing ,ref Nothing ,ref Nothing );
acsOut .Quit (ref Nothing ,ref Nothing ,ref Nothing );