Solved

Accessing Xls File

Posted on 2004-04-25
6
718 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

14 Experts available now in Live!

Get 1:1 Help Now