How to save grid to Excel Spreadsheet

Hi, I am fairly new to Delphi and am trying to figure
out how to save the contents of a TStringGrid to an Excel
Spreadsheet (.xls). Is there a relatively easy way to do
this ?

Thanks,

Mark.
MarkStephenAsked:
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.

bruintjeCommented:
Hello MarkStephen,

you could have a look at this post
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=7bn17o%2457q8%40forums.borland.com

it's a dbgrid but worth a try

HAGD:O)Bruintje
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
smurffCommented:
www.tmssoftware.com and look for TAdvStringGrid it has a SaveToXLS function.

Regards
Smurff
0
tkalchevCommented:
http://www.maxcomponents.net

there is a free mxMxNativeExcel component, which can create an Excel Sheet, w/o need of Excel, installed of the computer.

The code will be s.th. like this, assuming your StringGrid is called StringGrid1 and the mxNativeExcel component is called mxNativeExcel1

var i,j : Integer;

with StringGrid1, mxNativeExcel1 do
begin
 
  NewFile;
  FileName := 'shet1.xls';
 
  for i:=0 to RowCount-1
    for j:=0 to ColCount-1 do
      WriteLabel ( i+1,j+1,Cells[j,i] );

  CloseFile;
  SaveToFile;

end;

Simple, eh ?
0
nafeelmCommented:


try this :

F1Book1 is a component available in Delphi 3!

Just drop a StringGrid, F1Book and a Button component on the form.


The Button Click code is as follows:


procedure TForm1.Button1Click(Sender: TObject);
var r,c: Integer;
begin
  with F1Book1 do
  begin
    r:=1;
    for r:=0 to StringGrid1.Rowcount - 1 do
    begin
      Row:=r+1;
      for c:=0 to StringGrid1.Colcount - 1 do
      begin
        Col:=c+1;
        Entry:=StringGrid1.Cells[c,r];
      end;
    end;
    Write('c:\temp\test.xls', F1FileExcel5);
  end;
end;

This should solve your problem!
0
CleanupPingCommented:
MarkStephen:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
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.