IT民工系列——c#控制Excel的类库。对com操作进行了封装

前言:

我是一名IT民工,热爱计算机 热爱软件。我从事.net平台开发也有几年了,专注c#。熟悉: ORM/RBAC/AOP/OO/持久层/数据流/工作流/信息流/企业系统开发/Excel等解密等。


我过去几年直到现在的技术积累,希望能帮上各位兄弟。如果各位兄弟看上眼,一元钱用淘宝拍下;在淘宝商品备注留下email和项目的名字;我会邮寄给您代码源码密码和说明文档。

一元钱不多,希望能节省您的开发时间,也支持鼓励下我。如果兄弟收到了源码,也请保存好,不要放在互联网上,留小弟一条小小路走。我的淘宝用户是:pixysoft ,请确认,不要被恶意者冒用。


如果各位兄弟有小项目或者小想法,不想自己费神,我也愿意毛遂自荐承担一下,价格你开,只要我能做的就一定答应帮您做好!


我在此鞠躬感谢了!

代码目的:

通过调用类库操作excel文档,能够输出任意的excel文件。

代码测试片段:

class Testcase
    {
        
public void Test01()
        {
            
//根据Datatable 输出excel

            DataTable table 
= new DataTable();
            table.Columns.Add(
"ITEMNAME");
            table.Columns.Add(
"ITEMPRICE");

            
for (int i = 0; i < 10; i++)
            {
                DataRow row 
= table.NewRow();
                row[
"ITEMNAME"= "ITEM" + i;
                row[
"ITEMPRICE"= i;
                table.Rows.Add(row);
            }

            ExcelExporterConfiguration config 
= new ExcelExporterConfiguration();
            config.DataSource 
= table;

            ExcelExporter.Instance.Export(config, 
true);
        }

        
public void Test02()
        {
            
//设置了映射关系/隐藏关系/打印顺序的输出

            DataTable table 
= new DataTable();
            table.Columns.Add(
"ITEMNAME");
            table.Columns.Add(
"ITEMPRICE");
            table.Columns.Add(
"INVISABLECOL");

            
for (int i = 0; i < 10; i++)
            {
                DataRow row 
= table.NewRow();
                row[
"ITEMNAME"= "ITEM" + i;
                row[
"ITEMPRICE"= i;
                row[
"INVISABLECOL"= i;
                table.Rows.Add(row);
            }

            ExcelExporterConfiguration config 
= new ExcelExporterConfiguration();
            config.DataSource 
= table;
            config.Ordelist.Add(
"ITEMPRICE");
            config.Ordelist.Add(
"ITEMNAME");
            config.Mapping.Add(
"ITEMNAME""商品名称");
            config.Mapping.Add(
"ITEMPRICE""商品价格");
            config.Masklist.Add(
"INVISABLECOL");

            ExcelExporter.Instance.Export(config, 
true);
        }

        
public void Test03()
        {
            
//自定义数据的输出

            ExcelExporterConfiguration config 
= new ExcelExporterConfiguration();
            config.Cellconfiguration.Add(
new ExcelExporterCellConfiguration(00"ITEMNAME"));
            config.Cellconfiguration.Add(
new ExcelExporterCellConfiguration(01"ITEMPRICE"));

            ExcelExporter.Instance.Export(config, 
true);
        }

        
public void Test04()
        {
            
//datagridview 数据输出

            DataGridView view 
= null;//假设获取了界面的gridview

            ExcelExporter.Instance.Export(view, 
true);

        }


    }

代码源码下载(box.net提供空间 绝对安全放心):

http://www.citi-box.com/accessories/temp/Pixysoft.Iter.Microsoft.Excel.rar

代码资助链接(淘宝):

http://item.taobao.com/auction/item_detail.jhtml?item_id=86e39a36348da8663d647a9cce75d29c&x_id=0db2#

原文地址:https://www.cnblogs.com/zc22/p/1500992.html