Class commanprint{/// /// Export Excel
// Copyright: wing of light QQ: 272912705 www.hi.baidu.com/jcomet
/// /// /// Public static void exporttasks (datagridview mydgv, Dictionary {// Define the Excel component interface to be used// Define the application object, which indicates the entire EXCEL programMicrosoft. Office. InterOP. Excel. Application excelapp = NULL;// Define the workbook object, which indicates the working thinMicrosoft. Office.
Reprinted: original address: http://blogs.msdn.com/silverlightshanghai/archive/2008/07/23/com-net.aspx
In the previous blog, we used Visual Studio to convert the. NET Component (managed component) into a COM server. This topic continues to show you how to use the. NET toolkit to complete relevant functions.
First, let's take a look at the relationship between today's topic and CLR InterOP. In our group, the term
After reading [C # | Excel] by the farmer's uncle, I accidentally remembered a small project I created two years ago, I have encountered this strange problem that the Excel process cannot end. In fact, the solution is very simple. Excel is a very special thing, all operations on the resource are exclusive, so it is necessary to strictly release the resource. In order to better communicate with you and help those programmers who are being confused, I will attach a small piece of my previous code
Anyone familiar with COM InterOP in. NET should have a better understanding of tlbimp. This tool is specifically used to convert the Type Library (Type Library) into the corresponding InterOP assembly, so that in. netProgramUse the corresponding COM component. This InterOP Assembly mainly contains the metadata (insteadSource code. RCW implementation is actually i
The interoperability type "Microsoft. Office. InterOP. Excel. applicationclass" cannot be embedded ". Use the applicable interface instead.
When exporting the datagridview in winform, write the following statement:Microsoft. Office. InterOP. Excel. Application xlapp = new Microsoft. Office. InterOP. Excel. applicationclass ();
The result is as follows:
Type: M
The following uses the vs2008 development environment as an example:----------------------------------------------------------------------Step 1: Convert the COM interface to a. net interface
Before using mapwingis. ocx in the. NET language, you must convert the COM interface to the. NET interface,ProgramAccess the specific implementation functions in COM through the. NET interface.
Method (1) When mapwingis. ocx is added to the. NET project, a file named
Example5.cs source file (for example, the C:\CSOfficeSamples directory) and type csc/r after the command prompt : "C:\Office XP pias\ Microsoft.Office.Interop.Word.dll "/r: C:\Office XP pias\office.dll" Example5.cs.(If the Office XP PIA is saved in a different location, you will need to replace the following drive and installation paths with the corresponding values:csc/r: Drive:\. )
To run Example5.exe (located in the same folder as the Example5.cs source file), double-click the program.
Finally, we have time to share the following WinForm EXCEL operations with you. The previous section describes how to get the SHEET name and how to obtain the data in the SHEET. In fact, both methods are in preparation for importing EXCEL data into the database. We will continue to share with you how to import data into the database later. The following describes how to put data in SHEET:
Method 1:
View Code
1 publicvoidDataToExcel (DataTable dt)2 {3 try4 {5 if (dt = null) return;67 Microsoft. O
problem. Please try the following method:
Use identity simulation in Web. config and add After solving the above problems, we began to consider how to create a Word template file. The Word template file actually uses bookmarks to add content. That is, by creating bookmarks in the Word document, and then getting all bookmarks in the template file in the program, the document is generated by assigning values to the bookmarks.
The procedure in the program is as follows:
Declare the object of the W
/// /// Export an Excel worksheet to import multiple datatables of a dataset to multiple sheets of an Excel worksheet.
/// /// /// /// Public void doexport (Dataset ds, string [] tablenames, string strexcelfilename)
{
Microsoft. Office. InterOP. Excel. Application Excel = new Microsoft. Office. InterOP. Excel. Application ();
Try
{
Excel. Visible = false;
// Set to prohibit the pop-up prompt box for saving
. shapes. addolecontrol (classtype:
=
"
Forms. checkbox.1
"
)
2
With
Mycb. oleformat. Object
3
. Value
=
False
4
. Caption
=
"
Check if over 21
"
5
End
With
This is the VBA code for adding a check box to a Word document. If a bar code object is added, the Code is as follows:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
1
Set
Mycb
=
Activedocument. shapes. addolecon
Some time ago, I was working on a Plagiarism detection system for my school. When I read a large number of Word documents, the request for a cut operation often failed, for example:
The source code used for reading Word documents is as follows:
Protected void openfile (RichTextBox RTB, string filenametemp) {try {Microsoft. office. interOP. word. application mywordapp = new Microsoft. office. interOP. word.
external program"Box.
Click"Next"To view"Abstract"Page, and then click"Done".
After you create a project in Visual Studio, you will see two projects in the Solution Explorer window. The first project is the COM add-on Project, and the second project is the installation project used to deploy the COM add-on."Shared external program wizard"Only insertMicrosoft Office 12.0 Object LibraryTherefore, you must use the following steps to insert a reference to the infopath Object Library:
In a Windows system, use PHP to generate WORD Documents,
Preparations
First, make sure that a typical WAMP environment has been installed and configured in your Windows system. Since Interop is purely a Windows feature, we will build Apache and PHP on the Windows platform. In this example, I used EasyPHP 14.1, which is easy to install and configure.
Next, we will install Microsoft Office. The version is not strictly required. I am using Office2013 Pro
permission problem. Please try the following method:
Use identity simulation in web. config and add After solving the above problems, we began to consider how to create a WORD template file. The WORD template file actually uses bookmarks to add content. That is, by creating bookmarks in the Word document, and then getting all bookmarks in the template file in the program, the document is generated by assigning values to the bookmarks.
The procedure in the program is as follows:
Declare the obje
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.