?
Solved

How to save grid to Excel Spreadsheet

Posted on 2003-03-26
7
Medium Priority
?
1,860 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:MarkStephen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 100 total points
ID: 8213602
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
 
LVL 3

Assisted Solution

by:smurff
smurff earned 100 total points
ID: 8216682
www.tmssoftware.com and look for TAdvStringGrid it has a SaveToXLS function.

Regards
Smurff
0
 
LVL 9

Assisted Solution

by:tkalchev
tkalchev earned 100 total points
ID: 8216841
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
 
LVL 1

Expert Comment

by:nafeelm
ID: 8225631


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
 

Expert Comment

by:CleanupPing
ID: 9316588
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question