Columns in an excel sheet

wolverinewolverine Member Posts: 9
Hi all !

I'm generating an excel from navision. How can I manage columns dynamically ?

When I start generating the excel sheet, I don't know in advance how many columns will be needed.
With 'XlSheet.Range(col+line)' I can dynamically fill the lines, but I have to tell exlicitely wich column (A,B,C,..) I'm writing on, this is what I want
to manage dynamically, without hard coding it in the code.

Thanks for any help.

Comments

  • ArhontisArhontis Member Posts: 667
    Hi,

    Here is a small routine on getting the column name with an integer as a parameter...
    GetColumnName(Num : Integer) : Text[2]
    VAR
      times:integer;
      Chars:Text[26];
      FirstChar:Text[30];
      SecondChar:Text[30];
    BEGIN
      Chars:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      times := ROUND((Num-1) / 26,1,'<');
    
      IF times>0 THEN
        FirstChar:=COPYSTR(Chars,times,1)
      ELSE
        FirstChar:='';
      SecondChar:=COPYSTR(Chars,Num-(times*26),1);
      EXIT(FirstChar+SecondChar);
    END
    

    I hope it helps...
  • wolverinewolverine Member Posts: 9
    Thank you Arhontis. It works very well :D:D
Sign In or Register to comment.