当前位置:主页>销售管理软件> 列表

全部家当给分啦!!!excel文档 导入access 或者 找免费仓库管理软件

库存管理软件版1楼: 你好,我现在有个excel文档,我想把它导入到access进行数据处理.我查阅了以前的相关问题,我现在是用ADO里的控件tabel将excel里的数据用dbgrid显示出来了,但是我不太清楚怎么样将dbgrid里的数据读入到access数据库.
或者大家有直接将excel文档里的数据读入到access数据库也行.
谢谢大家了.

2楼: 大家给帮帮忙,谢了. 如建筑施工财务软件

3楼: 对电子表格逐行逐单元读取,放到TABLE的ACCESS中就可以了!

4楼: to mm7497
呵呵就是就是.但我想知道对dbgrid的逐个读 取的语法是什么?:)谢谢.

5楼: 大家给说说对dbgrid的逐个读 取的语法是什么?:)谢谢.

6楼: excel导入到access的方法:
不需要编程的方法:
打开access,选择 文件/获取外部数据/导入,选择文件类型为xls,点导入,取消“第一行包含列标题”的选择,下一步,下一步,OK。

库存管理软件版7楼: dbgrid导出到excel的方法:
procedure TfrmWageManage.CopyDbDataToExcel(Args: array of const;
titlename: string; NoShowId: Integer; IsControl: boolean);
var
iCount, jCount: Integer;
XLApp: Variant;
Sheet: Variant;
I: Integer;
l_noshowid: Integer;
l_control: boolean;
icol: Integer;
begin
//是否要控制输出列
l_control := IsControl;
//定义不显示在excel中的列
l_noshowid := NoShowId;
if l_control = false then
l_noshowid := -1;

Screen.Cursor := crHourGlass;
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := false;
XLApp.Quit;
VarClear(XLApp);
end;

try
XLApp := CreateOleObject(''Excel.Application'');
except
Screen.Cursor := crDefault;
exit;
end;

XLApp.WorkBooks.add;
XLApp.SheetsInNewWorkbook := High(Args) + 1;

for I := Low(Args) to High(Args) do
begin
XLApp.WorkBooks[1].WorkSheets[I + 1].name := TDBGrid(Args[I].VObject).name;
Sheet := XLApp.WorkBooks[1].WorkSheets[TDBGrid(Args[I].VObject).name];
if not TDBGrid(Args[I].VObject).DataSource.dataset.Active then
begin


Screen.Cursor := crDefault;
exit;
end;

TDBGrid(Args[I].VObject).DataSource.dataset.First;
for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
begin
//去掉敏感列的显示
if iCount <> l_noshowid then
Sheet.Cells[1, iCount + 1] := TDBGrid(Args[I].VObject).Columns.Items[iCount].Title.Caption;
Sheet.Cells[1, iCount + 1].HorizontalAlignment := xlCenter;
Sheet.Cells[1, iCount + 1].Font.Color := clBlue;
//控制单元格背景颜色
//Sheet.Cells[1, iCount + 1].Interior.ColorIndex := 39;
//控制边框线可见
Sheet.Cells[1, iCount + 1].borders.linestyle:=xlcontinuous;
end;

jCount := 1;
while not TDBGrid(Args[I].VObject).DataSource.dataset.eof do
begin
for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
begin
//去掉敏感列的显示
if iCount <> l_noshowid then

Sheet.Cells[jCount + 1, iCount + 1] := TDBGrid(Args[I].VObject).Columns.Items[iCount].Field.asstring;
Sheet.Cells[jCount + 1, iCount + 1].HorizontalAlignment := xlCenter;
//控制边框线可见
Sheet.Cells[jCount + 1, iCount + 1].borders.linestyle:=xlcontinuous;
end;
Inc(jCount);
TDBGrid(Args[I].VObject).DataSource.dataset.Next;
end;
//删除列的编号从1开始,而送入隐藏的列从0开始,故需要+1
if l_noshowid <> -1 then
XLApp.ActiveSheet.Columns[l_noshowid + 1].delete;
//显示工资统计数据,本代码为本过程特有
Sheet.Cells[jCount + 1, 6] := ''工资总计:'';
Sheet.Cells[jCount + 1, 7] := edWagetotal.Text;
Sheet.Cells[jCount + 2, 6] := ''奖金总计:'';
Sheet.Cells[jCount + 2, 7] := edBonusTotal.Text;
Sheet.Cells[jCount + 3, 6] := ''扣款总计:'';
Sheet.Cells[jCount + 3, 7] := edWageLoseTotal.Text;
Sheet.Cells[jCount + 4, 6] := ''差额:'';


Sheet.Cells[jCount + 4, 7] := edCha.Text;
if cbyear.Text <> '''' then
begin
Sheet.Cells[jCount + 5, 1] := ''年份:'';
Sheet.Cells[jCount + 5, 2] := cbyear.Text;
end;
Sheet.Cells[jCount + 6, 1] := ''员工姓名:'';
if cbname.Text = '''' then
Sheet.Cells[jCount + 6, 2] := ''全部'';
if cbname.Text <> '''' then
Sheet.Cells[jCount + 6, 2] := cbname.Text;
Sheet.Cells[jCount + 6, 4] := ''打印日期:'';
Sheet.Cells[jCount + 6, 5] := formatdatetime(''yyyy年mm月dd日'',now);
//控制边框线
Sheet.Cells[jCount + 1, 6].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 1, 7].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 2, 6].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 2, 7].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 3, 6].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 3, 7].borders.linestyle:=xlcontinuous;


Sheet.Cells[jCount + 4, 6].borders.linestyle:=xlcontinuous;
Sheet.Cells[jCount + 4, 7].borders.linestyle:=xlcontinuous;
//显示统计数据结束
//各列自适应宽度
for icol := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
begin
XLApp.ActiveSheet.Columns[icol + 1].EntireColumn.AutoFit;
end;
XLApp.Visible := true;
XLApp.Caption := titlename;
end;
Screen.Cursor := crDefault;
// XLApp.Quit;
VarClear(XLApp);
end;
调用示例:
//从dbgrid1中导出数据到excel,名称为"工资等发放清单",第5列不显示在导出表中//
//(由true控制),如果最后一个参数为false,则全部导出
CopyDbDataToExcel([DBGrid1], ''工资等发放清单'', 5, true);

8楼: 呵呵.如果有程序控制呢,用access直接导入我也知道.:)谢谢你了.

9楼: 请问怎么能将dbgrid的数据逐行读取到access数据库中,假设我数据库中有两个字段.id id1
adotable.fieldbyname(''id'').asstring:=??

10楼: 你最好生成文本文件,如 IMPORT.TXT,然后导入
文本类似
"1","A"
"2","B"
...
再建立一个 scheme.ini 文件放在 xxxx.mdb 同一个目录下,类似
[Import.txt]
ColNameHeader=True
format=Delimited(,)
MaxScanRows=0
CharacterSet=ANSI
Col1="ID" Char Width 30
Col2="ID1" Char Width 30


程序这样写:

ADOC_LOCAL.ConnectionString := ''Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=C:\xxxx.mdb;Persist Security Info=True'';
ADOC_LOCAL.Open;
ADOC_LOCAL.BeginTrans;
ADOC_LOCAL.Execute(''SELECT * INTO ['' + TableName + ''] FROM [Text;FMT=Delimited;HDR=Yes;DATABASE=C:\].IMPORT.TXT'');
ADOC_LOCAL.CommitTrans;

11楼: {---------------------------------------------------}
{ 操作 EXCEL }
{ 作者:SUBIN 时间:2006.01.04 }
{---------------------------------------------------}

unit UExcel;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj,DB, ADODB,IniFiles ;

type


TBaseExcel=Class
private
FSheetTitle : String;
FSheetIndex : Integer;
FFileName : String;
FExcelApp : Variant;
FExcelSheet : Variant;
function GetColColunt : Integer;
function GetRowCount : Integer;
function GetSheetCount : Integer;
procedure SetSheetTitle(const Value : String);
procedure SetSheetIndex(const Value : Integer);
procedure SetFileName (const Value : String);
procedure SetExcelApp (const Value : Variant);
procedure SetExcelSheet(const Value : Variant);
protected
function InitExcel : Boolean;virtual;
function FinallyExcel : Boolean;virtual;
function GetCellValue (Row,Col:Integer):String;
procedure SetCellValue(Row,Col:Integer;Value:String);

property SheetTitle : String read FSheetTitle write SetSheetTitle;
property SheetIndex : Integer read FSheetIndex write SetSheetIndex;
property FileName : String read FFileName write SetFileName;
property ExcelApp : Variant read FExcelApp write SetExcelApp;
property ExcelSheet : Variant read FExcelSheet write SetExcelSheet;
property ColCount : Integer read GetColColunt;
property RowCount : Integer read GetRowCount;
property SheetCount : Integer read GetSheetCount;
public
end;


type
TFieldInfo=Record
MDB_FieldName : String[20];
XLS_FieldName : String[20];
FieldIndex : Integer;
end;

TExcelToDataBase=Class(TBaseExcel)
private
FTabelName : String;
FColumnTitleRow : Integer;
FDataRow : Integer;
function GetFieldCount : Integer;
function GetFieldName : Boolean;
function GetFieldIndex : Boolean;
procedure SetTableName (const Value: String);
procedure SetColumnTitleRow(const Value: Integer);
procedure SetDataRow (const Value: Integer);
protected
FieldInfo : Array of TFieldInfo;
property ColCount; {Excel列}

property RowCount; {Excel行}
property ExcelApp;
property ExcelSheet;
property SheetTitle; {Excel标题}
property FieldCount : Integer read GetFieldCount; {字段数}
property TabelName : String read FTabelName write SetTableName;
public
function InitExcel : Boolean;overload; {初始化Excel}
function FinallyExcel : Boolean;overload; {结束Excel}
function ExcelToDataBase(SheetTitle,TabelName:String):Boolean; {导数据}
property FileName;
property ColumnTitleRow : Integer read FColumnTitleRow write SetColumnTitleRow;{Column标题所在行}
property DataRow : Integer read FDataRow write SetDataRow; {数据开始行}
end;
implementation

uses GlobalData;

{ TBaseExcel }
function TBaseExcel.InitExcel: Boolean;
begin
Result:=False;
try
ExcelApp := CreateOleObject( ''Excel.Application'' );
except
exit;
end;

if not FileExists(FileName) then Exit;
ExcelApp.Visible := false;
try
ExcelApp.WorkBooks.Open(FileName);
except
exit;
end;
Result:=True;
end;

function TBaseExcel.FinallyExcel: Boolean;
begin
Result:=False;
try
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp:=UnAssigned;
ExcelSheet:=UnAssigned;
Result:=True;
except
end;
end;

function TBaseExcel.GetCellValue(Row, Col: Integer): String;
begin
Result:=ExcelSheet.Cells[Row,Col].Value;
end;

function TBaseExcel.GetColColunt: Integer;
begin
Result:=ExcelSheet.UsedRange.columns.Count;
end;

function TBaseExcel.GetRowCount: Integer;
begin
Result:=ExcelSheet.UsedRange.Rows.Count;
end;

function TBaseExcel.GetSheetCount: Integer;
begin
Result:=ExcelApp.WorkSheets.Count;
end;

procedure TBaseExcel.SetCellValue(Row, Col: Integer; Value: String);

begin
ExcelSheet.Cells[Row,Col].Value:=Value;
end;

procedure TBaseExcel.SetExcelApp(const Value: Variant);
begin
FExcelApp := Value;
end;

procedure TBaseExcel.SetExcelSheet(const Value: Variant);
begin
FExcelSheet := Value;
end;

procedure TBaseExcel.SetFileName(const Value: String);
begin
FFileName := Value;
end;

procedure TBaseExcel.SetSheetIndex(const Value: Integer);
begin
FSheetIndex := Value;
end;

procedure TBaseExcel.SetSheetTitle(const Value: String);
begin
FSheetTitle := Value;
end;

{ TExcelToDataBase }

function TExcelToDataBase.FinallyExcel: Boolean;
begin
Result:=inherited FinallyExcel;
end;

function TExcelToDataBase.InitExcel: Boolean;
begin
Result:=inherited InitExcel;
end;

function TExcelToDataBase.GetFieldCount: Integer;
var
IniFile:TIniFile;
begin
IniFile:=TIniFile.Create(GetCurrentDir+''\''+''FieldConfig.ini'');
try
Result:= IniFile.ReadInteger(TabelName,''fieldCount'',0);
finally
IniFile.Free;
end;
end;

function TExcelToDataBase.ExcelToDataBase(SheetTitle,
TabelName: String): Boolean;
var
I,J:Integer;
CmdQuery:TAdoQuery;
begin
Result:=False;
Self.TabelName:=TabelName;
Self.SheetTitle:=SheetTitle;
if FieldCount>0 then
begin
{Select Excel ActiveSheet}
ExcelApp.WorkSheets[Self.SheetTitle].Activate;
ExcelSheet:=ExcelApp.ActiveSheet;
{Init FieldInfo}
SetLength(FieldInfo,FieldCount);
if not GetFieldName then Exit;
if not GetFieldIndex then Exit;

try
CmdQuery:=TAdoQuery.Create(Nil);
CmdQuery.Close;
CmdQuery.Connection:=ADOConnection;
CmdQuery.SQL.Text:=''Select * From ''+TabelName;
CmdQuery.Open;

for I:=2 to RowCount do
begin
CmdQuery.Insert;
for J:=0 to FieldCount-1 do
begin
if FieldInfo[j].FieldIndex>=0 then
begin
CmdQuery.FieldByName(FieldInfo[j].MDB_FieldName).AsString:=ExcelSheet.Cells[i,FieldInfo[j].FieldIndex].value;
end;
end;
CmdQuery.Post;
end;
finally
CmdQuery.Free;
end;
Result:=True;
end;
end;

function TExcelToDataBase.GetFieldIndex: Boolean;
var
I:Integer;
J:Integer;
begin
Result:=False;
for I:=1 to ColCount do
begin
for J:=0 to FieldCount-1 do
begin
if ExcelSheet.Cells[1,i].value=FieldInfo[j].XLS_FieldName then
begin
FieldInfo[j].FieldIndex:=I;
end;
end;
end;
Result:=True;
end;

function TExcelToDataBase.GetFieldName: Boolean;
var
IniFile:TIniFile;
I:Integer;
begin
Result:=False;
IniFile:=TIniFile.Create(GetCurrentDir+''\''+''FieldConfig.ini'');
try
for i:=1 to FieldCount do
begin
FieldInfo[i-1].MDB_FieldName:=IniFile.ReadString(TabelName,''MDB_FieldName''+IntToStr(i),'''');
FieldInfo[i-1].XLS_FieldName:=IniFile.ReadString(TabelName,''XLS_FieldName''+IntToStr(i),'''');
FieldInfo[i-1].FieldIndex:=-1;
end;
Result:=True;
finally
IniFile.Free;
end;
end;

procedure TExcelToDataBase.SetTableName(const Value: String);
begin
FTabelName := Value;
end;

procedure TExcelToDataBase.SetColumnTitleRow(const Value: Integer);
begin
FColumnTitleRow := Value;
end;

procedure TExcelToDataBase.SetDataRow(const Value: Integer);
begin
FDataRow := Value;
end;

end.

12楼: 接受答案了. 如免费仓库管理软件