/ Forside / Teknologi / Udvikling / Delphi/Pascal / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
Delphi/Pascal
#NavnPoint
oldwiking 603
jrossing 525
rpje 520
EXTERMINA.. 500
gandalf 460
gubi 270
DJ_Puden 250
PARKENSS 230
technet 210
10  jdjespers.. 200
Delphi Excel kan ikke klokken (c:
Fra : Hans Nikolajsen


Dato : 12-07-07 13:44

Jadav alle!

Jeg er ved at lege med Excel i Delphi!
Hvis jeg laver et lille regneark med fire felter og et af den indeholder
klokken, så går det galt (eks.)!
15:00
Test
654
1,6

Her bliver 15:00 til 0,625
De andre felter kan den godt finde ud af.

Nogen der har en god ide???????

Her er programmet:
************************* START*********************
unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;

type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
Label1: TLabel;
Label2: TLabel;

procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
x, y, k, r: Integer;

implementation

{$R *.dfm}

uses
ComObj;

function Xls_To_StringGrid(AGrid: TStringGrid; AXLSFile: string): Boolean;
const
xlCellTypeLastCell = $0000000B;
var
XLApp, Sheet: OLEVariant;
RangeMatrix: Variant;
x, y, k, r: Integer;
begin
Result := False;
// Create Excel-OLE Object
XLApp := CreateOleObject('Excel.Application');
try
// Hide Excel
XLApp.Visible := False;

// Open the Workbook
XLApp.Workbooks.Open(AXLSFile);

// Sheet := XLApp.Workbooks[1].WorkSheets[1];
Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];

// In order to know the dimension of the WorkSheet, i.e the number of
rows
// and the number of columns, we activate the last non-empty cell of it

Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
// Get the value of the last row
x := XLApp.ActiveCell.Row;
// Get the value of the last column
y := XLApp.ActiveCell.Column;

// Set Stringgrid's row &col dimensions.

AGrid.RowCount := x;
AGrid.ColCount := y;


// Assign the Variant associated with the WorkSheet to the Delphi
Variant

RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
// Define the loop for filling in the TStringGrid
k := 1;
repeat
for r := 1 to y do
AGrid.Cells[(r - 1), (k - 1)] := RangeMatrix[K, R];
Inc(k, 1);
AGrid.RowCount := k + 1;
until k > x;
// Unassign the Delphi Variant Matrix
RangeMatrix := Unassigned;

finally
// Quit Excel
if not VarIsEmpty(XLApp) then
begin
// XLApp.DisplayAlerts := False;
XLApp.Quit;
XLAPP := Unassigned;
Sheet := Unassigned;
Result := True;
end;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=inttostr(x);
label2.Caption:=inttostr(y);
if Xls_To_StringGrid(StringGrid1, 'C:\test.xls') then
ShowMessage('Table has been imported!');
end;
end.
************************* SLUT*********************
--
--
Mvh
Hans Nikolajsen



 
 
Uffe Kousgaard (12-07-2007)
Kommentar
Fra : Uffe Kousgaard


Dato : 12-07-07 14:47

"Hans Nikolajsen" <jadavnoget@vip.cybercity.dk> wrote in message
news:f757si$ehc$1@newsbin.cybercity.dk...
>
> Her bliver 15:00 til 0,625
> De andre felter kan den godt finde ud af.
>
> Nogen der har en god ide???????

15/24 = 0.625. Det er den måde klokkeslet repræsenteres på internt i delphi
og excel. "15:00" er kun en formatering af tallet.

Hilsen
Uffe



Søg
Reklame
Statistik
Spørgsmål : 177414
Tips : 31962
Nyheder : 719565
Indlæg : 6407849
Brugere : 218876

Månedens bedste
Årets bedste
Sidste års bedste