WEB开发网
开发学院数据库MSSQL Server DataSet导出到Excel比较完整的解决方案(一)--客... 阅读

DataSet导出到Excel比较完整的解决方案(一)--客户端生成文件(downmoon)

 2009-01-16 10:19:16 来源:WEB开发网   
核心提示: 导入到SQL Server时有多种方法:给出简要代码:GetDataFromCSVpublic static DataTable GetDataFromCSV(string filePath,int beginColumn){int intColCount = 0;bool blnFlag

导入到SQL Server时有多种方法:

给出简要代码:

GetDataFromCSV
public static DataTable GetDataFromCSV(string filePath,int beginColumn)
    {
      int intColCount = 0;
      bool blnFlag = true;
      DataTable mydt = new DataTable("myTableName");
  
      DataColumn mydc;
      DataRow mydr;
  
      string strline;
      string[] aryline;
  
      System.IO.StreamReader mysr = new System.IO.StreamReader(filePath,System.Text.Encoding.UTF8);
      int FlagFirst =1;
      while ((strline = mysr.ReadLine()) != null)
      {
        //if (beginColumn == FlagFirst) { FlagFirst++; continue; }
        strline = strline.Replace("n", "");
        strline = strline.Replace("r", "");
        strline = strline.Replace("t", "");
        //aryline = strline.Split(new char[] { '|' });
        aryline = strline.Split(new char[] { ',' });
  
        if (blnFlag)
        {
          blnFlag = false;
          intColCount = aryline.Length;
          for (int i = 0; i < aryline.Length; i++)
          {
            mydc = new DataColumn(aryline[i]);
            mydt.Columns.Add(mydc);
          }
        }
  
        mydr = mydt.NewRow();
        for (int i = 0; i < intColCount; i++)
        {
          mydr[i] = aryline[i];
        }
        mydt.Rows.Add(mydr);
        FlagFirst++;
      }
      mysr.Close();
      mysr.Dispose();
      return mydt;
    }

上一页  1 2 3 4 5 6  下一页

Tags:DataSet 导出 Excel

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接