Solved

Accessing Xls File

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 12 hours left to enroll

623 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