DSO Framer _ WinForm

Source: Internet
Author: User

According to your own learning of the dsoframer control, to simply package the dsoframer control as the usercontrol of C #, you need to do the following: (the process of creating a windows usercontrol will not be repeated ...)
We have not made much research on the network file opening and file uploading functions of dso for the moment. As a result, because I do not need this function, secondly, we do think that this feature is not very powerful and can be used in comparison.
Please forgive me!
1. register the dsoframer control before using it. I use this dso control as an embedded resource and register it using the method in Study Notes 1.
/// <Summary>
/// Usercontrol control Initialization
/// </Summary>
/// <Param name = "_ sFilePath"> full local file path </param>
Public void Init (string _ sFilePath)
{
Try
{
RegControl (); // register the control
If (! CheckFile (_ sFilePath) // checks whether the file is a supported office file
{
Throw new ApplicationException ("the file format does not exist or is not identified! ");
}
AddOfficeControl ();
// You must add the dso control to the interface before initializing the dso control,
// This dso control cannot be initialized before it is displayed. It is strange why the author considers this .....
InitOfficeControl (_ sFilePath );
}
Catch (Exception ex)
{
Throw ex;
}
}

Public bool RegControl ()
{
Try
{
Assembly thisExe = Assembly. GetExecutingAssembly ();
System. IO. Stream myS = thisExe. GetManifestResourceStream ("NameSpaceName. dsoframer. ocx ");

String sPath = "actual path of the ocx file" + @ "/dsoframer. ocx ";
ProcessStartInfo psi = new ProcessStartInfo ("regsvr32", "/s" + sPath );
Process. Start (psi );
}
Catch (Exception ex)
{
MessageBox. Show (ex. Message );
}
Return true;
}

2. dynamically Add a dsoframer instance to usercontrol
Private AxDSOFramer. AxFramerControl m_axFramerControl = new AxDSOFramer. AxFramerControl ();
/// <Summary>
/// Add controls
/// </Summary>
Private void AddOfficeControl ()
{
Try
{
This. m_Panel_Control.Controls.Add (m_axFramerControl );
M_axFramerControl.Dock = DockStyle. Fill;
}
Catch (Exception ex)
{
Throw ex;
}
}
3. initialize the dsoframer control. Here I use an existing file for dso initialization,
/// <Summary>
/// Initialize the office Control
/// </Summary>
/// <Param name = "_ sFilePath"> Local Document path </param>
Private void InitOfficeControl (string _ sFilePath)
{
Try
{
If (m_axFramerControl = null)
{
Throw new ApplicationException ("Please initialize the office control object first! ");
}

// This. m_axFramerControl.SetMenuDisplay (48 );
// This method is very special. I have not found the rule of parameters for a combination Menu Control method. If you are interested, please study it.
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 = false;
}
Catch (Exception ex)
{
Throw ex;
}
}

The following method is a parameter required by dso to open a file, representing the office file type.
/// <Summary>
/// Obtain the Opening Method Based on the suffix
/// </Summary>
/// <Param name = "_ sExten"> </param>
/// <Returns> </returns>
Private string LoadOpenFileType (string _ sExten)
{
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 "caf ":
SOpenType = "Visio. Drawing ";
Break;
Default:
SOpenType = "Word. Document ";
Break;
}
Return sOpenType;

}
Catch (Exception ex)
{
Throw ex;
}
}

4. in my opinion, the most important step is to announce the current activity object of dso. Because I do not have the usercontrol function, I cannot kill the dso function, leave a larger space for the user ....
/// <Summary>
/// Obtain the document for the current operation
/// </Summary>
Public object ActiveDocument
{
Get
{
Return this. m_axFramerControl.ActiveDocument;
}
}

/// <Summary>
/// Obtain the current control object
/// </Summary>
Public AxDSOFramer. AxFramerControl OfficeObject
{
Get
{
Return this. m_axFramerControl;
}
}
5. published some simple excel and word operations,
# Region public word method. These methods are only valid for word documents.

/// <Summary>
/// Set to retain the Modification Trace (you can use the word toolbar for approval and modification. This method only provides initialization)
/// This method is quite good. You can simulate the keyboard buttons. It's a coincidence. (You didn't know it for a long time ...)
/// </Summary>
/// <Param name = "_ bIs"> </param>
Public void WordSetSaveTrace ()

/// <Summary>
/// Replace tags
/// </Summary>
/// <Param name = "_ sMark"> </param>
/// <Param name = "_ sReplaceText"> </param>
/// <Param name = "_ IsD"> highlight after replacement </param>
/// <Returns> </returns>
Public bool WordReplace (string _ sMark, string _ sReplaceText, bool _ IsD)

/// <Summary>
/// Text replacement
/// </Summary>
/// <Param name = "_ sOrialText"> </param>
/// <Param name = "_ sReplaceText"> </param>
/// <Returns> </returns>
Public bool WordReplace (string _ sOrialText, string _ sReplaceText)

# Endregion

# Region public excel method

/// <Summary>
/// Enter a value at a fixed position
/// </Summary>
/// <Param name = "_ sValue"> content </param>
/// <Param name = "_ iBeginRow"> Start row </param>
/// <Param name = "_ iBeginCol"> Start column </param>
Public void ExcelFillValue (string _ sValue, int _ iBeginRow, int _ iBeginCol)

/// <Summary>
/// Enter a value at a fixed position
/// </Summary>
/// <Param name = "_ sValue"> enter the object </param>
/// <Param name = "_ iBeginRow"> Start row </param>
/// <Param name = "_ iBeginCol"> Start column </param>
Public void ExcelFillValue (Object _ sValue, int _ iBeginRow, int _ iBeginCol)

/// <Summary>
/// Enter a value at a fixed position
/// </Summary>
/// <Param name = "_ ds"> content </param>
/// <Param name = "_ iBeginRow"> Start row </param>
/// <Param name = "_ iBeginCol"> Start column </param>
Public void ExcelFillValue (System. Data. DataSet _ ds, int _ iBeginRow, int _ iBeginCol, bool _ IsTitle)

/// <Summary>
/// Clear the excel document
/// </Summary>
Public void ExcelClear ()

/// <Summary>
/// Clear content at a fixed position
/// </Summary>
/// <Param name = "_ iBeginRow"> Start row </param>
/// <Param name = "_ iBeginCol"> Start column </param>
Public void ExcelClear (int _ iBeginRow, int _ iBeginCol)

/// <Summary>
/// Clear the content of the specified region
/// </Summary>
/// <Param name = "_ iBeginRow"> Start row </param>
/// <Param name = "_ iBeginCol"> Start column </param>
/// <Param name = "_ iEndRow"> end row </param>
/// <Param name = "_ iEndCol"> end column </param>
Public void ExcelClear (int _ iBeginRow, int _ iBeginCol, int _ iEndRow, int _ iEndCol)

# Endregion
All of the above are pediatrics for excel and Word documents. I am afraid that you will not be able to paste them out .....

6. publish some simple methods (save and save as a way to prevent menus and toolbar from being hidden). There should be many ways to save these methods, I only use these so ....
/// <Summary>
/// Save
/// </Summary>
Public void Save ()
{
Try
{
// Save it first
This. m_axFramerControl.Save (true, true ,"","");
}
Catch (Exception ex)
{
Throw ex;
}
}

/// <Summary>
/// Save
/// </Summary>
Public void SaveAs ()
{
Try
{
// Save
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>
/// Close the current interface
/// </Summary>
Public void Close ()
{
Try
{
If (this. m_axFramerControl! = Null)
{
This. m_axFramerControl.Close ();
}
}
Catch (Exception ex)
{
Throw ex;
}
}

Finally, if you want to remove the registration of the dso control, you can also, because I have no way to get whether the control has been registered on the machine, so it must be registered every initialization, I wonder if any of my friends in the garden can detect this problem. Could you please kindly advise me?

Now, a simple office Online Editing control that can be used for windows programs is completed.

 

The article is reproduced in:
Author: jisen
Http://www.cnblogs.com/jisen/archive/2007/07/12/815772.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.