dsoframer controls dynamically loaded

The dsoframer control register 1. Before use, I put the dso controls as embedded resources, methods 1 study notes can be registered with
  /// <the Summary>
  /// UserControl control is initialized
  /// </ the Summary>
  // / <param name = "_ sFilePath "> local file full path </ param>
  public void the Init (String _sFilePath)
  {
   the try
   {
    RegControl (); // Register control
    (! CheckFile (_sFilePath)) if // determines whether supported the office file
    {
     the throw new new ApplicationException ( "file format or identity does not exist!");
    }
    AddOfficeControl (); // here we must first control dso dso added to the interface to initialize the control, no control in this dso can not be initialized before the operation is show up, very strange why 

        // What OF consider this .....
    InitOfficeControl (_sFilePath);
   }
   the catch (Exception EX)
   {
    the throw EX;
   }
  }

  public bool RegControl()
    {
      try
      {
        Assembly thisExe = Assembly.GetExecutingAssembly();
        System.IO.Stream myS = thisExe.GetManifestResourceStream("NameSpaceName.dsoframer.ocx");
  
        string sPath = “该ocx文件的实际路径”+ @"/dsoframer.ocx";
        ProcessStartInfo psi = new ProcessStartInfo("regsvr32","/s " +sPath);
        Process.Start(psi);
      }
      catch(Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
     return true;
    }

2. instance to dynamically add dsoframer UserControl
                Private AxDSOFramer.AxFramerControl m_axFramerControl new new AxDSOFramer.AxFramerControl = ();
  /// <Summary>
  /// Add controls
  /// </ Summary>
  Private void AddOfficeControl ()
  {
   the try
   {
    this.m_Panel_Control .Controls.Add (m_axFramerControl);
    m_axFramerControl.Dock = DockStyle.Fill;
   }
   the catch (Exception EX)
   {
    the throw EX;
   }
  }
3. dsoframer initialization control, I used here already have dso initialization file,
  /// <Summary >
  /// initialization office control
  /// </ the Summary>
  /// <param name = "_ sFilePath"> local document path </ param>
  private void InitOfficeControl(string _sFilePath)
  {
   The try
   {
    IF (m_axFramerControl == null)
    {
     the throw new new ApplicationException ( "Please initialize the control object office!");
    }
    
    //This.m_axFramerControl.SetMenuDisplay(48);// this method is very special, the menu control method of a combination of I have yet to find the law parameters, interested friends can look
    String sext = System.IO.Path.GetExtension (_sFilePath) .Replace (, "" ".");
    //this.m_axFramerControl.CreateNew(this. LoadOpenFileType (sExt)); // create a new file
    this.m_axFramerControl.Open (_sFilePath, false, this.LoadOpenFileType ( sExt), "", ""); // open the file
    // hide the title
    this.m_axFramerControl.Titlebar = to false;
   }
   the catch (Exception EX)
   {
    the throw EX;
   }
  }

     The following parameter is required when a file is opened dso representative office file type
  /// <Summary>
  /// The suffix obtained Open
  /// </ Summary>
  /// <param name = "_ Sexten"> </ param>
  /// <Returns> </ Returns>
  Private LoadOpenFileType String (String _sExten)
  {
   the try
   {
    String sOpenType = "";
    Switch (_sExten.ToLower ())
    {
     Case "XLS":
      sOpenType = "Excel.Sheet ";
      BREAK;
     Case" DOC ":
      sOpenType =" Word.Document ";
      BREAK;
     Case" PPT ":
      sOpenType =" PowerPoint.Show ";
      BREAK;
     Case"vsd":
      sOpenType = "Visio.Drawing";
      break;
     default:
      sOpenType = "Word.Document";
      break;
    }
    return sOpenType;

   }
   catch (Exception ex)
   {
    throw ex;
   }
  }

4. I think the most important step is to publish dso current active object, because they do this usercontrol function is not strong, but not to kill the people dso function, leaving the user with a larger space. . . .
  /// <Summary>
  /// Get the document currently operating
  /// </ Summary>
  public Object the ActiveDocument
  {
   GET
   {
    return this.m_axFramerControl.ActiveDocument;
   }
  }

  /// <Summary>
  /// Gets the current control object
  /// </ Summary>
  public AxDSOFramer.AxFramerControl OfficeObject
  {
   GET
   {
    return this.m_axFramerControl;
   }
  }
5. The published word and excel simple method of operation,
  #region public word method, this method is only effective for a few word documents

  /// <the Summary>
  /// set to retain traces of modification (modifying word may be approved toolbar, this method is only to provide initialization)
  /// This method is very good, can simulate keyboard keys, very clever ah. (Formerly very such time may not know ...)
  /// </ Summary>
  /// <param name = "_ BIS"> </ param>
  public void WordSetSaveTrace ()
  

  /// <Summary>
  /// Alternatively the tag
  /// </ Summary>
  /// <param name = "_ Smark"> </ param>
  /// <param name = "_ sReplaceText"> </ param>
  / // <param name = "_ IsD "> Alternatively if the highlighted </ param>
  /// <Returns> </ Returns>
  public BOOL WordReplace (_sMark String, String _sReplaceText, BOOL _IsD)
  

  /// <summary>
  /// 文本替换
  /// </summary>
  /// <param name="_sOrialText"></param>
  /// <param name="_sReplaceText"></param>
  /// <returns></returns>
  public bool WordReplace(string _sOrialText,string _sReplaceText)
  

  #endregion

  #region public excel method

  /// <Summary>
  /// fixed position to the fill value
  /// </ Summary>
  /// <param name = "_ sValue"> Fill SUMMARY </ param>
  /// <param name = "_ iBeginRow"> Start OK </ param>
  /// <param name = "_ iBeginCol"> the starting column </ param>
  public void ExcelFillValue (String _sValue, _iBeginRow int, int _iBeginCol)
  

  /// <Summary>
  /// fixed position to the fill value
  /// </ Summary>
  /// <param name = "_ sValue"> fill-out </ param>
  /// <param name = "_ iBeginRow"> Start OK </ param>
  /// <param name = "_ iBeginCol"> the starting column </ param>
  public void ExcelFillValue (Object _sValue, _iBeginRow int, int _iBeginCol)
  

  /// <Summary>
  /// fixed position to the fill value
  /// </ Summary>
  /// <param name = "_ DS"> Fill SUMMARY </ param>
  /// <param name = "_ iBeginRow"> Start OK </ param>
  /// <param name = "_ iBeginCol"> the starting column </ param>
  public void ExcelFillValue (a System.Data.DataSet _ds, _iBeginRow int, int _iBeginCol, BOOL _IsTitle)
  

  /// <Summary>
  /// Empty excel document
  /// </ Summary>
  public void ExcelClear ()
  

  /// <summary>
  SUMMARY emptying /// fixed position
  /// </ Summary>
  /// <param name = "_ iBeginRow"> Start OK </ param>
  /// <param name = "_ iBeginCol"> Start column </ param>
  public void ExcelClear (_iBeginRow int, int _iBeginCol)
  

  /// <Summary>
  /// emptying the contents of the specified region
  /// </ Summary>
  /// <param name = "_ iBeginRow"> Start OK </ param>
  /// <param name = "_ iBeginCol"> Start column </ param>
  /// <param name = "_ iEndRow"> end of line </ param>
  /// <param name = "_ iEndCol"> end column </ param>
  public void ExcelClear (int _iBeginRow, _iBeginCol int, int _iEndRow, int _iEndCol)
  
  #endregion
    these are the pediatrician to excel and word document manipulation, fear of posted prawn laughed, not posted .....

6. announced some simple methods (Save and Save As to save the method can not prevent the case of menus and toolbars are hidden), these should have a lot of ways, I currently only use one of these so ....
  /// <Summary>
  /// save
  /// </ Summary>
  public void the save ()
  {
   the try
   {
    // first save
    this.m_axFramerControl.Save (to true, to true, "", "");
   }
   the catch (Exception EX)
   {
    EX the throw;
   }
  }


  /// <summary>
  /// 另存为
  /// </summary>
  public void SaveAs()
  {
   try
   {
    //另存为
    SaveFileDialog sfd = new SaveFileDialog();
    string sExt = System.IO.Path.GetExtension(this.m_sFilePath).Replace(".","");
    sfd.Filter = sExt;
    if(sfd.ShowDialog() == DialogResult.OK)
    {
     string sSavePath = sfd.FileName;
     if(System.IO.File.Exists(sSavePath))
     {
      System.IO.File.Delete(sSavePath);
     }
     this.m_axFramerControl.SaveAs(sSavePath,this.LoadOpenFileType(sExt));
    }
   }
   catch(Exception ex)
   {
    throw ex;
   }
  }

  /// <summary>
  /// 关闭当前界面
  /// </summary>
  public void Close()
  {
   try
   {
    if(this.m_axFramerControl != null)
    {
     this.m_axFramerControl.Close();
    }
   }
   catch(Exception ex)
   {
    throw ex;
   }
  }

Guess you like

Origin www.cnblogs.com/guoxuen/p/11368231.html