Link to home
Create AccountLog in
ASP

ASP

--

Questions

--

Followers

Top Experts

Avatar of javilmer
javilmer

Pb reading Excel file in ASP
Hello,

We read an excel file in ASP like this :

    Dim ConnExcel
    Set ConnExcel = CreateObject("ADODB.Connection")
    Set RSExcel = CreateObject("ADODB.Recordset")
    SQL = "select * from [mysel$]"
    ConnExcel.ConnectionString = "DBQ=C:\ourfile.xls;DRIVER=Microsoft Excel Driver (*.xls);UID=admin;"

    ConnExcel.Open
    RSExcel.cursortype = 3 ' adStatic.
    RSExcel.open SQL, ConnExcel

     Set rs = Server.CreateObject("ADODB.Recordset")
     sTable = "pro_produits_aav"
     rs.Open sTable, db_conn_def_pr, adOpenKeyset, adLockOptimistic, adCmdTable

     While Not RSExcel.EOF
          response.write RSExcel("Floor") & "<br>"
     RSExcel.MoveNext
Wend

The problem is that we get empty string when the Excel column "Floor" is not numeric. We did set all the cell to "text" in Excel but it does nothing.

Any idea ??

Thanks

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of alorentzalorentz🇺🇸

Maybe...

  While Not RSExcel.EOF
          response.write cStr(RSExcel("Floor")) & "<br>"
     RSExcel.MoveNext

There is a known issue with mixed data types. The excerpt below is taken from:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;257819

A Caution about Mixed Data Types

As stated previously, ADO must guess at the data type for each column in your Excel worksheet or range. (This is not affected by Excel cell formatting settings.) A serious problem can arise if you have numeric values mixed with text values in the same column. Both the Jet and the ODBC Provider return the data of the majority type, but return NULL (empty) values for the minority data type. If the two types are equally mixed in the column, the provider chooses numeric over text.

For example:
In your eight (8) scanned rows, if the column contains five (5) numeric values and three (3) text values, the provider returns five (5) numbers and three (3) null values.
In your eight (8) scanned rows, if the column contains three (3) numeric values and five (5) text values, the provider returns three (3) null values and five (5) text values.
In your eight (8) scanned rows, if the column contains four (4) numeric values and four (4) text values, the provider returns four (4) numbers and four (4) null values.
As a result, if your column contains mixed values, your only recourse is to store numeric values in that column as text, and to convert them back to numbers when needed in the client application by using the Visual Basic VAL function or an equivalent.

To work around this problem for read-only data, enable Import Mode by using the setting "IMEX=1" in the Extended Properties section of the connection string. This enforces the ImportMixedTypes=Text registry setting. However, note that updates may give unexpected results in this mode. For additional information about this setting, click the article number below to view the article in the Microsoft Knowledge Base:
194124 PRB: Excel Values Returned as NULL Using DAO OpenRecordset

Avatar of alorentzalorentz🇺🇸

Yeah, don't think my answer will do anything :)

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of colly92002colly92002🇬🇧

One (quite horrible) work around for this to to export tthe Excel file to CSV, then set up a text file DSN to read in the data.  You have to set up a schema file to tell it the type of each column.

...Like I say this is horrible, but it does always work.

Iain.  

Avatar of javilmerjavilmer

ASKER

- mantarae : we followed the link and used the following connection string :

ConnExcel.ConnectionString = "DBQ=C:\ourfile.xls;DRIVER=Microsoft Excel Driver (*.xls);UID=admin;Excel 8.0; HDR=YES; IMEX=1;"
ConnExcel.Open
It does not change anything. Did we set the paramter correctly ?

- colly92002 : the idea is effectively a solution but as you say, a little horrible. Let's say we'll do it, if nothing else works.... thanks anyway.

try this instead:

xlsConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\ourfile.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


I did it.

But.... unbeleivable, no change, I still don't see the text values.....

ASKER CERTIFIED SOLUTION
Avatar of colly92002colly92002🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

No, I even set the first row to a string.

The only other thing M$ suggests is:

Insure that the data in Excel is entered as text. Just reformatting the Excel column to Text will not accomplish this. You must re-enter the existing values after reformatting the Excel column. In Excel, you can use F5 to re-enter existing values in the selected cell.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


We tried all this with no result.

I believe we will forget excel and go thru CSV as  colly92002 suggests.

Thanks also to mantarae that helped us understanding the complexity of the thing.

Thanks for your participation.

No problem.   Good luck.

You could append a text value to each columnal value. Easy done with a formula in excel.

ie =A1 & "added-string" then paste special the returned value of this formula over you original clean data.

The when it's in ASP land just do a replace.

stringVar = relpace(stringVar, "added-string", "")

Messy but functional.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of anyoneisanyoneis🇺🇸

For excel, see mantarae's solution above, but set TypeGuessRows = 0. for CSV.

For Excel, the connection string is:

string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};" +
                        @" Extended Properties=""{1}""", pathName, "Excel 8.0;HDR=YES;IMEX=1");

In the registry, set:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel\ImportMixedTypes = Text
and
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel\TypeGuessRows = 0

For CSV, the connection string is:
string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};" +
                        @" Extended Properties=""{1}""", path, "Text;HDR=YES;FMT=Delimited;IMEX=1");

In the registry, set:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\ImportMixedTypes = "Text"
and
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\MaxScanRows = "0"

David

Avatar of anyoneisanyoneis🇺🇸

Ignore the "for CSV." typo at then end of the first line. The first line should read:
       
       For excel, see mantarae's solution above, but set TypeGuessRows = 0.

ASP

ASP

--

Questions

--

Followers

Top Experts

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.