mssql数据库中的数据如何转入excel? (50分)

  • 主题发起人 主题发起人 sq770320
  • 开始时间 开始时间
S

sq770320

Unregistered / Unconfirmed
GUEST, unregistred user!
mssql数据库中的一个字符型字段(全是数字)
转入excel会自动将数据前面的0去掉请问如何解决?急!!!!!
谢谢!!!
 
你可这样,试试:
将该字段前加上一个单引号即:'
假设你的字段为field1,即为:'+field1
 
不行,我把数据转入到一个字符串中,但转过去以后excel还是把前面的0去掉,
很急。请各位大虾帮帮忙!!!!
 
你应在Excel中把数据类型设置成文本。
 
我是在delphi创建excel表的,请问如何设置数据类型???谢谢
 
procedure TForm1.WriteExcel(AdsData: TADODataSet; sName, Title: string);
var
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
i, j: integer;
filename: string;
begin
filename := concat(extractfilepath(application.exename), sName, '.xls');
try
ExcelApplication1 := TExcelApplication.Create(Application);
ExcelWorksheet1 := TExcelWorksheet.Create(Application);
ExcelWorkbook1 := TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.Messagebox('Excel 没有安装!','系统提示', MB_ICONERROR + mb_Ok);
Abort;
end;
try
ExcelApplication1.Workbooks.Add(EmptyParam, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
AdsData.First;
for j := 0 to AdsData.Fields.Count - 1 do
begin
ExcelWorksheet1.Cells.item[3, j + 1] := AdsData.Fields[j].DisplayLabel;
ExcelWorksheet1.Cells.item[3, j + 1].font.size := '10';
end;
for i := 4 to AdsData.RecordCount + 3 do
begin
for j := 0 to AdsData.Fields.Count - 1 do
begin
//关键是这句话呀!!!!!!!!!!!
ExcelWorksheet1.Cells.Item[i, j + 1].NumberFormatLocal := '@';
ExcelWorksheet1.Cells.item[i, j + 1] := AdsData.Fields[j].Asstring;
ExcelWorksheet1.Cells.item[i, j + 1].font.size := '10';
end;
AdsData.Next;
end;
ExcelWorksheet1.Columns.AutoFit;
ExcelWorksheet1.Cells.item[1, 2] := Title;
ExcelWorksheet1.Cells.Item[1, 2].font.size := '14';
ExcelWorksheet1.SaveAs(filename);
Application.Messagebox(pchar('系统提示' + filename),'Hello',mb_Ok);
finally
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
end;
end;
 
老大我对你的敬仰之情,犹如滔滔江水,连绵不绝>>>>>>>>>>>>>>>>
 
后退
顶部