Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Accessing Xls File

Posted on 2004-04-25
6
Medium Priority
?
762 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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