1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| private void ConvertRTFtoTXT()
{
// Intantiating Word
Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
// Open the Word document
Word.Document wordDoc = null;
object missing = System.Reflection.Missing.Value;
object openFileName = RTFFileName;
object saveAsFileName = TXTFileName;
object no = false;
object yes = true;
object saveFormat = Word.WdSaveFormat.wdFormatText;
try
{
wordDoc = word.Documents.Open(ref openFileName, ref missing, ref no, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref yes, ref missing, ref missing, ref missing, ref missing);
}
catch (System.Exception sysex)
{
MessageBox.Show(sysex.ToString());
}
// Save the document as a TXT file
try
{
wordDoc.SaveAs(ref saveAsFileName, ref saveFormat, 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);
// Showing the conversion is done
toolStripStatusLabel.Text = "Conversion processed successfully.";
}
catch (System.Exception sysex)
{
MessageBox.Show(sysex.ToString());
}
finally
{
if (wordDoc != null)
{
wordDoc.Close(ref no, ref missing, ref missing);
}
word.Quit(ref no, ref missing, ref missing);
}
} |
Partager