资源简介

1.CSV文件转换 CsvHelper CSV文件导入DataTable和DataTable导出到Csv文件等操作 2.导出Excel 操作类 DataToExcel 从“Excel导出数据的帮助类 ExcelHelper 导出到文件,导出一部分集合,从DataTable中操作等 ExportExcel 主要功能如下1.将整个网页导出来Excel 2.将GridView数据导出Excel GridViewExport 主要功能:将整GridView的数据导出到Excel中关增加一个效果线做美化 ExcelNPOIHelper(此类非常好用) 第三方(NPOI)导入导出,不用在担心客户端电脑是否装了Office ,安装了什么版本的office了。 支持导入excel 2003、excel 2007、excel 2010 等各种版本

资源截图

代码片段和文件信息

/// 
/// 联系方式:361983679  
/// 更新网站:http://www.sufeinet.com/thread-655-1-1.html
/// 

using System.Data;
using System.IO;

namespace DotNet.Utilities
{
    /// 
    /// CSV文件转换类
    /// 

    public static class CsvHelper
    {
        /// 
        /// 导出报表为Csv
        /// 

        /// DataTable
        /// 物理路径
        /// 表头
        /// 字段标题逗号分隔
        public static bool dt2csv(DataTable dt string strFilePath string tableheader string columname)
        {
            try
            {
                string strBufferLine = ““;
                StreamWriter strmWriterObj = new StreamWriter(strFilePath false System.Text.Encoding.UTF8);
                strmWriterObj.WriteLine(tableheader);
                strmWriterObj.WriteLine(columname);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strBufferLine = ““;
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j > 0)
                            strBufferLine += ““;
                        strBufferLine += dt.Rows[i][j].ToString();
                    }
                    strmWriterObj.WriteLine(strBufferLine);
                }
                strmWriterObj.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// 
        /// 将Csv读入DataTable
        /// 

        /// csv文件路径
        /// 表示第n行是字段title第n+1行是记录开始
        public static DataTable csv2dt(string filePath int n DataTable dt)
        {
            StreamReader reader = new StreamReader(filePath System.Text.Encoding.UTF8 false);
            int i = 0 m = 0;
            reader.Peek();
            while (reader.Peek() > 0)
            {
                m = m + 1;
                string str = reader.ReadLine();
                if (m >= n + 1)
                {
                    string[] split = str.Split(‘‘);

                    System.Data.DataRow dr = dt.NewRow();
                    for (i = 0; i < split.Length; i++)
                    {
                        dr[i] = split[i];
                    }
                    dt.Rows.Add(dr);
                }
            }
            return dt;
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      28160  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\bin\Debug\DotNet.Utilities.dll

     文件      56832  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\bin\Debug\DotNet.Utilities.pdb

     文件       9636  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\bin\Debug\DotNet.Utilities.xml

     文件    1089536  2013-08-17 08:27  Excel.Hepler\DotNet.Utilities\bin\Debug\Excel.dll

     文件    1599488  2014-01-05 08:01  Excel.Hepler\DotNet.Utilities\bin\Debug\NPOI.dll

     文件     395776  2014-01-05 08:01  Excel.Hepler\DotNet.Utilities\bin\Debug\NPOI.OOxml.dll

     文件      84480  2014-01-05 08:01  Excel.Hepler\DotNet.Utilities\bin\Debug\NPOI.Openxml4Net.dll

     文件    1866240  2014-01-05 08:01  Excel.Hepler\DotNet.Utilities\bin\Debug\NPOI.OpenxmlFormats.dll

     文件       2712  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\CSV\CsvHelper.cs

     文件       4388  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\DotNet.Utilities.csproj

     文件       7168  2014-04-27 23:21  Excel.Hepler\DotNet.Utilities\DotNet.Utilities.suo

     文件      16685  2013-08-17 08:25  Excel.Hepler\DotNet.Utilities\Excel\DataToExcel.cs

     文件      21468  2014-04-08 09:40  Excel.Hepler\DotNet.Utilities\Excel\ExcelHelper.cs

     文件      29018  2014-05-05 15:49  Excel.Hepler\DotNet.Utilities\Excel\ExcelNPOIHelper.cs

     文件       3435  2013-08-17 08:25  Excel.Hepler\DotNet.Utilities\Excel\ExportExcel.cs

     文件       6636  2013-08-17 08:25  Excel.Hepler\DotNet.Utilities\Excel\GridViewExport.cs

     文件       6147  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1710  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\obj\Debug\DotNet.Utilities.csproj.FileListAbsolute.txt

     文件      28160  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\obj\Debug\DotNet.Utilities.dll

     文件      56832  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\obj\Debug\DotNet.Utilities.pdb

     文件       1395  2013-08-17 08:25  Excel.Hepler\DotNet.Utilities\Properties\AssemblyInfo.cs

     文件        938  2014-05-05 15:45  Excel.Hepler\DotNet.Utilities.sln

    ..A..H.     71680  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities.suo

     文件        586  2014-05-07 09:02  Excel.Hepler\说明.txt

    ..AD...         0  2013-08-17 09:26  Excel.Hepler\DotNet.Utilities\obj\Debug\TempPE

     目录          0  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\bin\Debug

     目录          0  2014-05-07 08:50  Excel.Hepler\DotNet.Utilities\bin\Release

     目录          0  2014-05-07 08:53  Excel.Hepler\DotNet.Utilities\obj\Debug

     目录          0  2014-05-07 08:50  Excel.Hepler\DotNet.Utilities\bin

     目录          0  2014-05-07 08:48  Excel.Hepler\DotNet.Utilities\CSV

............此处省略8个文件信息

评论

共有 条评论