Link to home
Start Free TrialLog in
Avatar of jtran007
jtran007

asked on

Excel cell format

Hi Expert,
I have problem to read one column whose format is text. On the spreadsheet I see
all values, but when I read it by using oledb some line of the same column returned
null. Then I check its format. it is text and possibly has 'apostrophy' infront. Then I add
" ' " in front of the cell, then I can read it.
How can I use excel macro to check if the cells in this column named has " ' " if not ,
my macro will add " '". I am new to macro excel.
Could you please help me out?
Thx,'
JT
OleDbCommand cmd3 = new OleDbCommand("select * from [" + txtSheetName.Text + "$]", con);
            using (rd = cmd3.ExecuteReader())
            {
                int index = 0;
 
                while (rd.Read())
                {
                    index++;
 
                    if (index < DataRowIndex - 1)
                    {
                        continue;
                    }
                    else if (index == int.Parse(txtEndedData.Text.ToString()) - 1)
                    {
                        goto closing;
 
                    }
 
                    string countryId = null;
                    if (countryName != null)
                    {
                        countryId = valid(rd, CountryNameIndex);
                        //countryId = rd[CountryNameIndex].ToString();
                    }
                    string Destination = null;
                    Destination = valid(rd, DestIndex);
                    if (Destination.Equals("")) continue;
                    string countryCode = null;
                    if (DNCountry != null)
                        countryCode = valid(rd, DNCountryIndex);
                    //countryCode = rd[DNCountryIndex].ToString();
                    string cityCode = null;
                    cityCode = valid(rd, DNAreaIndex);
                    string Rate = null;

Open in new window

sheetname-err.xls
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Usually, I try to use IMEX=1 in the OLEDB connection string, when working with Excel files.

IMEX=1, of course!
http://blogs.acceleration.net/ryan/archive/2005/01/11/477.aspx
Avatar of jtran007
jtran007

ASKER

Hi Expert,

After adding IMEX=1, I receive this error message "could not find installable ISAM".
Do you what it means?
Thx,
JT
Hi,

have a good look at this: http://support.microsoft.com/kb/257819


Cheers,
Alex
That error just means that you have the connection string incorrect.  That article pointed to connectionstrings.com, which has the IMEX=1 in the Extended Properties:

http://www.connectionstrings.com/excel

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
Hi expert,

I checked everything , it seems ok  but i still have the error.

Also is there limit of charaters in the Excel cell, if yes, how can I increase it since
some of my cell contains more than 255  characters.

Thx,
JT

Under [Worksheet and workbook specifications] you can see Excel 2003 cell limit (255 chars)
http://office.microsoft.com/en-us/excel/HP051992911033.aspx

Here's the same thing but to Office 2007 (same limitation)
http://office.microsoft.com/en-us/excel/HP100738491033.aspx


So this is a limitation of Excel. Another link:
http://support.microsoft.com/kb/213841
Hi expert,

AlexCode: thanks.

I use "using Microsoft.Office.Tools.Excel; and using System.Data.OleDb;" to access Excel, but I still have
""could not find installable ISAM" . Do I miss something?

And my connection string is:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\xuan\\My Documents\\ex\\codeerr.xls;Extended Properties=Excel 8.0; HDR=YES; IMEX=1"      


Thx,
JT
Sorry mate, I'm finding it difficult to help you on that one.
Didn't the microsoft support link I gave you help in any way?
Hi Expert,

The support site that you told me did not help since whatever they recommend I did.
However I still have this error "could not find installable ISAM".

Thanks,
JT
What does your connection string look like?
Hi expert,

Please read my attached connection string in previous conversation.


And my connection string is:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\xuan\\My Documents\\ex\\codeerr.xls;Extended Properties=Excel 8.0; HDR=YES; IMEX=1"      
Thx,
JT
I'm not sure if they're required but I notice you're missing some quotes in that string.  Try some double quote around that last part

Extended Properties=""Excel 8.0; HDR=YES; IMEX=1"""
Hi expert,
They are not required. Also if I add them in, the compiler complains.
Ths,
JT
They are required, otherwise the parser doesn't know how to combine the values together for the Extended Properties.  If the compiler complains, you don't have enough double quotes.  "Cannot find installable ISAM" means that you didn't create a valid connection string--period.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial