Doc To RTF
来源:互联网 发布:mac 思维导图 知乎 编辑:程序博客网 时间:2024/05/01 06:08
using System;
using System.IO;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
namespace WinFormWord
{
public partial class FormWord : Form
{
#region
private Button docButton;
private RichTextBox richText;
private OpenFileDialog openFile;
private readonly string tempFilePath = Path.GetTempFileName();
#endregion
#region Form1
public FormWord()
{
InitializeComponent();
docButton = new Button();
docButton.Dock = DockStyle.Top;
docButton.Text = "读取Word文档(*.doc;*.docx)";
docButton.Click += new EventHandler(docButton_Click);
this.Controls.Add(docButton);
richText = new RichTextBox();
richText.AllowDrop = true;
richText.Dock = DockStyle.Fill;
richText.DragEnter += new DragEventHandler(richText_DragEnter);
this.Controls.Add(richText);
richText.BringToFront();
openFile = new OpenFileDialog();
openFile.Filter = "Word 文档(*.doc;*.docx)|*.doc;*.docx";
this.StartPosition = FormStartPosition.WindowsDefaultBounds;
}
#endregion
#region richText_DragEnter
private void richText_DragEnter(object sender, DragEventArgs e)
{
DataObject newData = e.Data as DataObject;
if (richText.EnableAutoDragDrop = !newData.ContainsFileDropList())
return;
string filePath = newData.GetFileDropList()[0];
if (Path.GetExtension(filePath).ToLowerInvariant().Contains(".doc"))
DocToRTF(filePath);
}
#endregion
#region DocToRTF
private void DocToRTF(string filePath)
{
Word.Application newWord = new Word.Application();
try
{
newWord.Visible = false;
object readOnly = true;
object fileName = filePath;
object missing = Type.Missing;
Word.Document doc = newWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
fileName = tempFilePath;
object format = Word.WdSaveFormat.wdFormatRTF;
doc.SaveAs(ref fileName, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
doc.Close(ref missing, ref missing, ref missing);
newWord.Quit(ref missing, ref missing, ref missing);
richText.LoadFile(tempFilePath);
this.Text = Path.GetFileName(filePath);
}
catch (Exception se)
{
MessageBox.Show(this, se.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
newWord = null;
GC.Collect();
}
}
#endregion
#region docButton_Click
private void docButton_Click(object sender, EventArgs e)
{
if (openFile.ShowDialog(this) == DialogResult.OK)
DocToRTF(openFile.FileName);
}
#endregion
#region OnFormClosing
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
File.Delete(tempFilePath);
}
#endregion
}
}
- Doc To RTF
- 把Doc文档转换成rtf格式
- 把Doc文档转换成rtf格式
- Windows下 .rtf 批量转换 .doc
- RTF field how to work
- 把Doc文档转换成rtf格式 [C#]
- RichTextBox读取Doc、txt、rtf三种格式
- 如何用C#把Doc文档转换成rtf格式
- java IO流(1)处理txt、rtf、doc、docx
- DOCX到RTF格式的转换器DOCX to RTF Converter
- VBA批量转换:docx转pdf、doc、rtf、txt以及doc转docx
- DOC TO CHM
- convert doc to docx
- ComponentOne Doc-To-Help 2009
- Print Documents From Delphi - Print PDF, DOC, XLS, HTML, RTF, DOCX, TXT
- poi实现word文档的导入(针对.doc .docx rtf)
- MS Word 组件Spire.Doc V6.0.5发布 | 修复了rtf 到pdf 的转换问题
- Clean RTF files to any encoding text file type
- PurgeComm()函数--清空缓冲区
- SetCommMask
- Linux下配置IP、DNS和路由
- IP-MAC扫描监视器早已完成
- oracle复习(二) 之扩展 设置数据库为只读
- Doc To RTF
- S3c2410触摸屏驱动移植
- 《C#图解教程》读书笔记第15章——委托
- C#类==>属性
- ASP.NET生成随机密码
- 进步一点点
- 深入浅出Win32多线程程序设计之综合实例
- 利用Axis2开发WebService(6)---axis2 传递对象数组,非stub方式
- 正则表达式笔记之四