c# 读取csv文件代码,在本地测试没问题,上传到服务器上就出错!

c# 读取csv文件代码,在本地测试没问题,上传到服务器上就出错!,第1张

ReadXml 方法提供了只将数据或同时将数据和架构从 XML 文档读入 DataSet 的方式,而 ReadXmlSchema 方法仅读架构。若要同时读数据和架构,请使用包括 mode 参数的 ReadXML 重载之一,并将其值设置为 ReadSchema。
请注意,对于 WriteXml 和 WriteXmlSchema 方法也是如此。若要写入来自 DataSet 的 XML 数据或架构和数据两者,使用 WriteXml 方法。若要只写入架构,请使用 WriteXmlSchema 方法。

linux 下,可以使用cli程序把csv文件导入到数据库。具体代码如下:

$ORACLE_HOME/bin/sqlplus -S username/password@instanceName > /dev/null 2>&1  <<!!
#对sqlplus作一些设置,使之只输出我们需要的文本
set echo off
set pagesize 0
set verify off
set feedback off
set termout off
set linesize 3000
set trimspool on
#查询输出到临时文件
spool /tmp/some_tmpcsv 
#select语句
select column1||','||column2||','||column3 
from some_table where condition
spool off
#这里可以添加多个查询,且每个查询可输出到不同的文件,如下面注释
#spool /tmp/some_tmpcsv 
#select column1||','||column2||','||column3 
#from some_table where condition
#spool off
set markup HTML off
quit
!!
#计算记录总行数,如果是0则不发邮件
NUM=`cat /tmp/some_tmpcsv | wc -l`
if[ $NUM -gt 0 ]
then
#先写excel的每列的title
echo 'Title_Of_Column1, Title_Of_Column2, Title_Of_ColumnN' > /tmp/attachementcsv
#数据正文
cat /tmp/some_tmpcsv >> /tmp/attachementcsv
#发邮件
(
echo "From: user@somehostcom"
echo "To: user1@somehostcom"
echo "MIME-Version: 10"
echo "Content-Type: multipart/mixed;"
echo ' boundary="A_Boundary_Name_You_Can_Change_It"'
echo "Subject: Subject"
echo ""
echo ""
#附件分隔符,上面的boundary前面加--
echo "--A_Boundary_Name_You_Can_Change_It"
echo 'Content-Transfer-Encoding: x-uuencode'
echo 'Content-Type: text/csv;'
echo '        name="attachementcsv"'
echo 'Content-Disposition: attachment;'
echo '        filename="attachementcsv"'
echo ""
uuencode /tmp/attachementcsv attachementcsv
echo "--A_Boundary_Name_You_Can_Change_It"
#附件结束
) | mailx -t
fi
#删除临时文件
rm -f /tmp/csv
exit 0

一、文件路径报错
因为在python之中文件路径都是以字符串类型出现的,所以在字符串对象的编写语法本身没有错误时,那么出现报错的唯一原因就是这个文件路径找不到文件。这种问题主要经常出现在已经发布部署到服务器上的python程序,因为在开发时很多时候都是用绝对路径来读取文件的,环境改变之后从磁盘根目录读取的绝对路径就是无法使用了。
二、解决方法
那么正确的做事实际上就是先导入os模块,然后调用getcwd()方法查看当前python程序,也就是py脚本文件处在哪个文件路径之中,代码示例如下所示:
import os
osgetcwd()
print(osgetcwd())
然后再打开文件夹查看一下所要读取的csv文件在哪个文件目录,然后在文件资源管理器内打开csv文件所在的文件目录并将其复制后粘贴到python文件所在的同级目录下,接下来就可以使用绝对不会出错的相对路径来读取该csv文件了。只需要写上csv文件的名称就可以来将其在python程序内打开并读取,代码示例如下所示:
import pandas as pd
train = pdread_csv

js读取CSV格式数据,参考如下:

<script type="text/javascript">     
// This will parse a delimited string into an array of  
// arrays The default delimiter is the comma, but this  
// can be overriden in the second argument  
function CSVToArray( strData, strDelimiter ){  
// Check to see if the delimiter is defined If not,  
// then default to comma  
strDelimiter = (strDelimiter || ",");  
   
// Create a regular expression to parse the CSV values  
var objPattern = new RegExp(  
(  
// Delimiters  
"(\\" + strDelimiter + "|\\r\\n|\\r|^)" +  
   
// Quoted fields  
"(:\"([^\"](:\"\"[^\"]))\"|" +  
   
// Standard fields  
"([^\"\\" + strDelimiter + "\\r\\n]))"  
),  
"gi"  
);  
   
   
// Create an array to hold our data Give the array  
// a default empty first row  
var arrData = [[]];  
   
// Create an array to hold our individual pattern  
// matching groups  
var arrMatches = null;  
   
   
// Keep looping over the regular expression matches  
// until we can no longer find a match  
while (arrMatches = objPatternexec( strData )){  
   
// Get the delimiter that was found  
var strMatchedDelimiter = arrMatches[ 1 ];  
   
// Check to see if the given delimiter has a length  
// (is not the start of string) and if it matches  
// field delimiter If id does not, then we know  
// that this delimiter is a row delimiter  
if (  
strMatchedDelimiterlength &&  
(strMatchedDelimiter != strDelimiter)  
){  
   
// Since we have reached a new row of data,  
// add an empty row to our data array  
arrDatapush( [] );  
   
}  
   
   
// Now that we have our delimiter out of the way,  
// let's check to see which kind of value we  
// captured (quoted or unquoted)  
if (arrMatches[ 2 ]){  
   
// We found a quoted value When we capture  
// this value, unescape any double quotes  
var strMatchedValue = arrMatches[ 2 ]replace(  
new RegExp( "\"\"", "g" ),  
"\""  
);  
   
} else {  
   
// We found a non-quoted value  
var strMatchedValue = arrMatches[ 3 ];  
   
}  
   
   
// Now that we have our value string, let's add  
// it to the data array  
arrData[ arrDatalength - 1 ]push( strMatchedValue );  
}  
   
// Return the parsed data  
return( arrData );  
}  
   
</script>

1、首先studio20导出csv需要选择正在打开的PowerBi文件,点击Contect。
2、其次再使用微信文件传输助手网页版传到服务器。
3、最后安装读取rda和rdata文件rda,rdata文件转为csv文件load即可。

读取CSV和读取普通文件一样
FILE ft;
ftOpen("文件名(包括路径)","a");
CSV表间的分隔符号是"," 换行符号是"\n" 通过这点对输入的字符串进行分割,


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/12809984.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-28
下一篇 2023-05-28

发表评论

登录后才能评论

评论列表(0条)

保存