السلام عليكم
احتاج لمساعدة
كيف ممكن عمل برنامج يعمل استراد بيانات من ملف اكسيل ويخزنها في قاعدة بيانات SQL
السلام عليكم
احتاج لمساعدة
كيف ممكن عمل برنامج يعمل استراد بيانات من ملف اكسيل ويخزنها في قاعدة بيانات SQL
يمكنك االتصال بالاكس عن طريق ado
مثل ما تفعل مع قاعدة البيانات فماما ثم تقوم بعمل حلقة insert في القاعدة
sameer.alhaj كتب:السلام عليكم
احتاج لمساعدة
كيف ممكن عمل برنامج يعمل استراد بيانات من ملف اكسيل ويخزنها في قاعدة بيانات SQL
ما تحتاج إلى عمل برنامج تستطيع استخدام خصائص Import & Export بحيث تنقل تلك البيانات
هذه دالة استخدمها كثيرا وهي مجربة فهي تقوم باستيراد البيانات من اكسل الي StringGrid
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;والاستدعاء
if Xls_To_StringGrid(StringGrid1, 'c:\File.xls') then
ShowMessage('Table has been Imported!');وهي متوفرة علي النت بكثرة
تحياتي
تم تعديل هذه المشاركة بواسطة prof_1982 في 18 أبريل 2010 في 10:07
الإنسان الذي يقول بأنه لا يمكن عمل شيء يجب ألا يعيق مطلقاً الإنسان الذي يقوم بعمل ذلك الشيء.
إن تخطئ فأنت إنسان ... أما أن تلوم جهازك الكمبيوتر على خطأك فهذا أكثر إنسانية.