zoukankan      html  css  js  c++  java
  • 导入word数据

     public static List<FL> ImportDOC(object fileName,out StringBuilder meg)        {            

    List<FL> flist = new List<FL>();            

    Application app = new Application();            

    Document doc = new Document();          

      meg = new StringBuilder();           

    try            {             

       #region 导入word数据               

    //打开文件                if (app.Documents.Count > 0)         

           {                    //if (MessageBox.Show("已经打开了一个word文档,你想关闭重新打开该文档吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)      

                  //{                 

       //    object unknow = Type.Missing;         

               //    doc = app.ActiveDocument;     

                   //    if (MessageBox.Show("你想保存吗?", "保存", MessageBoxButtons.YesNo) == DialogResult.Yes)                 

       //    {                   

    //        app.ActiveDocument.Save();             

           //    }

                       //    app.ActiveDocument.Close(ref unknow, ref unknow, ref unknow);                

        //    app.Visible = false;            

            //}              

          //else                

        //{                  

      //    return;              

          //}              

      }            

        else                {               

         object unknow = Type.Missing;          

         app.Visible = true;                

        doc = app.Documents.Open(ref fileName,      

       ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,                                    

         ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,                                            

    ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);

                   }                             

    #region 读取数据               

    int docCount=doc.Paragraphs.Count;//world数据行数               

    if (docCount> 0)                {                                    

     f f = new f();                                     

    for (int i = 1; i < docCount; i++)                    {                              

    string linedate=doc.Paragraphs[i].Range.Text.Trim();                              

    if (linedate.Contains("<MessageType>"))                              

    {                                  

    if (!linedate.Contains("N"))                                   {                                      

    meg.Append("文件类型不对");//文件类型不对不予理会                                

           break;                                

       }                            

       }                             

      if (!string.IsNullOrEmpty(getlinedata(linedate, "CallSign")))                        

           {                                   f.FLIGHTID = getlinedata(linedate, "CallSign");                    

               }                            

       if (!string.IsNullOrEmpty(getlinedata(linedate, "ScheduleDate")))                      

             {                            

           f.SCHEDULEDATE =getlinedata(linedate, "ScheduleDate");                         

          }                                           

    if (linedate.Contains("</Item>"))                          

    {                              

    flist.Add(f);                              

    f = new f();                         

      }                               

            }                                            

                   }               

    #endregion               

    //关闭文件               

    object unknow1 = Type.Missing;               

    object saveChanges1 = WdSaveOptions.wdPromptToSaveChanges;               

    app.ActiveDocument.Close(ref saveChanges1, ref unknow1, ref unknow1);

                   //关闭程序               

    object unknow2 = Type.Missing;               

    object saveChanges2 = WdSaveOptions.wdSaveChanges;               

    app.Quit(ref saveChanges2, ref unknow2, ref unknow2);               

    #endregion

               }           

    catch (Exception e)           

    {               

    meg.Append(e.Message);           

    }

               return flist;          

               //string text2 = Regex.Replace(wordDoc.Content.Text, @"(a|t|n|s+)", "");  //Regex.Replace(input, @"(a|t|n|s+)", "")        }

            public static string getlinedata(string linedate,string oldstr)         {             string  str=string.Empty;             try             {                 if (linedate.Contains("<" + oldstr + ">"))                 {                     str = linedate.Replace("<"+oldstr+">", string.Empty).Replace("</"+oldstr+">", string.Empty);                                     }                             }             catch (Exception e)             {                         }             return str;         }        //public static void replaceChar()        //{        //     try        //     {        //         object replaceAll =WdReplace.wdReplaceAll;        //         object missing = Type.Missing;

           //         app.Selection.Find.ClearFormatting();        //         app.Selection.Find.Text = "^l";

           //         app.Selection.Find.Replacement.ClearFormatting();        //         app.Selection.Find.Replacement.Text = "^p";

           //         app.Selection.Find.Execute(        //             ref missing, ref missing, ref missing, ref missing, ref missing,        //             ref missing, ref missing, ref missing, ref missing, ref missing,        //             ref replaceAll, ref missing, ref missing, ref missing, ref missing);        //     }        //     catch (Exception e)        //     {        //         //MessageBox.Show("文档出现错误,请重新操作");        //     }        // }

  • 相关阅读:
    Python环境搭建后,多种方式的使用进行程序的执行。
    Visual Studio 2017进行Python开发环境的搭建,使用VS2017进行python代码的编写。
    Linux Ubuntu运行线程程序出现undefined reference to ‘pthread_create’和undefined reference to ‘pthread_join’错误。
    计算机二级-C语言-程序填空题-190107记录
    2018/03/08 每日一学PHP 之 常量defind 和 const区别
    H5手机页面剖析
    jQuery(三)
    jQuery(二)
    jQuery(一)
    JS构造函数(便于理解,简易)
  • 原文地址:https://www.cnblogs.com/Ilin631/p/3370158.html
Copyright © 2011-2022 走看看