procedure TForm1.btnClick(Sender: TObject);
begin
OpenDialog1.Title := '请选择正确的excel文件';
OpenDialog1.Filter := 'Excel(*.xls)|*.xls';
if OpenDialog1.Execute then
edit1.Text := OpenDialog1.FileName;
end;
procedure TForm1.btninClick(Sender: TObject);
const
BeginRow = 2; BeginCol = 1;
var
Excel: OleVariant;
iRow,iCol : integer;
xlsFilename: string;
begin
if (trim(edit1.Text) = '') then
begin
MessageBox(GetActiveWindow(), 请选择正确的excel路径', MB_OK +
MB_ICONWARNING);
exit;
end;
xlsFilename := trim(edit1.Text);
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('excel没有安装', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
iRow := BeginRow;
iCol := BeginCol;
while trim(Excel.WorkSheets[1].Cells[iRow,iCol].va
本文转载自: https://blog.csdn.net/zxm8513/article/details/119820549
版权归原作者 zxm8513 所有, 如有侵权,请联系我们删除。
版权归原作者 zxm8513 所有, 如有侵权,请联系我们删除。