J
jade920
Unregistered / Unconfirmed
GUEST, unregistred user!
用来调用Excel的,在pb中引用
library ExcelInPut;
uses sysutils,dialogs,comobj;
var ExcelID : variant;
SheetID : integer;
SaveFile: pchar;
function ExcelOpen(pathname:string):integer;stdcall;
begin
pathname:=pchar(pathname);
if not FileExists(pathname) then
begin
result:=0;
exit;
end;
try
begin
ExcelID := CreateOleObject( 'Excel.Application' );
ExcelID.workbooks.open(pathname);
//ExcelID.visible := true;
result := 1;
SheetID := 1;
end;
except
begin
result := 0;
ExcelID.quit;
ExcelID := unassigned;
end;
end;
end;
function SetSheet(sheet:integer):integer;stdcall;
begin
SheetID := sheet;
end;
function GetCount(cols:integer):integer;stdcall;
var i,row,col : integer;
schar;
begin
row := 1;
try
while row>0 do
begin
i:=0;
for col := 1 to cols do
if length(pchar(string(ExcelID.WorkSheets[SheetID].cells[row,col].value)))<1 then
i:=i+1;
if i=cols then
begin
result := row - 1;
exit;
end;
row := row+1;
end;
except
ExcelID.quit;
ExcelID := unassigned;
result := 0;
end;
end;
function GetValue(row,col:integer)char;stdcall;
begin
if row>0 then
else
row := 1;
if col>0 then
else
col := 1;
try
result := pchar(string(ExcelID.WorkSheets[SheetID].cells[row,col].value));
except
begin
result := 0;
ExcelID.quit;
ExcelID := unassigned;
end;
end;
end;
function SaveAs(pathnamechar):integer;stdcall;
begin
SaveFile := pathname;
ExcelId.WorkBooks.add;
end;
function ExcelClose():integer;stdcall;
begin
if (not varisempty(ExcelID)) then
begin
ExcelID.quit;
ExcelID := unassigned;
end;
result := 1;
end;
exports
ExcelOpen,
SetSheet,
GetCount,
GetValue,
ExcelClose;
begin
end.
library ExcelInPut;
uses sysutils,dialogs,comobj;
var ExcelID : variant;
SheetID : integer;
SaveFile: pchar;
function ExcelOpen(pathname:string):integer;stdcall;
begin
pathname:=pchar(pathname);
if not FileExists(pathname) then
begin
result:=0;
exit;
end;
try
begin
ExcelID := CreateOleObject( 'Excel.Application' );
ExcelID.workbooks.open(pathname);
//ExcelID.visible := true;
result := 1;
SheetID := 1;
end;
except
begin
result := 0;
ExcelID.quit;
ExcelID := unassigned;
end;
end;
end;
function SetSheet(sheet:integer):integer;stdcall;
begin
SheetID := sheet;
end;
function GetCount(cols:integer):integer;stdcall;
var i,row,col : integer;
schar;
begin
row := 1;
try
while row>0 do
begin
i:=0;
for col := 1 to cols do
if length(pchar(string(ExcelID.WorkSheets[SheetID].cells[row,col].value)))<1 then
i:=i+1;
if i=cols then
begin
result := row - 1;
exit;
end;
row := row+1;
end;
except
ExcelID.quit;
ExcelID := unassigned;
result := 0;
end;
end;
function GetValue(row,col:integer)char;stdcall;
begin
if row>0 then
else
row := 1;
if col>0 then
else
col := 1;
try
result := pchar(string(ExcelID.WorkSheets[SheetID].cells[row,col].value));
except
begin
result := 0;
ExcelID.quit;
ExcelID := unassigned;
end;
end;
end;
function SaveAs(pathnamechar):integer;stdcall;
begin
SaveFile := pathname;
ExcelId.WorkBooks.add;
end;
function ExcelClose():integer;stdcall;
begin
if (not varisempty(ExcelID)) then
begin
ExcelID.quit;
ExcelID := unassigned;
end;
result := 1;
end;
exports
ExcelOpen,
SetSheet,
GetCount,
GetValue,
ExcelClose;
begin
end.