Delphi write data to excel, but provide outline mode support

GooD day

I would like to write the following data to excel, but it should be in outline mode.

Example of data
Dept Code      Sales
1                     500
1                     200
1                     300
2                     500
2                     600

The output to excel must be as follows:

+Dept 1 sum 1000
+Dept 2 sum 1100

if the user click on the +, then it should show the detail for each department.

Thanx in advance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there,

This should do the trick.
procedure TForm1.Button1Click(Sender: TObject);
  col_a: array[1..8] of string = ('Dept Code','1','1','1','Total for Dept 1','2','2','Total for Dept 2');
  col_b: array[1..8] of string = ('Sales','300','200','500','=sum(B2:B4)','100','600','=sum(B6:B7)');
  Excel, Book, Sheet, Range: Variant;
  row: integer;
  Excel := CreateOleObject('Excel.Application');
  Excel.Visible := True;

  // Get a new workbook
  Book := Excel.Workbooks.Add;
  Sheet := Book.ActiveSheet;

  for row := 1 to 8 do
    Sheet.Cells(row,1) := col_a[row];
    Range := Sheet.Range['B'+IntToStr(row)];
    Range.Formula := col_b[row];

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
henryreynoldsAuthor Commented:

It looks and works excellent, I just want to put everything into a real world example and then I will let you know. Do you know anything about TXLSReadWrite component maybe ?
I hope it works out.
Sorry no I haven't heard of TXLSReadWrite... automation and peeking at recorded macros seem to work for me :)
henryreynoldsAuthor Commented:
It will work thank you very much
henryreynoldsAuthor Commented:
Thank you very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.