我正在使用以下代码进行Excel上传
OleDbConnection sSourceConnection;
string properties = "Excel 8.0; HDR=NO; IMEX=1;";//properties set for connection to excel
string sSourceConstr = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + filePath + ";Extended Properties=\"" + properties + "\"";
sSourceConnection = new OleDbConnection(sSourceConstr);//creating the OLEDB connection
try
{
//select statement to select data from the first excel sheet
string sql = string.Format("Select * FROM [{0}]", "Sheet1$");
//commands to fill the dataset with excel data
OleDbDataAdapter excelAdapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
sSourceConnection.Open();
excelAdapter.SelectCommand = command;
excelAdapter.Fill(dSet, EXCEL_DATA);
我必须上传大约300条记录。一栏有一些文字评论。评论的长度从10个字符到1000个字符不等。但是所有高于255长度的评论都会在该列中被截断。
我已使用此帖子Excel cell-values are truncated by OLEDB-provider来更改注册表设置,但它无效。
我也尝试了帖子OleDB & mixed Excel datatypes : missing data中提到的所有内容,但仍然无效。
答案 0 :(得分:0)
我使用的是ACE引擎,所以更新注册表的正确位置是
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel\TypeGuessRowsHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows
答案 1 :(得分:0)
对于Microsoft Office 2010-2013-2016 / 365
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel
最好是扫描文本'TypeGuessRows',当你找到它时,结合Excel,将其值设置为0.我们在这个位置找到了另一个重要的位置
\HKEY_LOCAL_MACHINE \SOFTWARE\Microsoft\Office \ClickToRun\REGISTRY \MACHINE\Software \Wow6432Node \Microsoft \Office\16.0\Access Connectivity Engine\Engines\Excel.