Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Accessing Xls File

Posted on 2004-04-25
6
Medium Priority
?
769 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 336 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 332 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 332 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

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

926 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