Example #1
0
        static void testExport()
        {
            DataSet ds = new DataSet();

            DataTable db = new DataTable("tb0");

            DataColumn dc = null;
            dc = db.Columns.Add("id", Type.GetType("System.String"));
            dc = db.Columns.Add("name", Type.GetType("System.String"));
            dc = db.Columns.Add("sex", Type.GetType("System.String"));
            ds.Tables.Add(db);

            DataRow row = ds.Tables[0].NewRow();
            row["id"] = "1";
            row["name"] = "张三";
            row["sex"] = "男";
            ds.Tables[0].Rows.Add(row);

            DataRow row2 = ds.Tables[0].NewRow();
            row["id"] = "2";
            row["name"] = "李四";
            row["sex"] = "男";
            ds.Tables[0].Rows.Add(row2);

            String[] title = new String[] { "编号", "姓名", "性别" };
            int[] width = new int[] { 20, 20, 20 };

            ExcalHelper e = new ExcalHelper("测试", title, width, 1);
            e.ExportExcel(ds, "c:/b.xls");
        }
Example #2
0
 static void testExport(DataSet ds, String path)
 {
     String[] title = new String[] { "编号", "姓名", "性别" };
     int[] width = new int[] { 20, 20, 20 };
     ExcalHelper e = new ExcalHelper("测试", title, width, 1);
     e.ExportExcel(ds, path);
 }
Example #3
0
        static void Main()
        {
            //String sqltext = "select id, sex name from memcard";
            //  DataSet ds = ExecuteQuery(sqltext);
            //testExport(ds, "c:/mem.xls");

            ExcalHelper obj = new ExcalHelper(4);
            DataTable _data = obj.ImportExcelFile("c:/mem.xls");
            _data.TableName = "memcard";

            if (_data != null && _data.Rows.Count > 0)
            {
                SqlBulkCopy bcp = new SqlBulkCopy("server=sql.w3249.vhostgo.com;database=vipsoft;uid=vipsoft;pwd=vip123456");
                bcp.DestinationTableName = "memcard";
                bcp.WriteToServer(_data);
                bcp.Close();
            }
        }