北京保健按摩小妹,怎么做芝士蛋糕,孕妇胎教音乐大全
有想直接从word转txt文本的可以看看,懒得复制粘贴的也可以使用下,方便而快捷!!
首先打开vs2012创建一个简单的form窗体:
里面主要的就是一个存放word文档的button和一个执行的button
点击运行后:把实验的word文档导入文件中:
点击开始转换的button,进行执行文件:
点击确定实现整个过程,打开txt文档:
核心代码部分:
namespace wordtotext
{
public partial class form1 : form
{
public form1()
{
initializecomponent();
}
public static void wordtohtmltext(string wordfilepath)
{
try
{
word.application wapp = new word.application();
//指定原文件和目标文件
object docpath = wordfilepath;
string htmlpath = wordfilepath.substring(0, wordfilepath.length - 3) + "txt";
object target = htmlpath;
//缺省参数
object unknown = type.missing;
//只读方式打开
object readonly = true;
//打开doc文件
word.document document = wapp.documents.open(ref docpath, ref unknown,
ref readonly, ref unknown, ref unknown,
ref unknown, ref unknown, ref unknown,
ref unknown, ref unknown, ref unknown,
ref unknown);
object format = word.wdsaveformat.wdformattext;
document.saveas(ref target, ref format,
ref unknown, ref unknown, ref unknown,
ref unknown, ref unknown, ref unknown,
ref unknown, ref unknown, ref unknown);
document.close(ref unknown, ref unknown, ref unknown);
wapp.quit(ref unknown, ref unknown, ref unknown);
}
catch (exception e)
{
messagebox.show(e.message);
}
}
private void button2_click(object sender, eventargs e)
{
if (textbox1.text != "")
{
wordtohtmltext(textbox1.text.trim());
messagebox.show("转换成功,在word文件的同一目录下可找到txt数据!");
}
}
private void button1_click(object sender, eventargs e)
{
if (openfiledialog1.showdialog() == dialogresult.ok)
textbox1.text = openfiledialog1.filename;
}
}
}
有兴趣的可以自己动手试试!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
asp.net搭建博客,使用BlogEngine.NET+MySql搭建博客
网友评论