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.
outline.JPG
henryreynoldsAsked:
Who is Participating?
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.

cyberkiwiCommented:
Hi there,

This should do the trick.
procedure TForm1.Button1Click(Sender: TObject);
const
  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)');
var
  Excel, Book, Sheet, Range: Variant;
  row: integer;
begin
  Excel := CreateOleObject('Excel.Application');
  Excel.Visible := True;

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

  for row := 1 to 8 do
  begin
    Sheet.Cells(row,1) := col_a[row];
    Range := Sheet.Range['B'+IntToStr(row)];
    Range.Formula := col_b[row];
  end;
  Sheet.Range['A1:B8'].Select;
  Excel.Selection.AutoOutline;
  Sheet.Outline.ShowLevels(1);
end;

Open in new window

0

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:
Hi

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 ?
0
cyberkiwiCommented:
I hope it works out.
Sorry no I haven't heard of TXLSReadWrite... automation and peeking at recorded macros seem to work for me :)
0
henryreynoldsAuthor Commented:
It will work thank you very much
0
henryreynoldsAuthor Commented:
Thank you very much
0
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
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.