Recently, I have been trying to use VC #2005 to build a winform program with built-in word/office. Currently, we have the following solutions:
1. directly store the word/office window handle to winform through the API (complicated );
2. Use Web browser;
3. Use dsoframer.
I tested dsoframer and decided to use dsoframer to implement it.
Procedure:
1. Download dsoframer_kb311765_x86.exe from the micro-soft network and unlock it to get dsoframer. ocx;
2. Copy dsoframer. ocx to the system directory and register it. I wrote Reg. BAT to implement it:
Copy dsoframer. ocx c: \ windows \ system32 \ dsoframer. ocx
Regsvr32.exe c: \ windows \ system32 \ dsoframer. ocx
3. Start vs2005 and create a new winform C # program;
4. In the design toolbar, add new options, select the "tab" page on the pop-up page, browse, and select c: \ windows \ system32 \ dsoframer. OCX is added. The tool is named "DSO framer control object" in the design toolbar ";
5. Drag the tool to a design form window and add the following lines to the code file:
Private axdsoframer. axframercontrol axframercontrol1;
6. Open the file. This. axframercontrol1.open (_ filepath); // Note: _filepathis a file with a suffix of .doc).xls;
7. In this case, you can edit and save the opened Word/Excel files.
Note: during the operation, it is found that closing the print preview button will cause an error in Word/Excel. After searching for a long time, you can directly install office2003 SP3, haha, fix the bug, no error is reported.
I am very happy to write it down and share it with you. If you have any mistakes, please help us to point them out and make progress together.
In addition, the document is not good. Please forgive me.