.NET读写Excel工具Spire.XlS使用(DataExport )

Introduction

 E-ICEBLUE is developing office.net component, the main products include Spire.Doc, Spire.PDF, Spire.XLS, Spire.presentation, office Spire and so on. It means that they are the word, PDF, Excel, PowerPoint, office development kit .With the help of those products, developers can essily handle office documents or develop their own applications on the .NET platform.

Product evaluation invitation

I am glad to receive this invitation today (2016/04/12). To be honest, it is the first time for me to do a testing on product even though my major is sofeware. Perhaps it is because of this, that I am determined to spare no effort in doing this test. 

  E-iceblue官网:http://www.e-iceblue.com/(冰蓝科技)。

Download & Installation

Download Link :http://www.e-iceblue.com/downloads/pack/spire.office_2.13.zip

Inatallation:

ICON:

 Here I want to show you how to use the Spire.XLS to export data and import data.

Programming Guid

(1)Create a Project & Add Reference

(2)Using Namespace

In this project, I use the namespace as follows:

using System;
using System.Data.OleDb;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using Spire.Xls;

(3)Initialization Component

private void InitializeComponent()
        {
            this.btnRun = new System.Windows.Forms.Button();
            this.btnAbout = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();
            // 
            // btnRun
            // 
            this.btnRun.Location = new System.Drawing.Point(360, 288);
            this.btnRun.Name = "btnRun";
            this.btnRun.Size = new System.Drawing.Size(72, 23);
            this.btnRun.TabIndex = 2;
            this.btnRun.Text = "Run";
            this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
            // 
            // btnAbout
            // 
            this.btnAbout.Location = new System.Drawing.Point(448, 288);
            this.btnAbout.Name = "btnAbout";
            this.btnAbout.Size = new System.Drawing.Size(75, 23);
            this.btnAbout.TabIndex = 3;
            this.btnAbout.Text = "Close";
            this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click);
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.label1.Location = new System.Drawing.Point(16, 11);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(528, 32);
            this.label1.TabIndex = 4;
            this.label1.Text = "I am a Label , following is DataGrid,I will show you how to export data by Spire." +
    "XLS";
            // 
            // dataGrid1
            // 
            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(16, 56);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.Size = new System.Drawing.Size(512, 216);
            this.dataGrid1.TabIndex = 5;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(544, 325);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnAbout);
            this.Controls.Add(this.btnRun);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Spire.XLS sample";
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);

        }

(4)Clean up any resources being used (we can use it in other projects)

protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

(5)Button Click

private void btnRun_Click(object sender, System.EventArgs e)
        {
            Workbook workbook = new Workbook();
            
            workbook.LoadFromFile(@"e:\\我的课表.xls");
            //Initailize worksheet
            Worksheet sheet = workbook.Worksheets[0];

            this.dataGrid1.DataSource =  sheet.ExportDataTable();
        }


        private void btnAbout_Click(object sender, System.EventArgs e)
        {
            Close();
        }

(6)Result 

 

It's easy to use ,isn't it?

 

转载于:https://www.cnblogs.com/zpfbuaa/p/5388990.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值