Solved

Accessing Xls File

Posted on 2004-04-25
6
722 Views
Last Modified: 2010-04-05

 hi guys i hope u ok now

   i want to access first coloum in .Xls Excel  file using Delphi

                any one here can help me ?
                     
                 
                                                                     Thanx
0
Comment
Question by:BinLadin
6 Comments
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 84 total points
ID: 10912254

  This example change the font to Blue and Bold in the first column...

  procedure TForm1.ReadColumns;
  var
    ExcelColumns: Variant;
  begin
    XLApp := CreateOleObject('Excel.Application');
    ExcelColumns := XLApp.Workbooks[1].WorkSheets['Delphi Data'].Columns;
    ExcelColumns .Columns[1].Font.Bold := True;
    ExcelColumns .Columns[1].Font.Color := clBlue;
  end;
0
 
LVL 11

Assisted Solution

by:shaneholmes
shaneholmes earned 83 total points
ID: 10912268
If the machine that will be running your application will have Excel on it, then you can use Ole Automation.
There are Excel server component in Delphi 7.

What version do you use?

If Excel will no be on the machine, then you will need a third party component (freeware, shaerware, or commercial ware), which will read the file.

Did you try searching Delphi Super Page, Torry's, or Delphi 32 page

Torry
www.torry.ru
www.torry.net

www.delphi32.com
www.delphipages.com

Delphi Super Page
http://delphi.icm.edu.pl/


WHen i do a search, for say on Super Page


axxlsrw.zip (800,338 bytes)  
 
XLS Read Write is two native Delphi components, TXLSRead and TXLSWrite designed for accessing microsoft Excel XLS files. There is no need for any other files to be installed, including Excel.
With XLS Read Write can you:
Read Excel XLS 2.1, 3.0, 4.0 worksheet files and Excel XLS 5.0, 95, 97, 2000 workbook files.
Access all sheets in workbook files.
Receive all text, numbers, etc. you can write in a cell, including formulas!
Read cell formatting information (font, cell color, border, etc.).
Seek function for fast access to single cells.
Write Excel XLS 4.0 worksheet files and Excel XLS 5.0/ 95/ 97/ 2000 workbook files (with any number of sheets in it).
Easy to write formulas, just as strings: "SUM(A1:A10) / B2 + SIN(0.25)"
Write cell formatting (font, cell color, border, etc.).
FAST! Write more than 100,000 cells in less than two seconds!

(ver. 1.35, added 2/21/1999, updated 6/27/2001, no src.)  

http://delphi.icm.edu.pl/ftp/d10free/axxlsrw.zip


Shane
 
0
 
LVL 11

Assisted Solution

by:calinutz
calinutz earned 83 total points
ID: 10917506
Place a TExcelApplication and a TExcelWorkSheet from the Servers Component Page on your form, and a Button and a StringGrid (editable). Name the stringGrid : ks

On the OnClick Event of the Button1 place this code:

procedure TForm1.Button1Click(Sender: TObject);
var
 xls, wb, Range: OLEVariant;
 arrData: Variant;
 i,j:integer;
begin
 {create variant array where we'll copy our data}
 arrData := VarArrayCreate([1, ks.RowCount+2, 1,ks.Columns.Count], varVariant);

 {fill array}

 for i := 1 to ks.RowCount do
   for j := 1 to ks.Columns.Count do
 begin
     arrData[i, j] := ks.Cells[j-1, i-1];
//     arrdata[2,j]:=j;
     end;

 {initialize an instance of Excel}
 xls := CreateOLEObject('Excel.Application');

 {create workbook}
 wb := xls.Workbooks.Add;

 {retrieve a range where data must be placed}
 Range := wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],
wb.WorkSheets[1].Cells[ks.RowCount, ks.Columns.Count]];

 {copy data from allocated variant array}
 Range.Value := arrData;

 {show Excel with our data}
 xls.Visible := True;
end;



This is the way you export your data from a string grid. Similar to this is the export of a DataSet.
This is all you need.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now