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("文档出现错误,请重新操作");        //     }        // }

  • 相关阅读:
    Html 中的Body 标签
    ROS-1.1-基本概念
    机器人的自由度
    机器人学(MATLAB机器人工具箱10.x)——4.1-雅克比矩阵(1)
    机器人学(MATLAB机器人工具箱10.x)——3.6-画字母
    机器人学(MATLAB机器人工具箱10.x)——3.5-特殊问题
    机器人学——3.4-轨迹规划
    OpenCV 3-2.4-工具函数
    OpenCV 3-2.3-辅助类
    OpenCV 3-2.2-进一步了解 OpenCV 基本数据类型
  • 原文地址:https://www.cnblogs.com/Ilin631/p/3370158.html
Copyright © 2011-2022 走看看