首页 > 代码库 > Word 2007 转 Word2003格式 docx2doc

Word 2007 转 Word2003格式 docx2doc

啥也不说了,直接上代码。

    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            var dilog = new OpenFileDialog();
            dilog.RestoreDirectory = true;
            dilog.AddExtension = true;
            dilog.CheckFileExists = true;
            dilog.DefaultExt = "*.docx";
            dilog.Multiselect = true;
            dilog.Filter = "Word 2010 (*.docx))|*.docx";
            if (dilog.ShowDialog() == DialogResult.OK || dilog.ShowDialog() == DialogResult.Yes)
            {
                var files = dilog.FileNames;
                if (files == null || files.Length < 1)
                {
                    MessageBox.Show("未找到docx,请再重新选择文件夹");
                    return;
                }
                Log($"将开始转换{files.Length}个文件");

                var wordApp = new Microsoft.Office.Interop.Word.Application();

                foreach (var item in files)
                {
                    if (!File.Exists(item) || !item.EndsWith(".docx"))
                    {
                        Log($"文件{item}不适合转换");
                        continue;
                    }

                    var src = http://www.mamicode.com/item;"开始转换{src}");
                    try
                    {
                        Docx2Doc(wordApp, src, dst);
                        Log($"转换成功{dst}");
                    }
                    catch (Exception ex)
                    {
                        Log($"转换失败{ex}");
                    }
                }

                //关闭进程  
                object saveOption = WdSaveOptions.wdDoNotSaveChanges;
                object missingValue = http://www.mamicode.com/System.Reflection.Missing.Value;"{msg}\r\n{txtLog.Text}";
            if(txtLog.Text.Length > 5000)
            {
                txtLog.Text = txtLog.Text.Substring(0, 5000);
            }
        }


        static void Docx2Doc(Microsoft.Office.Interop.Word.Application wordApp, object sourceFileName, object targetFileName)
        {
            object missingValue = http://www.mamicode.com/System.Reflection.Missing.Value;>

 

Word 2007 转 Word2003格式 docx2doc