. Net encapsulates Excel-related classes. The following are events triggered by clicking the "Excel output" button in the tool bar of the program, provided that excel is installed in your system.
Here is my code, with notes:
Private void toolbar1_buttonclick (Object sender, system. Windows. Forms. toolbarbuttonclickeventargs E)
{// Click events for each Toolbar
If (E. Button = excelout)
{
Excel. Application excelkccx = new excel. Application (); // create an Excel Object
Excelkccx. workbooks. Add (true); // create an Excel worksheet
Datatable mydatatable = mydataset. Tables ["inventory information"]; // create a data table to obtain the data in the "inventory information" table of dataset.
Int ROW = 2;
// Input the information of the data table to the Excel table.
For (INT I = 0; I <mydatatable. Columns. Count; I ++) // obtain the field name
{
Excelkccx. cells [1, I + 1] = mydatatable. Columns [I]. columnname. tostring ();
}
For (INT I = 0; I <mydatatable. Rows. Count; I ++) // obtain the record value
{
For (Int J = 0; j <mydatatable. Columns. Count; j ++)
{
Excelkccx. cells [row, J + 1] = mydatatable. Rows [I] [J]. tostring ();
}
Row ++;
}
Excelkccx. Visible = true; // make Excel visible */
}
Else if (E. Button = reportform)
{
// Kcrptform myreport = new kcrptform ();
// Myreport. mdiparent = this;
// Myreport. Show ();
}