C#实现DataTable转TXT文件
程序员文章站
2022-06-22 11:08:06
实现DataTable转TXT文件代码如下: public ExecutionResult DataTableToTxt(DataTable vContent, string vOutputFilePath) { ExecutionResult sResult = new ExecutionResu ......
实现datatable转txt文件代码如下:
public executionresult datatabletotxt(datatable vcontent, string voutputfilepath) { executionresult sresult = new executionresult(); stringbuilder stxtcontent; try { if (file.exists(voutputfilepath)) file.delete(voutputfilepath); stxtcontent = new stringbuilder(); //数据 foreach (datarow row in vcontent.rows) { for (int i = 0; i < vcontent.columns.count; i++) { stxtcontent.append(row[i].tostring().trim()); stxtcontent.append(i == vcontent.columns.count - 1 ? "\r\n" : "\t"); } } file.writealltext(voutputfilepath, stxtcontent.tostring(), encoding.unicode); sresult.status = true; } catch (exception ex) { sresult.message = ex.message; sresult.status = false; } return sresult; }
上一篇: 今年是程序员本命年?