Excel cell-values are truncated by OLEDB-provider

后端 未结 2 1366
感动是毒
感动是毒 2020-12-03 08:16

I\'m using the OleDbConnection class to retrieve data from an Excel 2000/2003 workbook:

string connectionString = \"Provider=Microsoft.Jet.OLEDB.4.0;\" +
            


        
相关标签:
2条回答
  • 2020-12-03 08:27

    Try this OleDBAdapter Excel QA I posted via stack overflow.

    I populated an worksheet cell (Rows[0][4]) w/ 445 characters and it worked fine... Add this to the end of the code for the ouput

    // DataSet:          
    Object row0Col3 = ds.Tables["xlsImport"].Rows[0][2];
    Object row0Col4 = ds.Tables["xlsImport"].Rows[0][4];
    
    string rowZeroColumn3 = row0Col3.ToString();
    string rowZeroColumn4 = row0Col4.ToString();
    
    Console.WriteLine("Row 0, Col 4 string length: {0} " + Environment.NewLine + "Excel content: {1}", rowZeroColumn4.Length, rowZeroColumn4);           
    
    0 讨论(0)
  • 2020-12-03 08:47

    The OLEDB provider for excel will attempt to automatically determine the DataTypes based off of the first 8 rows of data, this can be set with the HDR=Yes/No property in the connection string. Additionally, there are multiple types that it can apply to text columns. The memo type holds over 255 characters, so if none of the first 8 rows have that then it will incorrectly set the data type.

    The way to change this is by changing a registry setting called TypeGuessRows, as described here: Microsoft Support

    NOTE: The valid range of values for the TypeGuessRows key is 0 to 16. However, if the value is 0, the number of source rows scanned is 16384. So if you have a very large file make sure the biggest rows are first.

    0 讨论(0)
提交回复
热议问题