473,385 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

conversion to c# from excel function help

D
I am trying to do this in C#

Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function

it takes a long and converts it to the excel header format of AA, BQ DS etc

so far I have this, I commented out the top and worked my way up from the
bottom. I'm not sure what the c# equivalent of Int in excel (which returns
the 210 part of 210.2342) and I don't know what how this is handled
Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

Thanks for any help.
public string Num2Let(long L )

{

string s0, s1, S2, s3, final;

/* if(L > 18278)

s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);

if(L > 702)

s1 = Chr((Int((L - 703) / 676) % 26) + 65);

*/

if(L > 26)

S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);

//S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

long x =(((L - 1) % 26) + 65);

char c = (char)x;

s3 = c.ToString();

//final = s0 + s1 + S2 + s3;

return s3;

}
Nov 16 '05 #1
6 1796
RCS
Man, you should make up a book of these and sell them at geek stores, you'd
make a fortune!!

If this doesn't get solved tonight, I'll give it a shot tomorrow - looks
fun!!
"D" <Da**@nothing.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I am trying to do this in C#

Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function

it takes a long and converts it to the excel header format of AA, BQ DS
etc

so far I have this, I commented out the top and worked my way up from the
bottom. I'm not sure what the c# equivalent of Int in excel (which returns
the 210 part of 210.2342) and I don't know what how this is handled
Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

Thanks for any help.
public string Num2Let(long L )

{

string s0, s1, S2, s3, final;

/* if(L > 18278)

s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);

if(L > 702)

s1 = Chr((Int((L - 703) / 676) % 26) + 65);

*/

if(L > 26)

S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);

//S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

long x =(((L - 1) % 26) + 65);

char c = (char)x;

s3 = c.ToString();

//final = s0 + s1 + S2 + s3;

return s3;

}

Nov 16 '05 #2
D
I wish I could but I didn't write it. I found it when I was looking for a
function to convert numbers to excel like headers (AAA, AAB, AAC etc).

I'll post the solution if I figure it out.
"RCS" <rs****@gmail.com> wrote in message
news:Vu*****************@newssvr33.news.prodigy.co m...
Man, you should make up a book of these and sell them at geek stores,
you'd make a fortune!!

If this doesn't get solved tonight, I'll give it a shot tomorrow - looks
fun!!
"D" <Da**@nothing.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I am trying to do this in C#

Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function

it takes a long and converts it to the excel header format of AA, BQ DS
etc

so far I have this, I commented out the top and worked my way up from the
bottom. I'm not sure what the c# equivalent of Int in excel (which
returns the 210 part of 210.2342) and I don't know what how this is
handled Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

Thanks for any help.
public string Num2Let(long L )

{

string s0, s1, S2, s3, final;

/* if(L > 18278)

s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);

if(L > 702)

s1 = Chr((Int((L - 703) / 676) % 26) + 65);

*/

if(L > 26)

S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);

//S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

long x =(((L - 1) % 26) + 65);

char c = (char)x;

s3 = c.ToString();

//final = s0 + s1 + S2 + s3;

return s3;

}


Nov 16 '05 #3
Try this one.
I needed one myself too. Cool!

Do not know if it works yet.

public static string CellIndexToName ( int index )
{
if (0x0 >= index)
return string.Empty;
StringBuilder sb = new StringBuilder(0x5);
if (0x4766 < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x4767)) /
17576)) % 0x1a) + 0x41));
}
if (0x2BE < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x2bf)) /
676)) % 0x1a) + 0x41));
}
if (0x1A < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x1b)) /
26)) % 0x1a) + 0x41));
}
sb.Append((char) (int) (((index - 0x1) % 0x1A) + 0x41));
return sb.ToString();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I wish I could but I didn't write it. I found it when I was looking for a
function to convert numbers to excel like headers (AAA, AAB, AAC etc).

I'll post the solution if I figure it out.
"RCS" <rs****@gmail.com> wrote in message
news:Vu*****************@newssvr33.news.prodigy.co m...
Man, you should make up a book of these and sell them at geek stores,
you'd make a fortune!!

If this doesn't get solved tonight, I'll give it a shot tomorrow - looks
fun!!
"D" <Da**@nothing.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I am trying to do this in C#

Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function

it takes a long and converts it to the excel header format of AA, BQ DS
etc

so far I have this, I commented out the top and worked my way up from
the bottom. I'm not sure what the c# equivalent of Int in excel (which
returns the 210 part of 210.2342) and I don't know what how this is
handled Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

Thanks for any help.
public string Num2Let(long L )

{

string s0, s1, S2, s3, final;

/* if(L > 18278)

s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);

if(L > 702)

s1 = Chr((Int((L - 703) / 676) % 26) + 65);

*/

if(L > 26)

S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);

//S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

long x =(((L - 1) % 26) + 65);

char c = (char)x;

s3 = c.ToString();

//final = s0 + s1 + S2 + s3;

return s3;

}



Nov 16 '05 #4
D
BRILLIANT!!!!!

Works fine for me so far.

Can you tell me why you used hex (0x0 , 0x4766, etc)?

Thanks alot!!!
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Try this one.
I needed one myself too. Cool!

Do not know if it works yet.

public static string CellIndexToName ( int index )
{
if (0x0 >= index)
return string.Empty;
StringBuilder sb = new StringBuilder(0x5);
if (0x4766 < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x4767)) /
17576)) % 0x1a) + 0x41));
}
if (0x2BE < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x2bf)) /
676)) % 0x1a) + 0x41));
}
if (0x1A < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x1b)) /
26)) % 0x1a) + 0x41));
}
sb.Append((char) (int) (((index - 0x1) % 0x1A) + 0x41));
return sb.ToString();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I wish I could but I didn't write it. I found it when I was looking for a
function to convert numbers to excel like headers (AAA, AAB, AAC etc).

I'll post the solution if I figure it out.
"RCS" <rs****@gmail.com> wrote in message
news:Vu*****************@newssvr33.news.prodigy.co m...
Man, you should make up a book of these and sell them at geek stores,
you'd make a fortune!!

If this doesn't get solved tonight, I'll give it a shot tomorrow - looks
fun!!
"D" <Da**@nothing.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I am trying to do this in C#

Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function

it takes a long and converts it to the excel header format of AA, BQ DS
etc

so far I have this, I commented out the top and worked my way up from
the bottom. I'm not sure what the c# equivalent of Int in excel (which
returns the 210 part of 210.2342) and I don't know what how this is
handled Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

Thanks for any help.
public string Num2Let(long L )

{

string s0, s1, S2, s3, final;

/* if(L > 18278)

s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);

if(L > 702)

s1 = Chr((Int((L - 703) / 676) % 26) + 65);

*/

if(L > 26)

S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);

//S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);

long x =(((L - 1) % 26) + 65);

char c = (char)x;

s3 = c.ToString();

//final = s0 + s1 + S2 + s3;

return s3;

}



Nov 16 '05 #5
So it works? Cool!
Have'nt really got the time to test it properly, just a few times with small
numbers.

There is no particular reason why i use hex instead of decimals, it is just
a matter
of preference, and maybe decimals would be clearer when posting code here.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
BRILLIANT!!!!!

Works fine for me so far.

Can you tell me why you used hex (0x0 , 0x4766, etc)?

Thanks alot!!!
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Try this one.
I needed one myself too. Cool!

Do not know if it works yet.

public static string CellIndexToName ( int index )
{
if (0x0 >= index)
return string.Empty;
StringBuilder sb = new StringBuilder(0x5);
if (0x4766 < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x4767))
/ 17576)) % 0x1a) + 0x41));
}
if (0x2BE < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x2bf)) /
676)) % 0x1a) + 0x41));
}
if (0x1A < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x1b)) /
26)) % 0x1a) + 0x41));
}
sb.Append((char) (int) (((index - 0x1) % 0x1A) + 0x41));
return sb.ToString();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I wish I could but I didn't write it. I found it when I was looking for a
function to convert numbers to excel like headers (AAA, AAB, AAC etc).

I'll post the solution if I figure it out.
"RCS" <rs****@gmail.com> wrote in message
news:Vu*****************@newssvr33.news.prodigy.co m...
Man, you should make up a book of these and sell them at geek stores,
you'd make a fortune!!

If this doesn't get solved tonight, I'll give it a shot tomorrow -
looks fun!!
"D" <Da**@nothing.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
>I am trying to do this in C#
>
> Function Num2Let(L As Long) As String
> Dim s0 As String, s1 As String, S2 As String, s3 As String
> If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
> If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
> If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
> s3 = Chr(((L - 1) Mod 26) + 65)
> Num2Let = s0 & s1 & S2 & s3
> End Function
>
> it takes a long and converts it to the excel header format of AA, BQ
> DS etc
>
> so far I have this, I commented out the top and worked my way up from
> the bottom. I'm not sure what the c# equivalent of Int in excel (which
> returns the 210 part of 210.2342) and I don't know what how this is
> handled Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);
>
> Thanks for any help.
>
>
> public string Num2Let(long L )
>
> {
>
> string s0, s1, S2, s3, final;
>
> /* if(L > 18278)
>
> s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);
>
> if(L > 702)
>
> s1 = Chr((Int((L - 703) / 676) % 26) + 65);
>
> */
>
> if(L > 26)
>
> S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);
>
> //S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);
>
> long x =(((L - 1) % 26) + 65);
>
> char c = (char)x;
>
> s3 = c.ToString();
>
> //final = s0 + s1 + S2 + s3;
>
> return s3;
>
> }
>
>



Nov 16 '05 #6
D
I haven't pushed it to the higher limits but so far it works good.
There is no particular reason why i use hex instead of decimals, it is
just
It looks cooler!

I worked with a guy who always wrote his if's in a similiar fashion although
not hex but put the number first like
this
if ( 1 < x )
versus
if ( x > 1 )
he said the reason was that it was a faster action in the cpu. I don't know
about that but it "sounded good to management."

Thanks again.

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:eL*************@TK2MSFTNGP12.phx.gbl... So it works? Cool!
Have'nt really got the time to test it properly, just a few times with
small numbers.

There is no particular reason why i use hex instead of decimals, it is
just a matter
of preference, and maybe decimals would be clearer when posting code here.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
BRILLIANT!!!!!

Works fine for me so far.

Can you tell me why you used hex (0x0 , 0x4766, etc)?

Thanks alot!!!
"Dennis Myrén" <de****@oslokb.no> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Try this one.
I needed one myself too. Cool!

Do not know if it works yet.

public static string CellIndexToName ( int index )
{
if (0x0 >= index)
return string.Empty;
StringBuilder sb = new StringBuilder(0x5);
if (0x4766 < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x4767))
/ 17576)) % 0x1a) + 0x41));
}
if (0x2BE < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x2bf))
/ 676)) % 0x1a) + 0x41));
}
if (0x1A < index)
{
sb.Append((char) ((int) ((int) ((double) (((double) (index - 0x1b)) /
26)) % 0x1a) + 0x41));
}
sb.Append((char) (int) (((index - 0x1) % 0x1A) + 0x41));
return sb.ToString();
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"D" <Da**@nothing.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I wish I could but I didn't write it. I found it when I was looking for
a function to convert numbers to excel like headers (AAA, AAB, AAC etc).

I'll post the solution if I figure it out.
"RCS" <rs****@gmail.com> wrote in message
news:Vu*****************@newssvr33.news.prodigy.co m...
> Man, you should make up a book of these and sell them at geek stores,
> you'd make a fortune!!
>
> If this doesn't get solved tonight, I'll give it a shot tomorrow -
> looks fun!!
>
>
> "D" <Da**@nothing.net> wrote in message
> news:%2***************@TK2MSFTNGP15.phx.gbl...
>>I am trying to do this in C#
>>
>> Function Num2Let(L As Long) As String
>> Dim s0 As String, s1 As String, S2 As String, s3 As String
>> If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
>> If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
>> If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 +
>> 65)
>> s3 = Chr(((L - 1) Mod 26) + 65)
>> Num2Let = s0 & s1 & S2 & s3
>> End Function
>>
>> it takes a long and converts it to the excel header format of AA, BQ
>> DS etc
>>
>> so far I have this, I commented out the top and worked my way up from
>> the bottom. I'm not sure what the c# equivalent of Int in excel
>> (which returns the 210 part of 210.2342) and I don't know what how
>> this is handled Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);
>>
>> Thanks for any help.
>>
>>
>> public string Num2Let(long L )
>>
>> {
>>
>> string s0, s1, S2, s3, final;
>>
>> /* if(L > 18278)
>>
>> s0 = Chr((Int((L - 18279) / 17576) % 26) + 65);
>>
>> if(L > 702)
>>
>> s1 = Chr((Int((L - 703) / 676) % 26) + 65);
>>
>> */
>>
>> if(L > 26)
>>
>> S2 = Chr(Num2Let(((L - 27) / 26)) % 26 + 65);
>>
>> //S2 = Chr(Num2Let & ( Int((L - 27) / 26) ) % 26 + 65);
>>
>> long x =(((L - 1) % 26) + 65);
>>
>> char c = (char)x;
>>
>> s3 = c.ToString();
>>
>> //final = s0 + s1 + S2 + s3;
>>
>> return s3;
>>
>> }
>>
>>
>
>



Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Benny Alexander | last post by:
Dear All, I have a problem, which needs your ideas. We have a excel document, which is been updated regularly. After everyday updating, we export as HTML file and upload it. As a ASP...
3
by: Don.Vonderburg | last post by:
I am having a problem importing an Excel spreadsheet. I have a column in an Excel sheet with alphanumeric text and some of the cells are numeric. Some of the cells contain numbers like 12345.6 and...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
2
by: Ronny Sigo | last post by:
Hello all, Could anybody help me referencing individual cells in excel? I don't know what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel 10.0 Object library is referenced)...
8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
1
by: RSB | last post by:
Hi Everyone, i am using the following code to transfer a DataGrid to Excel File. Every thing works ok beside the long numerice value like 0000121900000000 gets converted to 1.219E+11. how can i...
1
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set...
1
by: malick | last post by:
Hello it developers, I'm using PHPExcelReader which I downloaded from sourceforge (http://sourceforge.net/projects/phpexcelreader) To read excel xls files in php. In the file reader.php (...
4
by: smugcool | last post by:
HI, I am trying to import an excel data. All the fields are geting imported properly. But i am geting error in the date field. I tried to keep the format both in excel and access very similar.But...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.