当前位置:主页>仓库管理软件> 列表

SOS:Excel導出問題

财务软件版1楼: 現在要從數據庫中到出數據到Excel(利用ExcelApplication),其中有CP_NO欄位有型如(1234 123456 00)或(1234 1234)的數據要求導出后將其中的空格去掉并且如果后面兩位是零的也必須去掉﹐沒有0的則不用。該如何實現啊??

2楼: 怎么沒有人幫幫我啊?55555555555555555555555555 如仓库进销存管理软件

3楼: 是太難了還是?分少的話可以再加啊﹗

4楼: 分数却实太少了,我问一个题最启起也是100分

5楼: 先建一个空的excel文件保存好,然后到sql-server里选中需要导出的表,利用导出数据的功能,在导出目标里选种刚才保存的excel文件,按提示走下去就可以.

6楼: 首先TKS兩位﹐TOcnnren:你說的那些我知道﹐我是要在Delphi中利用Excel控件實現該功能﹐而且是有條件的(數據要求導出后將其中的空格去掉并且如果后面兩位是零的也必須去掉﹐沒有0的則不用。)

财务软件版7楼: 我是這么寫的﹐幫我看看代碼哪里出錯了?﹕(
procedure TForm1.Button1Click(Sender: TObject);
var
i,row,column:Integer;
begin
try
try
ExcelApplication1.Connect;
except


ExcelApplication1.Disconnect;
ShowMessage(''確認你是否安裝了Excel!'');
end;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:=''Excel Application1'';
ExcelApplication1.Workbooks.Add(null,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
MSQuery1.Open;
row:=1;
column:=1;
for i:=0 to MSQuery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[row,column]:=MSQuery1.Fields[i].DisplayLabel;
Inc(column);
end;

MSQuery1.First;
row:=2;
for i:=0 to MSQuery1.RecordCount-1 do
begin
if MSQuery1.Fields[i].DisplayLabel=''cp_name'' then
begin
ExcelWorksheet1.Cells.Item[row,1]:=MSQuery1.fieldbyname(''cp_name'').AsString;
//showmessage(ExcelWorksheet1.Cells.Item[row,1]);
Inc(row);
end else
if MSQuery1.Fields[i].DisplayLabel=''cp_no'' then

begin
case Length(MSQuery1.fieldbyname(''cp_no'').AsString) of
12:begin
ExcelWorksheet1.Cells.Item[row,2]:=Copy(Trim(Msquery1.fieldbyname''cp_no'').AsString),1,8);
Inc(row);
end;
9: begin
ExcelWorksheet1.Cells.Item[row,2]:=trim(MSQuery1.fieldbyname(''cp_no'').AsString);
Inc(row);
end;
end;
end;
msquery1.next;
end;
finally
ExcelApplication1.Quit;
end;
end;

8楼: DBGRIDEH导入EXCEL,有进度条
procedure Tfmjtjs.SpeedButton13Click(Sender: TObject);
var
i,row,column:integer;
len:integer;
str:array[1..100] of string;
begin
if adoquery1.RecordCount=0 then
begin
application.MessageBox(''没有数据,无法导入!'',''系统信息提示'',48);
exit;
end;
Try
ExcelApplication1.Connect;
Except
MessageDlg(''请检查您是否安装了Excel'',
mtError, [mbOk], 0);
Abort;
End;
ExcelApplication1.Visible[0]:=false;


ExcelApplication1.Caption:=''123'';
ExcelApplication1.Workbooks.Add(Null,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
//Table1.Open;
row:=2;
For I := 1 To adoquery1.FieldCount Do
ExcelWorksheet1.Cells.Item[1,i]:=adoquery1.Fields[I-1].FieldName ;
ProgressBar1.Min :=0;
ProgressBar1.Max :=adoquery1.RecordCount -1;
adoquery1.First ;
While Not(adoquery1.Eof) do
begin
column:=1;
len:=1;
ProgressBar1.Position:=row;
label18.Caption:= inttostr(row-2);
//////////////////////////////////////////////////////////////////// //
for i:=0 to adoquery1.FieldCount-1 do //
begin // 自动适应大小
if length(str[1+i])str[1+i]:=adoquery1.fields[i].AsString;
if length(str[1+i])>length(adoquery1.Fields[i].FieldName) then
begin


ExcelWorksheet1.Cells.Item[1,1+i].ColumnWidth:=length(str[1+i]);
end
else
ExcelWorksheet1.Cells.Item[1,1+i].ColumnWidth:=length(adoquery1.Fields[i].FieldName);
end; //
//////////////////////////////////////////////////////////////////////

for i:=1 to adoquery1.FieldCount do
begin
application.ProcessMessages;
ExcelWorksheet1.Cells.Item[row,column]:=adoquery1.fields[i-1].AsString;
column:=column+1;
end;
adoquery1.Next;
row:=row+1;
len:=len+1;
end;
ProgressBar1.Position:=0;
ExcelApplication1.Visible[0]:=true;

end;

9楼: 这样子行吗??
我以前试过好几种方法
行是行
可不好!

10楼: 那誰有更好的方法哦﹐一起分享啊