Exemple #1
0
        public static bool WordToHtml(string wordFileName, string htmlFileName)
        {
            try
            {
                Object oMissing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word._Application WordApp = new Microsoft.Office.Interop.Word.Application();
                WordApp.Visible = false;
                object    filename = wordFileName;
                _Document WordDoc  = WordApp.Documents.Open(ref filename, ref oMissing,
                                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                // Type wordType = WordApp.GetType();
                // 打开文件
                Type docsType = WordApp.Documents.GetType();
                // 转换格式,另存为
                Type   docType      = WordDoc.GetType();
                object saveFileName = htmlFileName;
                docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc,
                                     new object[] { saveFileName, WdSaveFormat.wdFormatHTML });

                //保存
                WordDoc.Save();
                WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(false);
            }
        }
Exemple #2
0
 public void Save()
 {
     if (m_Document != null)
     {
         m_Document.Save();
     }
 }
Exemple #3
0
    /// <summary>
    ///     Método responsável por inserir uma 'DataTable' em um documento do Word.
    /// </summary>
    /// <param name="DtDados">DataTable contendo os valores à serem inseridos</param>
    /// <param name="ApresentarDoc">'True' para apresentar o documento do Word ao término.</param>
    public void InsereDados_Documento(System.Data.DataTable DtDados, Boolean ApresentarDoc)
    {
        object missVal = System.Reflection.Missing.Value;

        if (DtDados != null && DtDados.Rows.Count > 0)
        {
            //mDoc = mWord.Documents.Add(_CaminhoArqWord, ref missVal, ref missVal, ref missVal);

            mTable = mDoc.Tables.Add(mWord.ActiveDocument.Range(), DtDados.Rows.Count, DtDados.Columns.Count, ref missVal, ref missVal);
            mTable.Range.ParagraphFormat.SpaceAfter = 7;

            for (int i = 0; i < DtDados.Rows.Count; i++)
            {
                for (int j = 0; j < DtDados.Columns.Count; j++)
                {
                    mTable.Cell(i, j).Range.Text = DtDados.Rows[i][j].ToString();
                }
            }

            //Gerava exceção com essas linhas
            //mTable.Rows[1].Range.Font.Bold = 1;
            //mTable.Rows[1].Range.Font.Italic = 1;
            //mTable.Borders.Shadow = true;

            if (ApresentarDoc)
            {
                ApresentaWord();
            }

            //Gerava exceção com essa linha
            // SaveAs2(mCaminhoArqWord);

            mDoc.Save();
        }
    }
 public void Save(_Document doc)
 {
     doc.Save();
 }
Exemple #5
0
 private void DocumentSaveAs(_Document aDoc)
 {
     aDoc.Save();
     aDoc.Close(ref _oMissing, ref _oMissing, ref _oMissing);
     _wordApp.Quit(ref _oMissing, ref _oMissing, ref _oMissing);
 }