16-12-2023, 09:31 PM
16-12-2023, 09:54 PM
(16-12-2023, 09:31 PM)ع الحليم كتب : [ -> ]السلام عليكم
هل يمكن البحث عن الخانات الفارغة في ملف excel وذكر مواضعها
وعليكم السلام :
جرب ما يلي
يمكنك استخدام مكتبة Excel.Application للتفاعل مع ملفات Excel في دلفي والبحث عن الخلايا الفارغة. سأقدم لك أدناه مثالًا أساسيًا باستخدام مكتبة Excel الخاصة بمكون Vcl.OleAuto في دلفي.
تأكد من وجود وحدة ComObj في قسم الاستخدامات لديك ومن قيامك باستيراد مكتبة Excel إلى مشروعك.
كود :
uses
..., ComObj;
procedure SearchEmptyCells(const FilePath: string);
var
ExcelApp: Variant;
Workbook: Variant;
Worksheet: Variant;
Cell: Variant;
Row, Column: Integer;
begin
try
// Create an instance of Excel
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := False; // Do not show Excel to the user
// Open the Excel workbook
Workbook := ExcelApp.Workbooks.Open(FilePath);
// Select the first sheet of the workbook (you can change the index if needed)
Worksheet := Workbook.Sheets[1];
// Iterate through rows and columns to find empty cells
for Row := 1 to Worksheet.UsedRange.Rows.Count do
begin
for Column := 1 to Worksheet.UsedRange.Columns.Count do
begin
Cell := Worksheet.Cells[Row, Column];
// Check if the cell is empty
if VarIsEmpty(Cell.Value) then
begin
ShowMessage('Empty cell found at row ' + IntToStr(Row) +
', column ' + IntToStr(Column));
end;
end;
end;
except
on E: Exception do
ShowMessage('Error: ' + E.Message);
end;
// Close Excel and release resources
ExcelApp.Quit;
Workbook := Unassigned;
Worksheet := Unassigned;
Cell := Unassigned;
ExcelApp := Unassigned;
end;17-12-2023, 07:55 PM
جزاك الله خيرا