![]() |
|
excel - نسخة قابلة للطباعة +- delphi4arab منتديات دلفي للعرب (https://delphi4arab.net/forum) +-- قسم : منتديات دلفي للعرب التعليمية (https://delphi4arab.net/forum/forumdisplay.php?fid=3) +--- قسم : سؤال و جواب حول دلفي (https://delphi4arab.net/forum/forumdisplay.php?fid=15) +--- الموضوع : excel (/showthread.php?tid=12476) |
excel - ع الحليم - 16-12-2023 السلام عليكم هل يمكن البحث عن الخانات الفارغة في ملف excel وذكر مواضعها RE: excel - wadoud - 16-12-2023 (16-12-2023, 09:31 PM)ع الحليم كتب : السلام عليكم وعليكم السلام : جرب ما يلي يمكنك استخدام مكتبة 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;RE: excel - ع الحليم - 17-12-2023 جزاك الله خيرا |