Parsing an Excel file in C#, the cells seem to get cut off at 255 characters… how do I stop that?

前端 未结 6 744
野趣味
野趣味 2020-12-29 07:08

I am parsing through an uploaded excel files (xlsx) in asp.net with c#. I am using the following code (simplified):

string connString = string.Format(\"Provi         


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 07:51

    Have you tried setting the columns datatype to text within the spreadsheet? I believe doing this will allow the cells to contain much more than 255 characters.

    [Edit] For what it's worth this dialog with the MS-Excel team is an interesting read. In the comments section at the bottom they get into some discussions about that 255 cutoff. They say Excel 12 can support 32k characters per cell.

    If that is true there must be a way to get at this data. Here is two things to consider.

    1. In the past I have used the "IMEX=1" option in my connection string to deal with columns containing mixed data showing up as empty. It's a longshot, but you might give that a try.

    2. Could you export the file to a tab delimited flat file? IMHO this is the most reliable way of dealing with Excel data, since Excel does have so many gotchas.

提交回复
热议问题