• 导入导出CSV


    const string dataPath = @"D:Usersjin_hDocumentsVisual Studio 2013ProjectsConsoleApplication1ConsoleApplication1";



    private static DataTable GetCsvData(string filePath, string fileName) { string connString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + filePath + ";Extensions=asc,csv,tab,txt;"; try { using (var odbcConn = new OdbcConnection(connString)) { odbcConn.Open(); var oleComm = new OdbcCommand(); oleComm.Connection = odbcConn; oleComm.CommandText = "select * from [" + fileName + "#csv]"; var adapter = new OdbcDataAdapter(oleComm); var ds = new DataSet(); adapter.Fill(ds, fileName); return ds.Tables[0]; } } catch (Exception ex) { throw ex; } } private static string ExportCSV(IEnumerable<ErrorData> errorDate) { var sbBuilder = new StringBuilder(); string[] title = { "ScenciSpotID", "DistrictNamePath", "GeographicRegionKeyword", "NoMatchField" }; foreach (var t in title) { sbBuilder.Append(t + ","); } sbBuilder.Append(" "); foreach (var field in errorDate) { sbBuilder.Append(field.ScenciSpotID + ","); sbBuilder.Append(field.DistrictNamePath + ","); sbBuilder.Append(field.GeographicRegionKeyword + ","); sbBuilder.Append(field.NoMatchField + ","); sbBuilder.Append(" "); } return sbBuilder.ToString(); }
  • 相关阅读:
    FastDFS 与 Nginx 实现分布式图片服务器
    git(三) 使用github
    html表单笔记
    Jquery笔记和ajax笔记
    CSS笔记
    javascript笔记
    idea笔记
    spring boot 框架设计步骤
    spring boot启动项的问题
    Loading class `com.mysql.jdbc.Driver'. The new driver class is `com.mysql.cj.jdb 问题
  • 原文地址:https://www.cnblogs.com/xffy1028/p/4501353.html
Copyright © 2020-2023  润新知