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

  • 相关阅读:
    Docker 容器间的单向连接
    使用 mysql 的 Docker 镜像
    Dockerfile 自动制作 Docker 镜像(三)—— 镜像的分层与 Dockerfile 的优化
    Dockerfile 自动制作 Docker 镜像(一)—— 基本命令
    在 Docker 的 CentOS7 镜像 中安装 mysql
    手动制作Docker镜像
    Docker容器基本命令注意点
    Linux基础15-Linux库函数
    Linux基础14-makefile
    Linux基础13-GDB调试
  • 原文地址:https://www.cnblogs.com/Ilin631/p/3370158.html
Copyright © 2011-2022 走看看