DataSet导出到Excel比较完整的解决方案(一)--客户端生成文件(downmoon)
2009-01-16 10:19:16 来源:WEB开发网导入到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;
}
更多精彩
赞助商链接