Import query data into Excel table output in C#.net

Source: Internet
Author: User
Tags count net query tostring
excel| data

. NET encapsulates Excel-related classes, the following are events triggered by clicking the Excel Output button in the program's winning toolbar, provided that you have Excel installed in your system.
Here is my code, with a note stating:
private void Toolbar1_buttonclick (object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{//toolbar button click event
if (e.button==excelout)
{
Excel.Application excelkccx = new Excel.Application ();//Create Excel Object
EXCELKCCX.WORKBOOKS.ADD (TRUE);//Create Excel workbook

DataTable mydatatable=mydataset.tables["Inventory information"];//create a datasheet that gets the data from the "Inventory information" table in the DataSet
int row=2;

Enter the data table's various information into the Excel table
for (int i=0;i<mydatatable.columns.count;i++)//Fetch field name
{
Excelkccx.cells[1,i+1]=mydatatable.columns[i]. Columnname.tostring ();
}
for (int i=0;i<mydatatable.rows.count;i++)//Fetch 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 ();
}

Source: The movement of the BLOG



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.